X-Git-Url: https://git.tld-linux.org/?p=tld-ftp-admin.git;a=blobdiff_plain;f=bin%2Fpfa-lintpkg;h=5fe2a101fe0ac7b3f9522ba5f2d80b4ffe349218;hp=dca510f029292ea69c255c1f9614124ecb4bba4c;hb=51b9814081f743180ffed6c80fd7945acb554ce2;hpb=f7b22268ab563fa906be0653d037f1805e220e5c diff --git a/bin/pfa-lintpkg b/bin/pfa-lintpkg index dca510f..5fe2a10 100755 --- a/bin/pfa-lintpkg +++ b/bin/pfa-lintpkg @@ -1,6 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et +from __future__ import print_function + import sys, os, re import getopt import subprocess @@ -12,8 +14,8 @@ import ftpio try: opts, args = getopt.getopt(sys.argv[1:], 'qsdo:', [ "quiet" ]) except getopt.GetoptError: - print >>sys.stderr, "ERR: options error" - print >>sys.stderr, "rpmlint.py tree package1 [package2...]" + print("ERR: options error", file=sys.stderr) + print("rpmlint.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) quiet = False @@ -31,8 +33,8 @@ for o, a in opts: outstream = open(a, 'w') if len(args) < 1: - print >>sys.stderr, "ERR: missing tree name" - print >>sys.stderr, "rpmlint.py tree package1 [package2...]" + print("ERR: missing tree name", file=sys.stderr) + print("rpmlint.py tree package1 [package2...]", file=sys.stderr) sys.exit(1) treename = args[0] @@ -43,7 +45,7 @@ checkdir(treename) ftpio.connect('rpmlint') if not ftpio.lock(treename, True): - print >>sys.stderr, "ERR: %s tree already locked" % treename + print("ERR: %s tree already locked" % treename, file=sys.stderr) sys.exit(1) files = [] @@ -63,7 +65,7 @@ try: tree.mark4moving(packages) files = tree.rpmfiles(debugfiles = debugfiles, sourcefiles = False) -except (ftptree.SomeError, KeyboardInterrupt), e: +except (ftptree.SomeError, KeyboardInterrupt) as e: # In case of problems we need to unlock the tree before exiting ftpio.unlock(treename) sys.exit(1) @@ -97,7 +99,7 @@ class LintPkg: def get_stats(self, file): cachefile = self.cachefile(file) - if not os.path.exists(cachefile): + if not os.path.exists(cachefile) or os.path.getsize(cachefile) <= 0: return None # show last line (that contains status) @@ -129,13 +131,13 @@ class LintPkg: def print_stats(self, file = None): if file: (dirname, filename) = os.path.split(file) - print >>self.outstream, "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings. [%s]" % (self.packages, self.specfiles, self.errors, self.warnings, filename), + print("\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings. [%s]" % (self.packages, self.specfiles, self.errors, self.warnings, filename), file=self.outstream) else: - print >>self.outstream, "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (self.packages, self.specfiles, self.errors, self.warnings) + print("\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (self.packages, self.specfiles, self.errors, self.warnings), file=self.outstream) sys.stdout.flush() def cat(self, file): - print >>self.outstream, "".join(open(file, 'r').readlines()) + print("".join(open(file, 'r').readlines()), file=self.outstream) def show_results(self, file): m = self.get_stats(file) @@ -144,11 +146,11 @@ class LintPkg: cachefile = self.cachefile(file) if not os.path.exists(cachefile): - print >>self.outsteram, "MISSING: report: %s" % file + print("MISSING: report: %s" % file, file=self.outstream) if m['errors'] > 0 or m['warnings'] > 0: (dirname, filename) = os.path.split(file) - print >>self.outstream, "rpmlint: %s" % filename + print("rpmlint: %s" % filename, file=self.outstream) self.cat(cachefile) def rpmlint(self, file): @@ -177,11 +179,11 @@ class LintPkg: try: lock = 'rpmlint:'+treename if not ftpio.lock(lock, True): - print >>sys.stderr, "ERR: %s tree already locked for rpmlint" % treename + print("ERR: %s tree already locked for rpmlint" % treename, file=sys.stderr) sys.exit(1) if not quiet: - print >>outstream, "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) + print("rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)), file=outstream) lint = LintPkg("~/tmp/rpmlint") lint.outstream = outstream for file in files: