-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotarize_and_poll_apple_servers.py
More file actions
93 lines (76 loc) · 3.39 KB
/
notarize_and_poll_apple_servers.py
File metadata and controls
93 lines (76 loc) · 3.39 KB
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
89
90
91
92
93
# Utility script for Jenkins. Must be run on a Mac since it runs Apple utilities.
# Takes four arguments:
# * bundle ID
# * Apple ID of account used to create the app-specific password (I think--anyhow, an Apple accound ID)
# * app-specific password
# * path to compressed app to send for notarization
import subprocess
import sys
import time
import urllib
if len(sys.argv) != 6:
print "NotarizeAndPollAppleServers.py: need bundle ID, Apple ID, app password, polling time in minutes, and path to zip file."
exit(-1)
bundleID = sys.argv[1]
appleID = sys.argv[2]
appSpecificPassword = sys.argv[3]
pollMinutes = float(sys.argv[4])
appZipPath = sys.argv[5]
print "NotarizeAndPollAppleServers.py: Starting notarization."
try:
uploadOutput = subprocess.check_output(['xcrun', '--verbose', '--log', 'altool', '--notarize-app', '--primary-bundle-id', bundleID, '-u', appleID, '-p', appSpecificPassword, '--file', appZipPath], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError, cpe:
print "NotarizeAndPollAppleServers.py: Exception in notarization:"
print str(cpe)
print "Output of command:"
print cpe.output
print "STDOUT:"
print cpe.stdout
except Exception, e:
print "NotarizeAndPollAppleServers.py: Exception in notarization:"
print str(e)
exit(-2)
print "NotarizeAndPollAppleServers.py: upload output: "
print uploadOutput
requestIDIndex = uploadOutput.find("RequestUUID = ")
if requestIDIndex == -1:
print "NotarizeAndPollAppleServers.py: Unable to upload for notarization."
exit(-3)
requestID = uploadOutput[requestIDIndex + len("RequestUUID = "):].strip()
print "Request ID: ", requestID
# Every pollMinutes minutes we poll the Apple servers for a result.
print "NotarizeAndPollAppleServers.py: Upload succeeded. Will poll for outcome every ", pollMinutes, " minutes."
while True:
pollOutput = ""
try:
pollOutput = subprocess.check_output(['xcrun', '--verbose', '--log', 'altool', '--notarization-info', requestID, '-u', appleID, '-p', appSpecificPassword], stderr=subprocess.STDOUT)
print "NotarizeAndPollAppleServers.py: poll output: "
print pollOutput
# check for successful notarization
pollOutputLower = pollOutput.lower()
if "package approved" in pollOutputLower:
print "NotarizeAndPollAppleServers.py: Notarization succeeded."
notarizationReportURLIndex = pollOutput.find("LogFileURL: ")
if notarizationReportURLIndex == -1:
print "NotarizeAndPollAppleServers.py: Unable to find notarization report URL in output from Apple notarization server."
else:
notarizationReportURL = pollOutput[notarizationReportURLIndex + len("LogFileURL: "):].splitlines()[0].strip()
notarizationReportContents = urllib.urlopen(notarizationReportURL).read()
print "NotarizeAndPollAppleServers.py: notarization report: "
print notarizationReportContents
exit(0)
# check for failed notarization
elif "fail" in pollOutput or "error" in pollOutputLower and not "in progress" in pollOutputLower:
print "NotarizeAndPollAppleServers.py: Notarization failed."
exit(-4)
except subprocess.CalledProcessError, cpe:
print "NotarizeAndPollAppleServers.py: Exception in polling:"
print str(cpe)
print "Output of command:"
print cpe.output
print "Will try again in ", pollMinutes, " minutes."
except Exception, e:
print "NotarizeAndPollAppleServers.py: Exception in polling:"
print str(e)
print "Will try again in ", pollMinutes, " minutes."
time.sleep(pollMinutes * 60)