pld-ftp-admin: scripts/lintpkg.py - run each file, cache it's output by mtime

glen glen at pld-linux.org
Wed Feb 9 08:53:02 CET 2011


Author: glen                         Date: Wed Feb  9 07:53:02 2011 GMT
Module: pld-ftp-admin                 Tag: HEAD
---- Log message:
- run each file, cache it's output by mtime

---- Files affected:
pld-ftp-admin/scripts:
   lintpkg.py (1.2 -> 1.3) 

---- Diffs:

================================================================
Index: pld-ftp-admin/scripts/lintpkg.py
diff -u pld-ftp-admin/scripts/lintpkg.py:1.2 pld-ftp-admin/scripts/lintpkg.py:1.3
--- pld-ftp-admin/scripts/lintpkg.py:1.2	Thu Feb  3 08:35:25 2011
+++ pld-ftp-admin/scripts/lintpkg.py	Wed Feb  9 08:52:57 2011
@@ -44,38 +44,31 @@
 
 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.
+cachedir = os.path.expanduser("~/tmp/rpmlint")
+if not os.path.isdir(cachedir):
+    os.makedirs(cachedir)
 
-     >>> 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(file):
+    (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()
+
+    # print result (from cache)
+    print "".join(open(cachefile, 'r').readlines())
 
-def rpmlint(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 of %d files" % (len(x), len(files))
+for x in files:
+    print "rpmlint %s" % x
     rpmlint(x)
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/pld-ftp-admin/scripts/lintpkg.py?r1=1.2&r2=1.3&f=u



More information about the pld-cvs-commit mailing list