#!/usr/bin/env python # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import sys, os import subprocess sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') import ftptree from common import checkdir import ftpio if len(sys.argv) < 2: print >>sys.stderr, "ERR: not enough parameters given" print >>sys.stderr, "rpmlint.py tree package1 [package2...]" sys.exit(1) checkdir(sys.argv[1]) ftpio.connect('rpmlint') if not ftpio.lock(sys.argv[1], True): print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1] sys.exit(1) files = [] try: if len(sys.argv) < 3: loadall = True else: loadall = False # if no files specified, grab whole tree contents tree = ftptree.FtpTree(sys.argv[1], loadall = loadall) if loadall: # this is hack, should be a param, not access private .loadedpkgs element tree.mark4moving(tree.loadedpkgs) else: tree.mark4moving(sys.argv[2:]) files = tree.rpmfiles(debugfiles = False, sourcefiles = False) except ftptree.SomeError: # In case of problems we need to unlock the tree before exiting ftpio.unlock(sys.argv[1]) sys.exit(1) ftpio.unlock(sys.argv[1]) cachedir = os.path.expanduser("~/tmp/rpmlint") if not os.path.isdir(cachedir): os.makedirs(cachedir) def rpmlint(file): (dirname,filename) = os.path.split(file) cachefile = os.path.join(cachedir, filename+'.txt') rc = None if not os.path.exists(cachefile) or os.stat(file).st_mtime > os.stat(cachefile).st_mtime: cmd = ['/usr/bin/rpmlint', file] outfd = open(cachefile, 'w') try: rc = subprocess.call(cmd, stdin = subprocess.PIPE, stdout = outfd, stderr = outfd, close_fds = True) except KeyboardInterrupt: os.unlink(cachefile) raise outfd.close() # print result (from cache) print "".join(open(cachefile, 'r').readlines()) return rc == 0 print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) for x in files: print "rpmlint %s" % x rpmlint(x)