2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
6 sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules')
9 from common import checkdir
11 from config import sign_key
12 from sign import is_signed, signpkgs
17 opts, args = getopt.getopt(sys.argv[1:], '')
18 except getopt.GetoptError:
19 print >>sys.stderr, "ERR: options error"
20 print >>sys.stderr, "sign.py tree package1 [package2...]"
24 print >>sys.stderr, "ERR: missing tree name"
25 print >>sys.stderr, "sign.py tree package1 [package2...]"
29 print >>sys.stderr, "ERR: sign_key not defined in config"
39 if not ftpio.lock(treename, True):
40 print >>sys.stderr, "ERR: %s tree already locked" % treename
50 # if no files specified, grab whole tree contents
51 tree = ftptree.FtpTree(treename, loadall = loadall)
53 # this is hack, should be a param, not access private .loadedpkgs element
54 tree.mark4moving(tree.loadedpkgs)
56 tree.mark4moving(packages)
57 files = tree.rpmfiles()
59 except ftptree.SomeError:
60 # In case of problems we need to unlock the tree before exiting
61 ftpio.unlock(treename)
64 ftpio.unlock(treename)
66 print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
70 if not is_signed(file):
74 print "\r%d/%d %s\033[0K" % (n, c, file),
79 print "No files to sign"
82 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
83 def chunk(seq, size, pad=None):
85 Slice a list into consecutive disjoint 'chunks' of
86 length equal to size. The last chunk is padded if necessary.
88 >>> list(chunk(range(1,10),3))
89 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
90 >>> list(chunk(range(1,9),3))
91 [[1, 2, 3], [4, 5, 6], [7, 8, None]]
92 >>> list(chunk(range(1,8),3))
93 [[1, 2, 3], [4, 5, 6], [7, None, None]]
94 >>> list(chunk(range(1,10),1))
95 [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
96 >>> list(chunk(range(1,10),9))
97 [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
98 >>> for X in chunk([],3): print X
103 for i in xrange(0, n - mod, size):
104 yield seq[i : i + size]
108 print "Total %d files to sign" % len(sign)
109 password = getpass.getpass("Enter signing password: ")
111 for x in chunk(sign, 512):
112 print "Signing %d files" % len(x)
113 signpkgs(x, password)
115 print >>sys.stderr, "ERR: %s" % e