-
Notifications
You must be signed in to change notification settings - Fork 1
/
notarize.py
88 lines (71 loc) · 3.12 KB
/
notarize.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import argparse
import os
import subprocess
import re
import sys
import time
def log_message(message, newline=True):
sys.stderr.write(message)
if newline:
sys.stderr.write("\n")
def upload_package(args):
process = subprocess.Popen(['xcrun', 'altool', '--notarize-app', '-t', 'osx', '-f', args.package,
'--primary-bundle-id', args.primary_bundle_id, '-u', args.username,
'--output-format', 'json', '-p', args.password],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
log_message('>> Uploading dmg to apple')
output, error = process.communicate()
output_str = output.decode('utf-8')
error_str = error.decode('utf-8')
log_message(output_str)
log_message(error_str)
if not 'No errors uploading' in error_str:
log_message('[Error] Upload failed')
exit(1)
m = re.match('.*RequestUUID = (.*)\n', error_str, re.S)
if not m:
log_message('[Error] No UUID created')
exit(1)
uuid = m.group(1)
log_message('>> Job UUID: %s' % uuid)
return uuid
def check_status(args, uuid):
process = subprocess.Popen(['xcrun', 'altool', '--notarization-info', uuid,
'-u', args.username, '-p', args.password, '--output-format', 'json'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
output_str = output.decode('utf-8')
error_str = error.decode('utf-8')
in_progress = 'Status: in progress' in error_str
success = 'Status: success' in error_str
if not in_progress and not success:
log_message(output_str)
log_message(error.decode('utf-8'))
log_message('[Error] Notarization failed')
exit(1)
return in_progress
def staple(args):
process = subprocess.Popen(['xcrun', 'stapler', 'staple', args.package], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
log_message(output.decode('utf-8'))
log_message(error.decode('utf-8'))
def main():
parser = argparse.ArgumentParser(description="Notarizes supplied dmg by uploading it to apple servers.")
parser.add_argument("--package", help="Path to the dmg file", action='store', required=True)
parser.add_argument("--username", help="Apple ID username to use to notarize", action='store', required=True)
parser.add_argument("--primary-bundle-id", help="Bundle id of package as specified in Info.plist", action='store', required=True)
parser.add_argument("--password", action='store', help="Password for the appleid.", required=True)
args = parser.parse_args()
if not args.package.endswith('.dmg'):
log_message('Supplied package %s is not a dmg file' % args.package)
exit(1)
uuid = upload_package(args)
while check_status(args, uuid):
log_message('.. Notarization in progress. Checking back in 30s')
time.sleep(30)
log_message('>> Notarization successful')
log_message('>> Stapling')
staple(args)
log_message('[Success] All done')
if __name__ == '__main__':
main()