]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - bin/pfa-signpkg
qa reports: fix current report selection dropdown
[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
fc574b00
AM
14os.umask(022)
15
5a666fec
ER
16try:
17 opts, args = getopt.getopt(sys.argv[1:], '')
18except getopt.GetoptError:
19 print >>sys.stderr, "ERR: options error"
20 print >>sys.stderr, "sign.py tree package1 [package2...]"
21 sys.exit(1)
22
23if len(args) < 1:
24 print >>sys.stderr, "ERR: missing tree name"
55bd5397
ER
25 print >>sys.stderr, "sign.py tree package1 [package2...]"
26 sys.exit(1)
27
28if sign_key == None:
29 print >>sys.stderr, "ERR: sign_key not defined in config"
f56d33c5
ER
30 sys.exit(1)
31
5a666fec
ER
32treename = args[0]
33packages = args[1:]
34
35checkdir(treename)
f56d33c5
ER
36
37ftpio.connect('sign')
38
5a666fec
ER
39if not ftpio.lock(treename, True):
40 print >>sys.stderr, "ERR: %s tree already locked" % treename
f56d33c5
ER
41 sys.exit(1)
42
42c96205 43files = []
f56d33c5 44try:
5a666fec
ER
45 if len(packages) < 1:
46 loadall = True
47 else:
48 loadall = False
49
50 # if no files specified, grab whole tree contents
51 tree = ftptree.FtpTree(treename, loadall = loadall)
52 if loadall:
53 # this is hack, should be a param, not access private .loadedpkgs element
54 tree.mark4moving(tree.loadedpkgs)
55 else:
56 tree.mark4moving(packages)
55bd5397
ER
57 files = tree.rpmfiles()
58
f56d33c5
ER
59except ftptree.SomeError:
60 # In case of problems we need to unlock the tree before exiting
5a666fec 61 ftpio.unlock(treename)
f56d33c5
ER
62 sys.exit(1)
63
5a666fec 64ftpio.unlock(treename)
42c96205
ER
65
66print "Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs))
67sign = []
95843bd6 68n = c = 0
42c96205
ER
69for file in files:
70 if not is_signed(file):
71 sign.append(file)
95843bd6
ER
72 c += 1
73 n += 1
2000899b 74 print "\r%d/%d %s\033[0K" % (n, c, file),
95843bd6
ER
75
76print ""
42c96205
ER
77
78if len(sign) == 0:
4e15eddf 79 print "No files to sign"
42c96205
ER
80 sys.exit(0)
81
95843bd6
ER
82# http://mail.python.org/pipermail/python-list/2009-February/700658.html
83def chunk(seq, size, pad=None):
84 '''
85 Slice a list into consecutive disjoint 'chunks' of
86 length equal to size. The last chunk is padded if necessary.
87
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
99 >>>
100 '''
101 n = len(seq)
102 mod = n % size
103 for i in xrange(0, n - mod, size):
104 yield seq[i : i + size]
105 if mod:
106 yield seq[-mod:]
107
108print "Total %d files to sign" % len(sign)
89b8ea8d 109password = getpass.getpass("Enter signing password: ")
4e83e214 110try:
95843bd6
ER
111 for x in chunk(sign, 512):
112 print "Signing %d files" % len(x)
89b8ea8d 113 signpkgs(x, password)
4e83e214
ER
114except OSError, e:
115 print >>sys.stderr, "ERR: %s" % e
116 exit(1)
This page took 0.257135 seconds and 4 git commands to generate.