def handle(self, *args, **options): subject = options['subject'] release = options['release'] index = options['index'] parameters_filepath = options['parameters_filepath'] if subject not in settings.ENABLED_SUBJECTS: raise CommandError('Subject {0} is not enabled'.format(subject)) parameters = None with open(parameters_filepath) as file_: for (i, line) in enumerate(file_): if index == i: line = line.strip('\n') parameters = tuple(float(p) for p in line.split(',')) break if parameters is None: raise CommandError('{0} is an invalid index'.format(i)) subject = Subject.objects.get(name=subject) releases = Release.objects.filter(subject=subject) subject = subjects.SubjectCreator.from_subject(subject) ma, mi, pa = helpers.get_version_components(release) release = releases.get(major=ma, minor=mi, patch=pa) subject.initialize(release) utilities.analyze_sensitivity(subject, parameters)
def handle(self, *args, **options): subject = options['subject'] release = options['release'] field = options['field'] granularity = options['granularity'] if not release: raise CommandError('Release number cannot be left empty') if not field: raise CommandError('Parameter field cannot be left empty') if subject not in settings.ENABLED_SUBJECTS: raise CommandError('Subject {0} is not enabled'.format(subject)) subject = Subject.objects.get(name=subject) ma, mi, pa = helpers.get_version_components(release) release = Release.objects.get( subject=subject, major=ma, minor=mi, patch=pa ) subject = subjects.SubjectCreator.from_subject(subject) subject_exists = ReleaseStatistics.objects.filter( release=release, granularity=granularity ).exists() if not subject_exists: raise CommandError('{0} not loaded.'.format(release)) subject.initialize(release, granularity) if 'page_rank' in field: utilities.update_pagerank(subject) elif 'sloc' in field: utilities.update_sloc(subject) else: raise CommandError('Updating {0} is not supported'.format(field))
def _load_vulnerability_fix_overrides(self, subjects): for subject in subjects: overrides_file = helpers.get_absolute_path( 'app/assets/data/{}/vulnerability_fix_overrides.csv'.format( subject.name)) if not os.path.exists(overrides_file): continue with open(overrides_file, 'r') as _overrides_file: reader = csv.reader(_overrides_file) for row in reader: print('Loading vulnerability fix override for {}'.format( row[1], )) ma, mi, pa = helpers.get_version_components(row[0]) release = Release.objects.get(subject=subject, major=ma, minor=mi, patch=pa) cve_release = CveRelease.objects.get( release=release, fix_sha=row[2], cve__subject=subject, cve__identifier=row[1]) vulnerability_fix = VulnerabilityFix( cve_release=cve_release, name=row[3], file=row[4]) vulnerability_fix.save()
def _load_releases(self, subjects): for subject in subjects: branches = Branch.objects.filter(subject=subject) releases_file = helpers.get_absolute_path( 'app/assets/data/{}/releases.csv'.format(subject.name)) with open(releases_file, 'r') as _releases_file: reader = csv.reader(_releases_file) for row in reader: print('Loading release {} of {}'.format( row[0], subject.name)) ma, mi, pa = helpers.get_version_components(row[0]) branch = branches.get(major=ma, minor=mi) release = Release( subject=subject, branch=branch, date=row[2], major=ma, minor=mi, patch=pa, reference=row[1] if row[1] else row[0], ) release.save()
def check_revision(option, opt_str, value, parser, *args, **kwargs): setattr(parser.values, option.dest, value) if value: try: (ma, mi, bu) = get_version_components(value) if not Revision.objects.filter(number=value).exists(): raise OptionValueError( 'Revision %s does not exist in the database.' % value) except InvalidVersionError: raise OptionValueError( 'Invalid revision number specified. %s must be formatted as ' '0.0.0' % opt_str)
def check_release(option, opt_str, value, parser, *args, **kwargs): setattr(parser.values, option.dest, value) if value: try: ma, mi, pa = helpers.get_version_components(value) releases = Release.objects.filter(major=ma, minor=mi, patch=pa) if not releases.exists(): raise OptionValueError( 'Release %s does not exist in the database.' % value) except InvalidVersionError: raise OptionValueError( 'Invalid release number specified. %s must be formatted as ' '0.0.0' % opt_str)
def handle(self, *args, **options): subject = options['subject'] release = options['release'] index = options['index'] if subject not in settings.ENABLED_SUBJECTS: raise CommandError('Subject {0} is not enabled'.format(subject)) subject = Subject.objects.get(name=subject) ma, mi, pa = helpers.get_version_components(release) release = Release.objects.get(subject=subject, major=ma, minor=mi, patch=pa) subject = subjects.SubjectCreator.from_subject(subject) subject.initialize(release) subject.gprof(index)
def _load_branches(self, subjects): for subject in subjects: branches_file = helpers.get_absolute_path( 'app/assets/data/{}/branches.csv'.format(subject.name)) with open(branches_file, 'r') as _branches_file: reader = csv.reader(_branches_file) for row in reader: print('Loading branch {} of {}'.format( row[0], subject.name)) ma, mi, pa = helpers.get_version_components(row[0]) branch = Branch(subject=subject, major=ma, minor=mi, reference=row[0], configure_options=row[1]) branch.save()
def _map_cve_to_release(self, subjects): for subject in subjects: releases = Release.objects.filter(subject=subject) branches = Branch.objects.filter(subject=subject) cves = Cve.objects.filter(subject=subject) cves_fixed_file = helpers.get_absolute_path( 'app/assets/data/{}/cves_fixed.csv'.format(subject.name)) with open(cves_fixed_file, 'r') as _cves_fixed_file: reader = csv.reader(_cves_fixed_file) for row in reader: ma, mi, pa = helpers.get_version_components(row[0]) branch = branches.get(major=ma, minor=mi) cve = cves.get(identifier=row[1]) release = releases.get(major=ma, minor=mi, patch=pa) cve_release = CveRelease(cve=cve, release=release, fix_sha=row[2]) cve_release.save() _subject = SubjectCreator.from_subject(subject) _subject.clone() for branch in branches: _subject.checkout(branch.reference, force=True) cve_releases = CveRelease.objects.filter( release__branch=branch, ) for cve_release in cve_releases: shas = [cve_release.fix_sha] for (name, file_) in _subject.get_functions(shas): vulnerability_fix = VulnerabilityFix( cve_release=cve_release, name=name, file=file_) vulnerability_fix.save()
def test_get_version_components(self): self.assertRaises( errors.InvalidVersionError, helpers.get_version_components, 'a.b.c' ) self.assertEqual( helpers.get_version_components('1'), (1, 0, 0) ) self.assertEqual( helpers.get_version_components('0.1'), (0, 1, 0) ) self.assertEqual( helpers.get_version_components('0.0.1'), (0, 0, 1) ) self.assertEqual( helpers.get_version_components('1.00.1'), (1, 0, 1) ) self.assertEqual( helpers.get_version_components('00.01.00'), (0, 1, 0) ) self.assertEqual( helpers.get_version_components('0.1.00'), (0, 1, 0) ) self.assertEqual( helpers.get_version_components('refs/tags/n2.2.10'), (2, 2, 10) ) self.assertEqual( helpers.get_version_components('refs/remotes/origin/release/2.5'), (2, 5, 0) ) self.assertEqual( helpers.get_version_components('0_1'), (0, 1, 0) ) self.assertEqual( helpers.get_version_components('0_0_1'), (0, 0, 1) ) self.assertEqual( helpers.get_version_components('1_00_1'), (1, 0, 1) ) self.assertEqual( helpers.get_version_components('00_01_00'), (0, 1, 0) ) self.assertEqual( helpers.get_version_components('0_1_00'), (0, 1, 0) ) self.assertEqual( helpers.get_version_components('refs/tags/curl-7_30_0'), (7, 30, 0) )