]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - bin/pfa-signpkg
- signpkg: allow signing whole tree if no pkgname given
[projects/pld-ftp-admin.git] / bin / pfa-signpkg
CommitLineData
f56d33c5
ER
1#!/usr/bin/env python
2# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3
4import sys, os
5a666fec 5import getopt
f56d33c5
ER
6sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
7import ftptree
89b8ea8d 8import getpass
f56d33c5
ER
9from common import checkdir
10import ftpio
55bd5397 11from config import sign_key
42c96205 12from sign import is_signed, signpkgs
f56d33c5 13
5a666fec
ER
14try:
15 opts, args = getopt.getopt(sys.argv[1:], '')
16except getopt.GetoptError:
17 print >>sys.stderr, "ERR: options error"
18 print >>sys.stderr, "sign.py tree package1 [package2...]"
19 sys.exit(1)
20
21if len(args) < 1:
22 print >>sys.stderr, "ERR: missing tree name"
55bd5397
ER
23 print >>sys.stderr, "sign.py tree package1 [package2...]"
24 sys.exit(1)
25
26if sign_key == None:
27 print >>sys.stderr, "ERR: sign_key not defined in config"
f56d33c5
ER
28 sys.exit(1)
29
5a666fec
ER
30treename = args[0]
31packages = args[1:]
32
33checkdir(treename)
f56d33c5
ER
34
35ftpio.connect('sign')
36
5a666fec
ER
37if not ftpio.lock(treename, True):
38 print >>sys.stderr, "ERR: %s tree already locked" % treename
f56d33c5
ER
39 sys.exit(1)
40
42c96205 41files = []
f56d33c5 42try:
5a666fec
ER
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)
55bd5397
ER
55 files = tree.rpmfiles()
56
f56d33c5
ER
57except ftptree.SomeError:
58 # In case of problems we need to unlock the tree before exiting
5a666fec 59 ftpio.unlock(treename)
f56d33c5
ER
60 sys.exit(1)
61
5a666fec 62ftpio.unlock(treename)
42c96205
ER
63
64print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
65sign = []
95843bd6 66n = c = 0
42c96205
ER
67for file in files:
68 if not is_signed(file):
69 sign.append(file)
95843bd6
ER
70 c += 1
71 n += 1
2000899b 72 print "\r%d/%d %s\033[0K" % (n, c, file),
95843bd6
ER
73
74print ""
42c96205
ER
75
76if len(sign) == 0:
4e15eddf 77 print "No files to sign"
42c96205
ER
78 sys.exit(0)
79
95843bd6
ER
80# http://mail.python.org/pipermail/python-list/2009-February/700658.html
81def 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
106print "Total %d files to sign" % len(sign)
89b8ea8d 107password = getpass.getpass("Enter signing password: ")
4e83e214 108try:
95843bd6
ER
109 for x in chunk(sign, 512):
110 print "Signing %d files" % len(x)
89b8ea8d 111 signpkgs(x, password)
4e83e214
ER
112except OSError, e:
113 print >>sys.stderr, "ERR: %s" % e
114 exit(1)
This page took 0.051936 seconds and 4 git commands to generate.