]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - bin/pfa-signpkg
show src.rpm package name in reports; very hackish due poldek bugs/missing features
[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 import getopt
6 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
7 import ftptree
8 import getpass
9 from common import checkdir
10 import ftpio
11 from config import sign_key
12 from sign import is_signed, signpkgs
13
14 try:
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...]"
19     sys.exit(1)
20
21 if len(args) < 1:
22     print >>sys.stderr, "ERR: missing tree name"
23     print >>sys.stderr, "sign.py tree package1 [package2...]"
24     sys.exit(1)
25
26 if sign_key == None:
27     print >>sys.stderr, "ERR: sign_key not defined in config"
28     sys.exit(1)
29
30 treename = args[0]
31 packages = args[1:]
32
33 checkdir(treename)
34
35 ftpio.connect('sign')
36
37 if not ftpio.lock(treename, True):
38     print >>sys.stderr, "ERR: %s tree already locked" % treename
39     sys.exit(1)
40
41 files = []
42 try:
43     if len(packages) < 1:
44         loadall = True
45     else:
46         loadall = False
47
48     # if no files specified, grab whole tree contents
49     tree = ftptree.FtpTree(treename, loadall = loadall)
50     if loadall:
51         # this is hack, should be a param, not access private .loadedpkgs element
52         tree.mark4moving(tree.loadedpkgs)
53     else:
54         tree.mark4moving(packages)
55     files = tree.rpmfiles()
56
57 except ftptree.SomeError:
58     # In case of problems we need to unlock the tree before exiting
59     ftpio.unlock(treename)
60     sys.exit(1)
61
62 ftpio.unlock(treename)
63
64 print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
65 sign = []
66 n = c = 0
67 for file in files:
68     if not is_signed(file):
69         sign.append(file)
70         c += 1
71     n += 1
72     print "\r%d/%d %s\033[0K" % (n, c, file),
73
74 print ""
75
76 if len(sign) == 0:
77     print "No files to sign"
78     sys.exit(0)
79
80 # http://mail.python.org/pipermail/python-list/2009-February/700658.html
81 def chunk(seq, size, pad=None):
82      '''
83      Slice a list into consecutive disjoint 'chunks' of
84      length equal to size. The last chunk is padded if necessary.
85
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
97      >>>
98      '''
99      n = len(seq)
100      mod = n % size
101      for i in xrange(0, n - mod, size):
102          yield seq[i : i + size]
103      if mod:
104          yield seq[-mod:]
105
106 print "Total %d files to sign" % len(sign)
107 password = getpass.getpass("Enter signing password: ")
108 try:
109     for x in chunk(sign, 512):
110         print "Signing %d files" % len(x)
111         signpkgs(x, password)
112 except OSError, e:
113     print >>sys.stderr, "ERR: %s" % e
114     exit(1)
This page took 0.027439 seconds and 3 git commands to generate.