-
Notifications
You must be signed in to change notification settings - Fork 14
/
amo_xpi_sign.py
65 lines (51 loc) · 2.18 KB
/
amo_xpi_sign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
'''Script to sign a Firefox xpi'''
import argparse
import re
import shutil
import subprocess
TIMEOUT = 10*60*1000
def handle_arguments():
'''Handle command line arguments'''
parser = argparse.ArgumentParser(description=('Sign .xpi file on '
'mozilla.org'))
parser.add_argument('--key', '-k', type=str, required=True,
help='AMO API key')
parser.add_argument('--output', '-o', type=str,
help=('Target file or directory to save signed .xpi '
'file to. The default behavior is to save in '
'the same directory as the unsigned xpi with '
'\'-signed\' appended to the file '
'name (before the \'.xpi\' extension). If a '
'directory is given, this default name is used '
'to save the .xpi file in that directory.'))
parser.add_argument('--secret', '-s', type=str, required=True,
help='AMO secret key')
parser.add_argument('--xpi', '-x', type=str, required=True,
help='.xpi file to be signed')
return vars(parser.parse_args())
def sign(xpi, key, secret, output=None):
'''Upload xpi file for signing and then download the signed xpi if
successful'''
jpm_cmd = ['jpm', 'sign', '--api-key', key, '--api-secret', secret,
'--xpi', xpi, '--timeout', str(TIMEOUT)]
proc = subprocess.run(jpm_cmd, stdout=subprocess.PIPE,
universal_newlines=True)
stdout = proc.stdout.splitlines()
if re.match(r'JPM \[info\] SUCCESS', stdout[-1]):
signed_xpi = re.match(r'\s+(.*\.xpi)', stdout[-2]).group(1)
if output:
shutil.move(signed_xpi, output)
signed_xpi = output
else:
import pickle
with open('stdout.pickle', 'wb') as f_out:
pickle.dump(stdout, f_out)
raise RuntimeError(proc.stdout)
return signed_xpi
def main():
'''Main logic'''
args = handle_arguments()
sign(**args)
if __name__ == '__main__':
main()