in Xcode/AppleCookieDownloader.py [0:0]
def main(self):
download_dir = os.path.join(self.env["RECIPE_CACHE_DIR"], "downloads")
login_cookies = os.path.join(download_dir, "login_cookies")
download_cookies = os.path.join(download_dir, "download_cookies")
# create download_dir if needed
if not os.path.exists(download_dir):
try:
os.makedirs(download_dir)
except OSError as err:
raise ProcessorError(
"Can't create %s: %s" % (download_dir, err.strerror)
)
self.output("Getting login cookie")
# We need to POST a request to the auth page to get the
# 'myacinfo' cookie
login_curl_opts = [
"--request",
"POST",
"--data",
"@{}".format(self.env["login_data"]),
"--cookie-jar",
login_cookies,
]
self.download(
url="https://idmsa.apple.com/IDMSWebAuth/authenticate",
curl_opts=login_curl_opts,
output="-",
request_headers=None,
allow_failure=True,
)
self.output("Getting download cookie")
# Now we need to get the download cookie
dl_curl_opts = [
"--request",
"POST",
"--cookie",
login_cookies,
"--cookie-jar",
download_cookies,
]
headers = {"Content-length": "0"}
output = os.path.join(download_dir, "listDownloads.gz")
if os.path.exists(output):
# Delete it first
os.unlink(output)
self.download(
url="https://developer.apple.com/services-account/QH65B2/downloadws/listDownloads.action",
curl_opts=dl_curl_opts,
output=output,
request_headers=headers,
allow_failure=True,
)
self.env["download_cookies"] = download_cookies
try:
with open(output) as f:
json.load(f)
# If we successfully load this as JSON, then we failed
# to download the gzip list
raise ProcessorError(
"Unable to list downloads. Check your Apple credentials."
)
except IOError:
raise ProcessorError("Unable to load listDownloads.gz file.")
except ValueError:
pass
# While we're at it, let's unzip the download list
# It's actually a gunzip, so Unarchiver doesn't work
# The result is a JSON blob
self.output("Unzipping download list")
os.chdir(download_dir)
if os.path.exists(output.rstrip(".gz")):
# Delete the file if it's already here
os.unlink(output.rstrip(".gz"))
gunzip_cmd = ["/usr/bin/gunzip", output]
proc = subprocess.Popen(
gunzip_cmd,
shell=False,
bufsize=1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(stdout, stderr) = proc.communicate()
if proc.returncode:
gzerr = stderr.rstrip("\n")
raise ProcessorError(
"Gunzip failure: %s (exit code %s)" % (gzerr, proc.returncode)
)