]>
Commit | Line | Data |
---|---|---|
f56d33c5 ER |
1 | #!/usr/bin/env python |
2 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et | |
3 | ||
4 | import sys, os | |
5 | sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules') | |
6 | import ftptree | |
7 | from common import checkdir | |
8 | import ftpio | |
55bd5397 | 9 | from config import sign_key |
42c96205 | 10 | from sign import is_signed, signpkgs |
f56d33c5 ER |
11 | |
12 | if len(sys.argv) < 3: | |
55bd5397 ER |
13 | print >>sys.stderr, "ERR: not enough parameters given" |
14 | print >>sys.stderr, "sign.py tree package1 [package2...]" | |
15 | sys.exit(1) | |
16 | ||
17 | if sign_key == None: | |
18 | print >>sys.stderr, "ERR: sign_key not defined in config" | |
f56d33c5 ER |
19 | sys.exit(1) |
20 | ||
21 | checkdir(sys.argv[1]) | |
22 | ||
23 | ftpio.connect('sign') | |
24 | ||
25 | if not ftpio.lock(sys.argv[1], True): | |
4e83e214 | 26 | print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1] |
f56d33c5 ER |
27 | sys.exit(1) |
28 | ||
42c96205 | 29 | files = [] |
f56d33c5 | 30 | try: |
42c96205 | 31 | tree = ftptree.FtpTree(sys.argv[1]) |
55bd5397 ER |
32 | tree.mark4moving(sys.argv[2:]) |
33 | files = tree.rpmfiles() | |
34 | ||
f56d33c5 ER |
35 | except ftptree.SomeError: |
36 | # In case of problems we need to unlock the tree before exiting | |
37 | ftpio.unlock(sys.argv[1]) | |
38 | sys.exit(1) | |
39 | ||
40 | ftpio.unlock(sys.argv[1]) | |
42c96205 ER |
41 | |
42 | print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs)) | |
43 | sign = [] | |
95843bd6 | 44 | n = c = 0 |
42c96205 | 45 | for file in files: |
95843bd6 | 46 | print "\r%d/%d %s\033[0K" % (n, c, file), |
42c96205 ER |
47 | if not is_signed(file): |
48 | sign.append(file) | |
95843bd6 ER |
49 | c += 1 |
50 | n += 1 | |
51 | ||
52 | print "" | |
42c96205 ER |
53 | |
54 | if len(sign) == 0: | |
4e15eddf | 55 | print "No files to sign" |
42c96205 ER |
56 | sys.exit(0) |
57 | ||
95843bd6 ER |
58 | # http://mail.python.org/pipermail/python-list/2009-February/700658.html |
59 | def chunk(seq, size, pad=None): | |
60 | ''' | |
61 | Slice a list into consecutive disjoint 'chunks' of | |
62 | length equal to size. The last chunk is padded if necessary. | |
63 | ||
64 | >>> list(chunk(range(1,10),3)) | |
65 | [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | |
66 | >>> list(chunk(range(1,9),3)) | |
67 | [[1, 2, 3], [4, 5, 6], [7, 8, None]] | |
68 | >>> list(chunk(range(1,8),3)) | |
69 | [[1, 2, 3], [4, 5, 6], [7, None, None]] | |
70 | >>> list(chunk(range(1,10),1)) | |
71 | [[1], [2], [3], [4], [5], [6], [7], [8], [9]] | |
72 | >>> list(chunk(range(1,10),9)) | |
73 | [[1, 2, 3, 4, 5, 6, 7, 8, 9]] | |
74 | >>> for X in chunk([],3): print X | |
75 | >>> | |
76 | ''' | |
77 | n = len(seq) | |
78 | mod = n % size | |
79 | for i in xrange(0, n - mod, size): | |
80 | yield seq[i : i + size] | |
81 | if mod: | |
82 | yield seq[-mod:] | |
83 | ||
84 | print "Total %d files to sign" % len(sign) | |
4e83e214 | 85 | try: |
95843bd6 ER |
86 | for x in chunk(sign, 512): |
87 | print "Signing %d files" % len(x) | |
88 | signpkgs(x) | |
4e83e214 ER |
89 | except OSError, e: |
90 | print >>sys.stderr, "ERR: %s" % e | |
91 | exit(1) |