2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
6 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
9 from common import checkdir
11 from config import sign_key
12 from sign import is_signed, signpkgs
15 opts, args = getopt.getopt(sys.argv[1:], '')
16 except getopt.GetoptError:
17 print >>sys.stderr, "ERR: options error"
18 print >>sys.stderr, "sign.py tree package1 [package2...]"
22 print >>sys.stderr, "ERR: missing tree name"
23 print >>sys.stderr, "sign.py tree package1 [package2...]"
27 print >>sys.stderr, "ERR: sign_key not defined in config"
37 if not ftpio.lock(treename, True):
38 print >>sys.stderr, "ERR: %s tree already locked" % treename
48 # if no files specified, grab whole tree contents
49 tree = ftptree.FtpTree(treename, loadall = loadall)
51 # this is hack, should be a param, not access private .loadedpkgs element
52 tree.mark4moving(tree.loadedpkgs)
54 tree.mark4moving(packages)
55 files = tree.rpmfiles()
57 except ftptree.SomeError:
58 # In case of problems we need to unlock the tree before exiting
59 ftpio.unlock(treename)
62 ftpio.unlock(treename)
64 print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
68 if not is_signed(file):
72 print "\r%d/%d %s\033[0K" % (n, c, file),
77 print "No files to sign"
80 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
81 def chunk(seq, size, pad=None):
83 Slice a list into consecutive disjoint 'chunks' of
84 length equal to size. The last chunk is padded if necessary.
86 >>> list(chunk(range(1,10),3))
87 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
88 >>> list(chunk(range(1,9),3))
89 [[1, 2, 3], [4, 5, 6], [7, 8, None]]
90 >>> list(chunk(range(1,8),3))
91 [[1, 2, 3], [4, 5, 6], [7, None, None]]
92 >>> list(chunk(range(1,10),1))
93 [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
94 >>> list(chunk(range(1,10),9))
95 [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
96 >>> for X in chunk([],3): print X
101 for i in xrange(0, n - mod, size):
102 yield seq[i : i + size]
106 print "Total %d files to sign" % len(sign)
107 password = getpass.getpass("Enter signing password: ")
109 for x in chunk(sign, 512):
110 print "Signing %d files" % len(x)
111 signpkgs(x, password)
113 print >>sys.stderr, "ERR: %s" % e