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