def check_source(self, pkg): # lookup spec file for fname, pkgfile in pkg.files().items(): if fname.endswith('.spec'): self._spec_file = pkgfile.path with Pkg.FakePkg(pkgfile.path) as package: self.check_spec(package)
def check_source(self, pkg): """Find specfile in SRPM and run spec file related checks.""" wrong_spec = False self._spec_file = None self._spec_name = None # Check if a specfile exist in a specified path for fname, pkgfile in pkg.files.items(): if fname.endswith('.spec'): self._spec_file = pkgfile.path self._spec_name = pkgfile.name if fname == pkg.name + '.spec': wrong_spec = False break else: wrong_spec = True # method call self._check_no_spec_file(pkg) self._check_invalid_spec_name(pkg, wrong_spec) if self._spec_file: # check content of spec file with Pkg.FakePkg(self._spec_file) as package: self.check_spec(package)
def check_source(self, pkg): wrong_spec = False # lookup spec file for fname, pkgfile in pkg.files().items(): if fname.endswith('.spec'): self._spec_file = pkgfile.path self._spec_name = pkgfile.name if fname == pkg.name + '.spec': wrong_spec = False break else: wrong_spec = True if not self._spec_file: self.output.add_info('E', pkg, 'no-spec-file') else: if wrong_spec: self.output.add_info('E', pkg, 'invalid-spec-name') # check content of spec file with Pkg.FakePkg(self._spec_file) as package: self.check_spec(package)
def main(): locale.setlocale(locale.LC_COLLATE, '') output = Filter(cfg) # Load all checks for c in cfg.configuration['Checks']: loadCheck(c, cfg, output) packages_checked = 0 specfiles_checked = 0 try: # Loop over all file names given in arguments dirs = [] for arg in args: pkgs = [] isfile = False try: if arg == '-': arg = '(standard input)' # Short-circuit stdin spec file check stdin = sys.stdin.readlines() if not stdin: continue with Pkg.FakePkg(arg) as pkg: runSpecChecks(pkg, None, spec_lines=stdin) specfiles_checked += 1 continue try: st = os.stat(arg) isfile = True if stat.S_ISREG(st[stat.ST_MODE]): if arg.endswith('.spec'): # Short-circuit spec file checks with Pkg.FakePkg(arg) as pkg: runSpecChecks(pkg, arg) specfiles_checked += 1 elif '/' in arg or arg.endswith('.rpm') or \ arg.endswith('.spm'): pkgs.append(Pkg.Pkg(arg, extract_dir)) else: raise OSError elif stat.S_ISDIR(st[stat.ST_MODE]): dirs.append(arg) continue else: raise OSError except OSError: ipkgs = Pkg.getInstalledPkgs(arg) if not ipkgs: print_warning( '(none): E: no installed packages by name %s' % arg) else: ipkgs.sort(key=lambda x: locale.strxfrm( x.header.sprintf('%{NAME}.%{ARCH}'))) pkgs.extend(ipkgs) except KeyboardInterrupt: if isfile: arg = os.path.abspath(arg) print_warning( '(none): E: interrupted, exiting while reading %s' % arg) sys.exit(2) except Exception as e: if isfile: arg = os.path.abspath(arg) print_warning('(none): E: error while reading %s: %s' % (arg, e)) pkgs = [] continue for pkg in pkgs: with pkg: runChecks(pkg) packages_checked += 1 for dname in dirs: try: for path, _, files in os.walk(dname): for fname in files: fname = os.path.abspath(os.path.join(path, fname)) try: if fname.endswith('.rpm') or \ fname.endswith('.spm'): with Pkg.Pkg(fname, extract_dir) as pkg: runChecks(pkg) packages_checked += 1 elif fname.endswith('.spec'): with Pkg.FakePkg(fname) as pkg: runSpecChecks(pkg, fname) specfiles_checked += 1 except KeyboardInterrupt: print_warning( '(none): E: interrupted while reading %s' % fname) sys.exit(2) except Exception as e: print_warning( '(none): E: while reading %s: %s' % (fname, e)) continue except Exception as e: print_warning( '(none): E: error while reading dir %s: %s' % (dname, e)) continue print(output.print_results(output.results)) if output.badness_threshold > 0 and output.score > output.badness_threshold: print_warning('(none): E: badness %d exceeds threshold %d, aborting.' % (output.score, output.badness_threshold)) sys.exit(66) finally: print('%d packages and %d specfiles checked; %d errors, %d warnings.' % (packages_checked, specfiles_checked, output.printed_messages['E'], output.printed_messages['W'])) if output.printed_messages['E'] > 0: sys.exit(64) sys.exit(0)