def __init__(self, spec_file, srpm_file): ''' Create a Checks set. srpm_file and spec_file are required, unless invoked from ChecksLister. ''' _ChecksLoader.__init__(self) self.spec = SpecFile(spec_file, self.flags) self.srpm = SRPMFile(srpm_file) self.srpm.unpack() self.data = self.Data() self.data.rpms = RpmDataSource(self.spec) self.data.buildsrc = BuildFilesSource() self.data.sources = SourcesDataSource(self.spec) self._clock = None
def _get_spec_from_srpm(self): path = urlparse(self.srpm_url).path name = os.path.basename(path).rsplit('-', 2)[0] ReviewDirs.workdir_setup(name) self.do_download_srpm() SRPMFile(self.srpm_file).unpack() file = glob(os.path.join(ReviewDirs.srpm_unpacked, name + '*.spec'))[0] self.spec_file = file self.spec_url = 'file://' + file
def _get_spec_from_srpm(self): ''' Extract spec from srpm and update self.spec_url. ''' path = urlparse(self.srpm_url).path name = os.path.basename(path).rsplit('-', 2)[0] ReviewDirs.workdir_setup(name, Settings.cache) self.do_download_srpm() SRPMFile(self.srpm_file).unpack() try: path = glob(os.path.join(ReviewDirs.srpm_unpacked, name + '*.spec'))[0] except IndexError: raise ReviewError("Cannot find spec file in srpm") self.spec_file = path self.spec_url = 'file://' + path
class Checks(_ChecksLoader): ''' Interface class to run checks. ''' def __init__(self, spec_file, srpm_file): ''' Create a Checks set. srpm_file and spec_file are required, unless invoked from ChecksLister. ''' _ChecksLoader.__init__(self) self.spec = SpecFile(spec_file, self.flags) self.srpm = SRPMFile(srpm_file) self.srpm.unpack() self.data = self.Data() self.data.rpms = RpmDataSource(self.spec) self.data.buildsrc = BuildFilesSource() self.data.sources = SourcesDataSource(self.spec) self._clock = None rpms = property(lambda self: self.data.rpms) sources = property(lambda self: self.data.sources) buildsrc = property(lambda self: self.data.buildsrc) @staticmethod def _write_testdata(results): ''' Write hidden file usable when writing tests. ''' with open('.testlog.txt', 'w') as f: for r in results: f.write('\n' + 24 * ' ' + "('%s', '%s')," % (r.state, r.name)) def _ready_to_run(self, name): """ Check that check 'name' havn't already run and that all checks listed in 'needs' have run i. e., it's ready to run. """ try: check = self.checkdict[name] except KeyError: return False if check.is_run: return False if check.registry.is_user_enabled() and not \ check.registry.user_enabled_value(): return False for dep in check.needs: if dep not in self.checkdict: self.log.warning('%s depends on deprecated %s' % (name, dep)) self.log.warning('Removing %s, cannot resolve deps' % name) del self.checkdict[name] return True elif not self.checkdict[dep].is_run: return False return True def deprecate(self): ''' Mark all deprecated tests as run. ''' allkeys = list(self.checkdict.iterkeys()) for c in allkeys: if c not in self.checkdict: continue if self.checkdict[c].is_applicable(): self.checkdict.fix_deprecations(c) def _get_ready_to_run(self): ''' Return checks ready to run, deprecating checks first. ''' names = list(self.checkdict.iterkeys()) tests_to_run = filter(self._ready_to_run, names) return sorted(tests_to_run, key=lambda t: len(self.checkdict[t].deprecates), reverse=True) def is_external_plugin_installed(self, group_name): ''' Return True if external plugin install for given group. ''' for reg_group, registry in self.groups.iteritems(): basename = reg_group.split('.')[0] if basename == group_name and registry.external_plugin: return True return False def run_checks(self, output=sys.stdout, writedown=True): ''' Run all checks. ''' def run_check(name): """ Run check. Update results, attachments and issues. """ check = self.checkdict[name] if check.is_run: return self.log.debug('Running check: ' + name) check.run() now = time.time() self.log.debug(' %s completed: %.3f seconds' % (name, (now - self._clock))) self._clock = now attachments.extend(check.attachments) result = check.result if not result: return results.append(result) if result.type == 'MUST' and result.result == "fail": issues.append(result) issues = [] results = [] attachments = [] has_deprecated = False tests_to_run = self._get_ready_to_run() self._clock = time.time() while tests_to_run != []: for name in tests_to_run: if self.checkdict[name].deprecates and not has_deprecated: self.deprecate() has_deprecated = True break run_check(name) tests_to_run = self._get_ready_to_run() if writedown: key_getter = attrgetter('group', 'type', 'name') write_template(output, sorted(results, key=key_getter), issues, attachments) write_xml_report(self.spec, results) else: with open('.testlog.txt', 'w') as f: for r in results: f.write('\n' + 24 * ' ' + "('%s', '%s')," % (r.state, r.name))