]> git.pld-linux.org Git - projects/pld-ftp-admin.git/commitdiff
- add -o outfile support
authorElan Ruusamäe <glen@pld-linux.org>
Thu, 17 Feb 2011 08:31:42 +0000 (08:31 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Thu, 17 Feb 2011 08:31:42 +0000 (08:31 +0000)
Changed files:
    bin/pfa-lintpkg -> 1.12

bin/pfa-lintpkg

index f7da0d7dab469785bb3169b310f78a75911d976d..ba9dd16913de43f7324622e7814c854fe9dd5019 100644 (file)
@@ -10,7 +10,7 @@ from common import checkdir
 import ftpio
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], 'qs', [ "quiet" ])
+    opts, args = getopt.getopt(sys.argv[1:], 'qso:', [ "quiet" ])
 except getopt.GetoptError:
     print >>sys.stderr, "ERR: options error"
     print >>sys.stderr, "rpmlint.py tree package1 [package2...]"
@@ -18,11 +18,14 @@ except getopt.GetoptError:
 
 quiet = False
 show = False
+outstream = sys.stdout
 for o, a in opts:
     if o == "-q" or o == "--quiet":
         quiet = True
     if o == "-s":
         show = True
+    if o == "-o":
+        outstream = open(a, 'w')
 
 if len(args) < 1:
     print >>sys.stderr, "ERR: missing tree name"
@@ -66,6 +69,8 @@ ftpio.unlock(treename)
 
 class LintPkg:
     def __init__(self, cachedir):
+        self.outstream = sys.stdout
+
         # for rpmlint stats
         self.packages = self.specfiles = self.errors = self.warnings = 0
         # 1 packages and 0 specfiles checked; 0 errors, 0 warnings.
@@ -115,13 +120,13 @@ class LintPkg:
     def print_stats(self, file = None):
         if file:
             (dirname, filename) = os.path.split(file)
-            print "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings. [%s]" % (self.packages, self.specfiles, self.errors, self.warnings, filename),
+            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),
         else:
-            print "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (self.packages, self.specfiles, self.errors, self.warnings)
+            print >>self.outstream, "\r\033[0K%d packages and %d specfiles checked; %d errors, %d warnings." % (self.packages, self.specfiles, self.errors, self.warnings)
         sys.stdout.flush()
 
     def cat(self, file):
-        print "".join(open(file, 'r').readlines())
+        print >>self.outstream, "".join(open(file, 'r').readlines())
 
     def show_results(self, file):
         m = self.get_stats(file)
@@ -130,9 +135,11 @@ class LintPkg:
 
         cachefile = self.cachefile(file)
         if not os.path.exists(cachefile):
-            print "MISSING: report: %s" % file
+            print >>self.outsteram, "MISSING: report: %s" % file
 
         if m['errors'] > 0 or m['warnings'] > 0:
+            (dirname, filename) = os.path.split(file)
+            print >>self.outstream, "rpmlint: %s" % filename
             self.cat(cachefile)
 
     def rpmlint(self, file):
@@ -162,8 +169,9 @@ try:
         sys.exit(1)
 
     if not quiet:
-        print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
+        print >>outstream, "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
     lint = LintPkg("~/tmp/rpmlint")
+    lint.outstream = outstream
     for file in files:
         lint.rpmlint(file)
         if not quiet:
@@ -175,6 +183,6 @@ try:
         lint.print_stats()
 
     ftpio.unlock(lock)
-except Exception:
+except (Exception, KeyboardInterrupt):
     ftpio.unlock(lock)
     raise
This page took 0.072047 seconds and 4 git commands to generate.