pld-ftp-admin: scripts/lintpkg.py (NEW) - add wrapper to call rpmlint

glen glen at pld-linux.org
Tue Feb 1 21:39:37 CET 2011


Author: glen                         Date: Tue Feb  1 20:39:37 2011 GMT
Module: pld-ftp-admin                 Tag: HEAD
---- Log message:
- add wrapper to call rpmlint

---- Files affected:
pld-ftp-admin/scripts:
   lintpkg.py (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: pld-ftp-admin/scripts/lintpkg.py
diff -u /dev/null pld-ftp-admin/scripts/lintpkg.py:1.1
--- /dev/null	Tue Feb  1 21:39:37 2011
+++ pld-ftp-admin/scripts/lintpkg.py	Tue Feb  1 21:39:32 2011
@@ -0,0 +1,72 @@
+#!/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) < 3:
+    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:
+    tree = ftptree.FtpTree(sys.argv[1])
+    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])
+
+# http://mail.python.org/pipermail/python-list/2009-February/700658.html
+def chunk(seq, size, pad=None):
+     '''
+     Slice a list into consecutive disjoint 'chunks' of
+     length equal to size. The last chunk is padded if necessary.
+
+     >>> list(chunk(range(1,10),3))
+     [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
+     >>> list(chunk(range(1,9),3))
+     [[1, 2, 3], [4, 5, 6], [7, 8, None]]
+     >>> list(chunk(range(1,8),3))
+     [[1, 2, 3], [4, 5, 6], [7, None, None]]
+     >>> list(chunk(range(1,10),1))
+     [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
+     >>> list(chunk(range(1,10),9))
+     [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
+     >>> for X in chunk([],3): print X
+     >>>
+     '''
+     n = len(seq)
+     mod = n % size
+     for i in xrange(0, n - mod, size):
+         yield seq[i : i + size]
+     if mod:
+         yield seq[-mod:]
+
+def rpmlint(files):
+    print files
+    cmd = ['/usr/bin/rpmlint'] + files
+    rc = subprocess.call(cmd, stdin = subprocess.PIPE, stdout = sys.stdout, stderr = sys.stderr, close_fds = True)
+    return rc == 0
+
+print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
+for x in chunk(files, 512):
+    print "rpmlint %d files" % len(x)
+    rpmlint(x)
================================================================


More information about the pld-cvs-commit mailing list