2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
5 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
7 from common import checkdir
9 from config import sign_key
10 from sign import is_signed, signpkgs
13 print >>sys.stderr, "ERR: not enough parameters given"
14 print >>sys.stderr, "sign.py tree package1 [package2...]"
18 print >>sys.stderr, "ERR: sign_key not defined in config"
25 if not ftpio.lock(sys.argv[1], True):
26 print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1]
31 tree = ftptree.FtpTree(sys.argv[1])
32 tree.mark4moving(sys.argv[2:])
33 files = tree.rpmfiles()
35 except ftptree.SomeError:
36 # In case of problems we need to unlock the tree before exiting
37 ftpio.unlock(sys.argv[1])
40 ftpio.unlock(sys.argv[1])
42 print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
46 print "\r%d/%d %s\033[0K" % (n, c, file),
47 if not is_signed(file):
55 print "No files to sign"
58 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
59 def chunk(seq, size, pad=None):
61 Slice a list into consecutive disjoint 'chunks' of
62 length equal to size. The last chunk is padded if necessary.
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
79 for i in xrange(0, n - mod, size):
80 yield seq[i : i + size]
84 print "Total %d files to sign" % len(sign)
86 for x in chunk(sign, 512):
87 print "Signing %d files" % len(x)
90 print >>sys.stderr, "ERR: %s" % e