def main(): ignore_tags = [] try: opts, args = getopt.getopt(sys.argv[1:], "hti:", ["help", "ignore-times", "ignore="]) except getopt.GetoptError as e: Pkg.warn("Error: %s" % e) _usage() for option, argument in opts: if option in ("-h", "--help"): _usage(0) if option in ("-t", "--ignore-times"): # deprecated; --ignore=T should be used instead ignore_tags.append("T") if option in ("-i", "--ignore"): ignore_tags.append(argument) if len(args) != 2: _usage() d = Rpmdiff(args[0], args[1], ignore=ignore_tags) textdiff = d.textdiff() if textdiff: print(textdiff) sys.exit(int(d.differs()))
def runSpecChecks(pkg, fname, spec_lines=None): if verbose: printInfo(pkg, 'checking') for name in Config.allChecks(): check = AbstractCheck.known_checks.get(name) if check: check.verbose = verbose check.check_spec(pkg, fname, spec_lines) else: Pkg.warn('(none): W: unknown check %s, skipping' % name)
def check(self, pkg): res = pkg.checkSignature() if not res or res[0] != 0: if res and res[1]: kres = SignatureCheck.unknown_key_regex.search(res[1]) else: kres = None if kres: printError(pkg, "unknown-key", kres.group(1)) else: Pkg.warn("Error checking signature of %s: %s" % (pkg.filename, res[1])) else: if not SignatureCheck.pgp_regex.search(res[1]): printError(pkg, "no-signature")
def main(): locale.setlocale(locale.LC_COLLATE, '') # Add check dirs to the front of load path sys.path[0:0] = Config.checkDirs() # Load all checks for c in Config.allChecks(): loadCheck(c) 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: Pkg.warn( '(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) Pkg.warn('(none): E: interrupted, exiting while reading %s' % arg) sys.exit(2) except Exception as e: if isfile: arg = os.path.abspath(arg) Pkg.warn('(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: Pkg.warn( '(none): E: interrupted while reading %s' % fname) sys.exit(2) except Exception as e: Pkg.warn('(none): E: while reading %s: %s' % (fname, e)) continue except Exception as e: Pkg.warn('(none): E: error while reading dir %s: %s' % (dname, e)) continue if printAllReasons(): Pkg.warn('(none): E: badness %d exceeds threshold %d, aborting.' % (badnessScore(), badnessThreshold())) sys.exit(66) finally: print("%d packages and %d specfiles checked; %d errors, %d warnings." % (packages_checked, specfiles_checked, printed_messages["E"], printed_messages["W"])) if printed_messages["E"] > 0: sys.exit(64) sys.exit(0)
############################################################################# # ############################################################################# argv0 = os.path.basename(sys.argv[0]) # parse options try: (opt, args) = getopt.getopt(sys.argv[1:], 'iI:c:C:hVvanE:f:o:', [ 'info', 'explain=', 'check=', 'checkdir=', 'help', 'version', 'verbose', 'all', 'noexception', 'extractdir=', 'file=', 'option=', 'rawout=' ]) except getopt.GetoptError as e: Pkg.warn("%s: %s" % (argv0, e)) usage(argv0) sys.exit(1) # process options checkdir = '/usr/share/rpmlint' checks = [] verbose = False extract_dir = None conf_file = _default_user_conf info_error = set() # load global config files configs = glob.glob('/etc/rpmlint/*config') configs.sort()
def __init__(self, old, new, ignore=None): self.result = [] self.ignore = ignore if self.ignore is None: self.ignore = [] FILEIDX = self.__FILEIDX for tag in self.ignore: for entry in FILEIDX: if tag == entry[0]: entry[1] = None break try: old = self.__load_pkg(old).header new = self.__load_pkg(new).header except KeyError as e: Pkg.warn(str(e)) sys.exit(2) # Compare single tags for tag in self.TAGS: old_tag = old[tag] new_tag = new[tag] if old_tag != new_tag: tagname = rpm.tagnames[tag] if old_tag is None: self.__add(self.FORMAT, (self.ADDED, tagname)) elif new_tag is None: self.__add(self.FORMAT, (self.REMOVED, tagname)) else: self.__add(self.FORMAT, ('S.5.....', tagname)) # compare Provides, Requires, ... for tag in self.PRCO: self.__comparePRCOs(old, new, tag) # compare the files old_files_dict = self.__fileIteratorToDict(old.fiFromHeader()) new_files_dict = self.__fileIteratorToDict(new.fiFromHeader()) files = list( set(itertools.chain(iter(old_files_dict), iter(new_files_dict)))) files.sort() for f in files: diff = False old_file = old_files_dict.get(f) new_file = new_files_dict.get(f) if not old_file: self.__add(self.FORMAT, (self.ADDED, f)) elif not new_file: self.__add(self.FORMAT, (self.REMOVED, f)) else: format = '' for entry in FILEIDX: if entry[1] is not None and \ old_file[entry[1]] != new_file[entry[1]]: format = format + entry[0] diff = True else: format = format + '.' if diff: self.__add(self.FORMAT, (format, f))