2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
5 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
8 from common import checkdir
10 from config import sign_key
11 from sign import is_signed, signpkgs
14 print >>sys.stderr, "ERR: not enough parameters given"
15 print >>sys.stderr, "sign.py tree package1 [package2...]"
19 print >>sys.stderr, "ERR: sign_key not defined in config"
26 if not ftpio.lock(sys.argv[1], True):
27 print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1]
32 tree = ftptree.FtpTree(sys.argv[1])
33 tree.mark4moving(sys.argv[2:])
34 files = tree.rpmfiles()
36 except ftptree.SomeError:
37 # In case of problems we need to unlock the tree before exiting
38 ftpio.unlock(sys.argv[1])
41 ftpio.unlock(sys.argv[1])
43 print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
47 if not is_signed(file):
51 print "\r%d/%d %s\033[0K" % (n, c, file),
56 print "No files to sign"
59 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
60 def chunk(seq, size, pad=None):
62 Slice a list into consecutive disjoint 'chunks' of
63 length equal to size. The last chunk is padded if necessary.
65 >>> list(chunk(range(1,10),3))
66 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
67 >>> list(chunk(range(1,9),3))
68 [[1, 2, 3], [4, 5, 6], [7, 8, None]]
69 >>> list(chunk(range(1,8),3))
70 [[1, 2, 3], [4, 5, 6], [7, None, None]]
71 >>> list(chunk(range(1,10),1))
72 [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
73 >>> list(chunk(range(1,10),9))
74 [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
75 >>> for X in chunk([],3): print X
80 for i in xrange(0, n - mod, size):
81 yield seq[i : i + size]
85 print "Total %d files to sign" % len(sign)
86 password = getpass.getpass("Enter signing password: ")
88 for x in chunk(sign, 512):
89 print "Signing %d files" % len(x)
92 print >>sys.stderr, "ERR: %s" % e