2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
4 from __future__ import print_function
8 sys.path.insert(0, os.environ['HOME']+'/tld-ftp-admin/modules')
11 from common import checkdir
13 from config import sign_key
14 from sign import is_signed, signpkgs
19 opts, args = getopt.getopt(sys.argv[1:], '')
20 except getopt.GetoptError:
21 print("ERR: options error", file=sys.stderr)
22 print("sign.py tree package1 [package2...]", file=sys.stderr)
26 print("ERR: missing tree name", file=sys.stderr)
27 print("sign.py tree package1 [package2...]", file=sys.stderr)
31 print("ERR: sign_key not defined in config", file=sys.stderr)
41 if not ftpio.lock(treename, True):
42 print("ERR: %s tree already locked" % treename, file=sys.stderr)
52 # if no files specified, grab whole tree contents
53 tree = ftptree.FtpTree(treename, loadall = loadall)
55 # this is hack, should be a param, not access private .loadedpkgs element
56 tree.mark4moving(tree.loadedpkgs)
58 tree.mark4moving(packages)
59 files = tree.rpmfiles()
61 except ftptree.SomeError:
62 # In case of problems we need to unlock the tree before exiting
63 ftpio.unlock(treename)
66 ftpio.unlock(treename)
68 print("Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs)))
72 if not is_signed(file):
76 print("\r%d/%d %s\033[0K" % (n, c, file), end='')
81 print("No files to sign")
84 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
85 def chunk(seq, size, pad=None):
87 Slice a list into consecutive disjoint 'chunks' of
88 length equal to size. The last chunk is padded if necessary.
90 >>> list(chunk(range(1,10),3))
91 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
92 >>> list(chunk(range(1,9),3))
93 [[1, 2, 3], [4, 5, 6], [7, 8, None]]
94 >>> list(chunk(range(1,8),3))
95 [[1, 2, 3], [4, 5, 6], [7, None, None]]
96 >>> list(chunk(range(1,10),1))
97 [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
98 >>> list(chunk(range(1,10),9))
99 [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
100 >>> for X in chunk([],3): print(X)
105 for i in range(0, n - mod, size):
106 yield seq[i : i + size]
110 print("Total %d files to sign" % len(sign))
111 password = getpass.getpass("Enter signing password: ")
113 for x in chunk(sign, 512):
114 print("Signing %d files" % len(x))
115 signpkgs(x, password)
117 print("ERR: %s" % e, file=sys.stderr)