]>
Commit | Line | Data |
---|---|---|
03861ee2 ER |
1 | #!/usr/bin/env python |
2 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et | |
3 | ||
4 | import sys, os | |
5 | import subprocess | |
6 | sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') | |
7 | import ftptree | |
8 | from common import checkdir | |
9 | import ftpio | |
10 | ||
11 | if len(sys.argv) < 3: | |
12 | print >>sys.stderr, "ERR: not enough parameters given" | |
13 | print >>sys.stderr, "rpmlint.py tree package1 [package2...]" | |
14 | sys.exit(1) | |
15 | ||
16 | checkdir(sys.argv[1]) | |
17 | ||
18 | ftpio.connect('rpmlint') | |
19 | ||
20 | if not ftpio.lock(sys.argv[1], True): | |
21 | print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1] | |
22 | sys.exit(1) | |
23 | ||
24 | files = [] | |
25 | try: | |
26 | tree = ftptree.FtpTree(sys.argv[1]) | |
27 | tree.mark4moving(sys.argv[2:]) | |
28 | files = tree.rpmfiles(debugfiles = False, sourcefiles = False) | |
29 | ||
30 | except ftptree.SomeError: | |
31 | # In case of problems we need to unlock the tree before exiting | |
32 | ftpio.unlock(sys.argv[1]) | |
33 | sys.exit(1) | |
34 | ||
35 | ftpio.unlock(sys.argv[1]) | |
36 | ||
37 | # http://mail.python.org/pipermail/python-list/2009-February/700658.html | |
38 | def chunk(seq, size, pad=None): | |
39 | ''' | |
40 | Slice a list into consecutive disjoint 'chunks' of | |
41 | length equal to size. The last chunk is padded if necessary. | |
42 | ||
43 | >>> list(chunk(range(1,10),3)) | |
44 | [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | |
45 | >>> list(chunk(range(1,9),3)) | |
46 | [[1, 2, 3], [4, 5, 6], [7, 8, None]] | |
47 | >>> list(chunk(range(1,8),3)) | |
48 | [[1, 2, 3], [4, 5, 6], [7, None, None]] | |
49 | >>> list(chunk(range(1,10),1)) | |
50 | [[1], [2], [3], [4], [5], [6], [7], [8], [9]] | |
51 | >>> list(chunk(range(1,10),9)) | |
52 | [[1, 2, 3, 4, 5, 6, 7, 8, 9]] | |
53 | >>> for X in chunk([],3): print X | |
54 | >>> | |
55 | ''' | |
56 | n = len(seq) | |
57 | mod = n % size | |
58 | for i in xrange(0, n - mod, size): | |
59 | yield seq[i : i + size] | |
60 | if mod: | |
61 | yield seq[-mod:] | |
62 | ||
63 | def rpmlint(files): | |
64 | print files | |
65 | cmd = ['/usr/bin/rpmlint'] + files | |
66 | rc = subprocess.call(cmd, stdin = subprocess.PIPE, stdout = sys.stdout, stderr = sys.stderr, close_fds = True) | |
67 | return rc == 0 | |
68 | ||
69 | print "rpmlint of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) | |
70 | for x in chunk(files, 512): | |
71 | print "rpmlint %d files" % len(x) | |
72 | rpmlint(x) |