diff options
-rw-r--r-- | key_checker.py (renamed from key_checker) | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/key_checker b/key_checker.py index e7fdfc4..2130837 100644 --- a/key_checker +++ b/key_checker.py @@ -1,5 +1,6 @@ #!/usr/bin/python import rpm, rpmUtils.miscutils, sys +from optparse import OptionParser ts=rpm.TransactionSet() pubkeys={} @@ -26,36 +27,47 @@ def getSig(hdr): return (getPkgNevra(hdr), pubkeys['unknown']) else: return (getPkgNevra(hdr), 'unsigned') +def getPkg(name=None): + if name: + mi=ts.dbMatch(rpm.RPMTAG_NAME, name) + else: + mi=ts.dbMatch() + exists = False + for hdr in mi: + exists = True + if hdr[rpm.RPMTAG_NAME] == 'gpg-pubkey': continue + nevra, key = getSig(hdr) + pkgs[key].append(nevra) + if not exists: + sys.stderr.write('No such package %s\n' % name) if __name__ == '__main__': + usage = '%prog [options] pkg1 pkg2...' + parser = OptionParser(usage) + parser.add_option('-m', '--machine-readable', action='store_true', + dest='mr', help='Produce machine readable output') + options, args = parser.parse_args() buildKeyList() pkgs = {} for keyname in pubkeys.itervalues(): pkgs[keyname] = [] - pkgs['unsigned'] = [] - try: - foo = sys.argv[1] - for pkg in sys.argv[1:]: - mi=ts.dbMatch(rpm.RPMTAG_NAME, pkg) - exists = False - for hdr in mi: - exists = True - nevra, key=getSig(hdr) - pkgs[key].append(nevra) - if not exists: - sys.stderr.write('Package %s does not exist\n' % pkg) - except IndexError: - mi=ts.dbMatch() - for hdr in mi: - if hdr[rpm.RPMTAG_NAME] == 'gpg-pubkey': - continue - nevra, key = getSig(hdr) - pkgs[key].append(nevra) - for pkg in pkgs.iteritems(): - if pkg[1]: - print pkg[0] - print '-' * len(pkg[0]) - for pkginstance in pkg[1]: - print pkginstance - print + pkgs['unAsigned'] = [] + if len(args) != 0: + for pkg in args: + getPkg(pkg) + else: + getPkg() + if options.mr: + for pkg in pkgs.iteritems(): + if pkg[1]: + for pkginstance in pkg[1]: + print '%s,%s' % (pkginstance, pkg[0]) + else: + for pkg in pkgs.iteritems(): + if pkg[1]: + print pkg[0] + print '-' * len(pkg[0]) + for pkginstance in pkg[1]: + print pkginstance + print |