]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - bin/pfa-signpkg
- chunk the signing to 512 packages a time
[projects/pld-ftp-admin.git] / bin / pfa-signpkg
1 #!/usr/bin/env python
2 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3
4 import sys, os
5 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
6 import ftptree
7 from common import checkdir
8 import ftpio
9 from config import sign_key
10 from sign import is_signed, signpkgs
11
12 if len(sys.argv) < 3:
13     print >>sys.stderr, "ERR: not enough parameters given"
14     print >>sys.stderr, "sign.py tree package1 [package2...]"
15     sys.exit(1)
16
17 if sign_key == None:
18     print >>sys.stderr, "ERR: sign_key not defined in config"
19     sys.exit(1)
20
21 checkdir(sys.argv[1])
22
23 ftpio.connect('sign')
24
25 if not ftpio.lock(sys.argv[1], True):
26     print >>sys.stderr, "ERR: %s tree already locked" % sys.argv[1]
27     sys.exit(1)
28
29 files = []
30 try:
31     tree = ftptree.FtpTree(sys.argv[1])
32     tree.mark4moving(sys.argv[2:])
33     files = tree.rpmfiles()
34
35 except ftptree.SomeError:
36     # In case of problems we need to unlock the tree before exiting
37     ftpio.unlock(sys.argv[1])
38     sys.exit(1)
39
40 ftpio.unlock(sys.argv[1])
41
42 print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
43 sign = []
44 n = c = 0
45 for file in files:
46     print "\r%d/%d %s\033[0K" % (n, c, file),
47     if not is_signed(file):
48         sign.append(file)
49         c += 1
50     n += 1
51
52 print ""
53
54 if len(sign) == 0:
55     print "No files to sign"
56     sys.exit(0)
57
58 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
59 def chunk(seq, size, pad=None):
60      '''
61      Slice a list into consecutive disjoint 'chunks' of
62      length equal to size. The last chunk is padded if necessary.
63
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
75      >>>
76      '''
77      n = len(seq)
78      mod = n % size
79      for i in xrange(0, n - mod, size):
80          yield seq[i : i + size]
81      if mod:
82          yield seq[-mod:]
83
84 print "Total %d files to sign" % len(sign)
85 try:
86     for x in chunk(sign, 512):
87         print "Signing %d files" % len(x)
88         signpkgs(x)
89 except OSError, e:
90     print >>sys.stderr, "ERR: %s" % e
91     exit(1)
This page took 0.054368 seconds and 3 git commands to generate.