]> git.pld-linux.org Git - projects/pld-ftp-admin.git/commitdiff
- run each file, cache it's output by mtime
authorElan Ruusamäe <glen@pld-linux.org>
Wed, 9 Feb 2011 07:52:57 +0000 (07:52 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Wed, 9 Feb 2011 07:52:57 +0000 (07:52 +0000)
Changed files:
    bin/pfa-lintpkg -> 1.3

bin/pfa-lintpkg

index a5ce67f9dbd42e39b5ddb8ac2123569da32be257..509de1aa1a0408f35d1b28c0f135ecf511ad172b 100644 (file)
@@ -44,38 +44,31 @@ except ftptree.SomeError:
 
 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)
This page took 0.0635 seconds and 4 git commands to generate.