in Xcode/AppleURLSearcher.py [0:0]
def main(self):
# If we have "URL" already passed in, we should just use it
if self.env.get("URL"):
self.output_result(self.env["URL"])
return
if self.env.get("BETA"):
self.output("Beta flag is set, searching Apple downloads URL...")
beta_url = "https://developer.apple.com/download/"
# We're going to make the strong assumption that if BETA is
# populated, we should only use URLTextSearcher, because as of
# 6/7/19, Apple has only posted the new Xcode beta to the main
# developer page, and not the "More Downloads" section.
# If this trend holds true, then URLTextSearcher = betas,
# AppleURLSearcher = "more downloads" = stable/GM releases.
# If we do get a url from URLTextSearcher, it needs to be appended
# to the base Apple Developer Portal URL.
curl_opts = [
"--cookie",
"login_cookies",
"--cookie-jar",
"download_cookies",
]
pattern = r"""<a href=["'](.*.xip)"""
groupmatch, groupdict = self.get_url_and_search(
beta_url, pattern, opts=curl_opts
)
fixed_url = "https://developer.apple.com/" + groupmatch
self.env[self.env["result_output_var_name"]] = fixed_url
self.output("New fixed URL: {}".format(fixed_url))
self.output_variables = {}
self.output_variables[self.env["result_output_var_name"]] = fixed_url
return
self.output("Beta flag not set, searching More downloads list...")
# If we're not looking for BETA, then disregard everything from
# URLTextSearcher and search the Apple downloads list instead.
download_dir = os.path.join(self.env["RECIPE_CACHE_DIR"], "downloads")
downloads = os.path.join(download_dir, "listDownloads")
if not os.path.exists(downloads):
raise ProcessorError("Missing the download data from AppleCookieDownloader")
pattern = self.env["re_pattern"]
with open(downloads) as f:
data = json.load(f)
dl_base_url = "https://download.developer.apple.com"
xcode_list = []
for x in data["downloads"]:
for y in x["files"]:
url = dl_base_url + y["remotePath"]
# Regex the results
re_pattern = re.compile(pattern)
dl_match = re_pattern.findall(url)
if not dl_match:
continue
filename = os.path.splitext(
posixpath.basename(urlsplit(y["remotePath"]).path)
)[0]
xcode_item = {
"datePublished_str": x["datePublished"],
"datePublished_obj": datetime.datetime.strptime(
x["datePublished"], "%m/%d/%y %H:%M"
),
"remotePath": y["remotePath"],
"filename": filename,
"full_url": url,
}
xcode_list.append(xcode_item)
matches = sorted(xcode_list, key=lambda i: i["datePublished_obj"])
match = matches[-1]
if not match or not xcode_list:
raise ProcessorError("No match found!")
self.output(
"Sorted list of possible filenames: {}".format(
[x["filename"] for x in matches]
),
verbose_level=2,
)
self.output("Found matching item: {}".format(match["filename"]))
full_url_match = match["full_url"]
if not full_url_match:
raise ProcessorError("No matching URL found!")
self.output_result(full_url_match)