#!/usr/bin/env python # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import sys, os, re 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) # for rpmlint stats packages = specfiles = errors = warnings = 0 # 1 packages and 0 specfiles checked; 0 errors, 0 warnings. lintre = re.compile('(?P\d+) packages and (?P\d+) specfiles checked; (?P\d+) errors, (?P\d+) warnings.') def rpmlint(file): global packages global specfiles global errors global warnings (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() # show last line (that contains status) l = (open(cachefile, 'r').readlines())[-1] m = lintre.match(l) if m: packages += int(m.group('packages')) specfiles += int(m.group('specfiles')) errors += int(m.group('errors')) warnings += int(m.group('warnings')) return rc == 0 print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) for x in files: (n, f) = os.path.split(x) print "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings. [%s]" % (packages, specfiles, errors, warnings, f), sys.stdout.flush() rpmlint(x) print "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (packages, specfiles, errors, warnings) print "Done"