]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - bin/pfa-signpkg
Switch to Python 3 for rpm.org rpm
[projects/pld-ftp-admin.git] / bin / pfa-signpkg
CommitLineData
a1e62e44 1#!/usr/bin/env python3
f56d33c5
ER
2# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3
2ec96333
JR
4from __future__ import print_function
5
f56d33c5 6import sys, os
5a666fec 7import getopt
f56d33c5
ER
8sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
9import ftptree
89b8ea8d 10import getpass
f56d33c5
ER
11from common import checkdir
12import ftpio
55bd5397 13from config import sign_key
42c96205 14from sign import is_signed, signpkgs
f56d33c5 15
ce26983c 16os.umask(0o022)
fc574b00 17
5a666fec
ER
18try:
19 opts, args = getopt.getopt(sys.argv[1:], '')
20except getopt.GetoptError:
2ec96333
JR
21 print("ERR: options error", file=sys.stderr)
22 print("sign.py tree package1 [package2...]", file=sys.stderr)
5a666fec
ER
23 sys.exit(1)
24
25if len(args) < 1:
2ec96333
JR
26 print("ERR: missing tree name", file=sys.stderr)
27 print("sign.py tree package1 [package2...]", file=sys.stderr)
55bd5397
ER
28 sys.exit(1)
29
30if sign_key == None:
2ec96333 31 print("ERR: sign_key not defined in config", file=sys.stderr)
f56d33c5
ER
32 sys.exit(1)
33
5a666fec
ER
34treename = args[0]
35packages = args[1:]
36
37checkdir(treename)
f56d33c5
ER
38
39ftpio.connect('sign')
40
5a666fec 41if not ftpio.lock(treename, True):
2ec96333 42 print("ERR: %s tree already locked" % treename, file=sys.stderr)
f56d33c5
ER
43 sys.exit(1)
44
42c96205 45files = []
f56d33c5 46try:
5a666fec
ER
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)
55bd5397
ER
59 files = tree.rpmfiles()
60
f56d33c5
ER
61except ftptree.SomeError:
62 # In case of problems we need to unlock the tree before exiting
5a666fec 63 ftpio.unlock(treename)
f56d33c5
ER
64 sys.exit(1)
65
5a666fec 66ftpio.unlock(treename)
42c96205 67
2ec96333 68print("Checking signatures of %d files from %d packages" % (len(files), len(tree.loadedpkgs)))
42c96205 69sign = []
95843bd6 70n = c = 0
42c96205
ER
71for file in files:
72 if not is_signed(file):
73 sign.append(file)
95843bd6
ER
74 c += 1
75 n += 1
68f2c1fb 76 print("\r%d/%d %s\033[0K" % (n, c, file), end='')
95843bd6 77
2ec96333 78print()
42c96205
ER
79
80if len(sign) == 0:
2ec96333 81 print("No files to sign")
42c96205
ER
82 sys.exit(0)
83
95843bd6
ER
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]]
2ec96333 100 >>> for X in chunk([],3): print(X)
95843bd6
ER
101 >>>
102 '''
103 n = len(seq)
104 mod = n % size
f09b8024 105 for i in range(0, n - mod, size):
95843bd6
ER
106 yield seq[i : i + size]
107 if mod:
108 yield seq[-mod:]
109
2ec96333 110print("Total %d files to sign" % len(sign))
89b8ea8d 111password = getpass.getpass("Enter signing password: ")
4e83e214 112try:
95843bd6 113 for x in chunk(sign, 512):
2ec96333 114 print("Signing %d files" % len(x))
89b8ea8d 115 signpkgs(x, password)
9c170c61 116except OSError as e:
2ec96333 117 print("ERR: %s" % e, file=sys.stderr)
4e83e214 118 exit(1)
This page took 0.31903 seconds and 4 git commands to generate.