]> git.pld-linux.org Git - projects/pld-ftp-admin.git/commitdiff
- add getopt support and -q option
authorElan Ruusamäe <glen@pld-linux.org>
Thu, 10 Feb 2011 12:56:59 +0000 (12:56 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Thu, 10 Feb 2011 12:56:59 +0000 (12:56 +0000)
Changed files:
    bin/pfa-lintpkg -> 1.7

bin/pfa-lintpkg

index e6030693824644fe966a86d618bbf63065d41c43..f0c0cdfd1169c4fa698cd3b84501c0d7760d380c 100644 (file)
@@ -2,47 +2,63 @@
 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
 
 import sys, os, re
+import getopt
 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"
+try:
+    opts, args = getopt.getopt(sys.argv[1:], 'q', [ "quiet" ])
+except getopt.GetoptError:
+    print >>sys.stderr, "ERR: options error"
+    print >>sys.stderr, "rpmlint.py tree package1 [package2...]"
+    sys.exit(1)
+
+quiet = False
+for o, a in opts:
+    if o == "-q" or o == "--quiet":
+        quiet = True
+
+if len(args) < 1:
+    print >>sys.stderr, "ERR: missing tree name"
     print >>sys.stderr, "rpmlint.py tree package1 [package2...]"
     sys.exit(1)
 
-checkdir(sys.argv[1])
+treename = args[0]
+packages = args[1:]
+
+checkdir(treename)
 
 ftpio.connect('rpmlint')
 
-if not ftpio.lock(sys.argv[1], True):
-    print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1]
+if not ftpio.lock(treename, True):
+    print >>sys.stderr, "ERR: %s tree already locked" % treename
     sys.exit(1)
 
 files = []
 try:
-    if len(sys.argv) < 3:
+    if len(packages) < 1:
         loadall = True
     else:
         loadall = False
 
     # if no files specified, grab whole tree contents
-    tree = ftptree.FtpTree(sys.argv[1], loadall = loadall)
+    tree = ftptree.FtpTree(treename, 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:])
+        tree.mark4moving(packages)
     files = tree.rpmfiles(debugfiles = False, sourcefiles = False)
 
 except (ftptree.SomeError, KeyboardInterrupt), e:
     # In case of problems we need to unlock the tree before exiting
-    ftpio.unlock(sys.argv[1])
+    ftpio.unlock(treename)
     sys.exit(1)
 
-ftpio.unlock(sys.argv[1])
+ftpio.unlock(treename)
 
 class LintPkg:
     def __init__(self, cachedir):
@@ -105,10 +121,13 @@ class LintPkg:
             rc = 1
         return rc == 0
 
-print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
+if not quiet:
+    print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
 lint = LintPkg("~/tmp/rpmlint")
 for file in files:
     lint.rpmlint(file)
-    lint.print_stats(file)
+    if not quiet:
+        lint.print_stats(file)
 
-lint.print_stats()
+if not quiet:
+    lint.print_stats()
This page took 0.035526 seconds and 4 git commands to generate.