summaryrefslogtreecommitdiffstats
path: root/release/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'release/util.py')
-rw-r--r--release/util.py78
1 files changed, 42 insertions, 36 deletions
diff --git a/release/util.py b/release/util.py
index 9d0eb1dc..df7a5638 100644
--- a/release/util.py
+++ b/release/util.py
@@ -20,54 +20,60 @@ import subprocess
20import sys 20import sys
21 21
22 22
23assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' 23assert sys.version_info >= (3, 6), "This module requires Python 3.6+"
24 24
25 25
26TOPDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 26TOPDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
27HOMEDIR = os.path.expanduser('~') 27HOMEDIR = os.path.expanduser("~")
28 28
29 29
30# These are the release keys we sign with. 30# These are the release keys we sign with.
31KEYID_DSA = '8BB9AD793E8E6153AF0F9A4416530D5E920F5C65' 31KEYID_DSA = "8BB9AD793E8E6153AF0F9A4416530D5E920F5C65"
32KEYID_RSA = 'A34A13BE8E76BFF46A0C022DA2E75A824AAB9624' 32KEYID_RSA = "A34A13BE8E76BFF46A0C022DA2E75A824AAB9624"
33KEYID_ECC = 'E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39' 33KEYID_ECC = "E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39"
34 34
35 35
36def cmdstr(cmd): 36def cmdstr(cmd):
37 """Get a nicely quoted shell command.""" 37 """Get a nicely quoted shell command."""
38 ret = [] 38 ret = []
39 for arg in cmd: 39 for arg in cmd:
40 if not re.match(r'^[a-zA-Z0-9/_.=-]+$', arg): 40 if not re.match(r"^[a-zA-Z0-9/_.=-]+$", arg):
41 arg = f'"{arg}"' 41 arg = f'"{arg}"'
42 ret.append(arg) 42 ret.append(arg)
43 return ' '.join(ret) 43 return " ".join(ret)
44 44
45 45
46def run(opts, cmd, check=True, **kwargs): 46def run(opts, cmd, check=True, **kwargs):
47 """Helper around subprocess.run to include logging.""" 47 """Helper around subprocess.run to include logging."""
48 print('+', cmdstr(cmd)) 48 print("+", cmdstr(cmd))
49 if opts.dryrun: 49 if opts.dryrun:
50 cmd = ['true', '--'] + cmd 50 cmd = ["true", "--"] + cmd
51 try: 51 try:
52 return subprocess.run(cmd, check=check, **kwargs) 52 return subprocess.run(cmd, check=check, **kwargs)
53 except subprocess.CalledProcessError as e: 53 except subprocess.CalledProcessError as e:
54 print(f'aborting: {e}', file=sys.stderr) 54 print(f"aborting: {e}", file=sys.stderr)
55 sys.exit(1) 55 sys.exit(1)
56 56
57 57
58def import_release_key(opts): 58def import_release_key(opts):
59 """Import the public key of the official release repo signing key.""" 59 """Import the public key of the official release repo signing key."""
60 # Extract the key from our repo launcher. 60 # Extract the key from our repo launcher.
61 launcher = getattr(opts, 'launcher', os.path.join(TOPDIR, 'repo')) 61 launcher = getattr(opts, "launcher", os.path.join(TOPDIR, "repo"))
62 print(f'Importing keys from "{launcher}" launcher script') 62 print(f'Importing keys from "{launcher}" launcher script')
63 with open(launcher, encoding='utf-8') as fp: 63 with open(launcher, encoding="utf-8") as fp:
64 data = fp.read() 64 data = fp.read()
65 65
66 keys = re.findall( 66 keys = re.findall(
67 r'\n-----BEGIN PGP PUBLIC KEY BLOCK-----\n[^-]*' 67 r"\n-----BEGIN PGP PUBLIC KEY BLOCK-----\n[^-]*"
68 r'\n-----END PGP PUBLIC KEY BLOCK-----\n', data, flags=re.M) 68 r"\n-----END PGP PUBLIC KEY BLOCK-----\n",
69 run(opts, ['gpg', '--import'], input='\n'.join(keys).encode('utf-8')) 69 data,
70 70 flags=re.M,
71 print('Marking keys as fully trusted') 71 )
72 run(opts, ['gpg', '--import-ownertrust'], 72 run(opts, ["gpg", "--import"], input="\n".join(keys).encode("utf-8"))
73 input=f'{KEYID_DSA}:6:\n'.encode('utf-8')) 73
74 print("Marking keys as fully trusted")
75 run(
76 opts,
77 ["gpg", "--import-ownertrust"],
78 input=f"{KEYID_DSA}:6:\n".encode("utf-8"),
79 )