-
Notifications
You must be signed in to change notification settings - Fork 8
/
file_list.py
112 lines (81 loc) · 3.46 KB
/
file_list.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import re
from typing import List, Tuple, Dict
import requests
from files import ReleaseFile
from files import SourceFile
from util import retry_multi, GLOBAL_TIMEOUT
def get_release_files(tag_name, config) -> Tuple[List[ReleaseFile], Dict[str, SourceFile]]:
@retry_multi(5)
def execute_request(path):
headers = {
"Accept": "application/vnd.github.v3+json"
}
url = "https://api.github.com" + path
response = requests.get(url, headers=headers, timeout=GLOBAL_TIMEOUT)
response.raise_for_status()
return response.json()
build_group_regex = re.compile("fs2_open_.*-builds-([^.-]*)(-([^.]*))?.*")
source_file_regex = re.compile("fs2_open_.*-source-([^.]*)?.*")
response = execute_request(
"/repos/{}/{}/releases/tags/{}".format(config["github"]["user"], config["github"]["repo"], tag_name))
binary_files = []
source_files = {}
for asset in response["assets"]:
url = asset["browser_download_url"]
name = asset["name"]
group_match = build_group_regex.match(name)
if group_match is not None:
platform = group_match.group(1)
# x64 is the Visual Studio name but for consistency we need Win64
if platform == "x64":
platform = "Win64"
binary_files.append(ReleaseFile(name, url, platform, group_match.group(3)))
else:
group_match = source_file_regex.match(name)
if group_match is None:
continue
group = group_match.group(1)
source_files[group] = SourceFile(name, url, group)
return binary_files, source_files
def get_nightly_files(tag_name, config):
tag_regex = re.compile("nightly_(.*)")
build_group_regex = re.compile("nightly_.*-builds-([^.]+).*")
link_regex = re.compile(r'<a href="(nightly_[^"]+)"')
version_str = tag_regex.match(tag_name).group(1)
files = []
for mirror in config["ftp"]["mirrors"]:
url = mirror.format(type="nightly", version=version_str, file="")
try:
response = requests.get(url)
response.raise_for_status()
except Exception as ex:
print("Failed to retrieve filelist from %s: %s" % (url, ex))
continue
files = link_regex.findall(response.text)
break
if not files:
print("No files found!")
return []
out_data = []
for file in files:
file_match = build_group_regex.match(file)
if file_match is None:
print("Ignoring non nightly file '{}'".format(file))
continue
group_match = file_match.group(1)
primary_url = None
mirrors = []
# x64 is the name Visual Studio uses but Win64 works better for us since that gets displayed in the nightly post
if "x64" in group_match:
group_match = group_match.replace("x64", "Win64")
# nebula.py expects "MacOSX" as the group, but the build actions may pass off as just "Mac"
if "Mac" in group_match:
group_match = group_match.replace("Mac", "MacOSX")
for mirror in config["ftp"]["mirrors"]:
download_url = mirror.format(type="nightly", version=version_str, file=file)
if primary_url is None:
primary_url = download_url
else:
mirrors.append(download_url)
out_data.append(ReleaseFile(file, primary_url, group_match, None, mirrors))
return out_data