forked from mozilla/fx-desktop-qa-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect_executables.py
executable file
·90 lines (76 loc) · 2.73 KB
/
collect_executables.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
"""Get the link to download Fx or Geckodriver, for any supported platform.
Use -g to get geckodriver, otherwise you will get Fx.
Set env var FX_CHANNEL to get non-beta, blank string for Release.
Set env var FX_LOCALE to get a different locale build."""
from os import environ
from platform import uname
from sys import argv, exit
from time import sleep
import requests
GECKO_API_URL = "https://api.github.com/repos/mozilla/geckodriver/releases/latest"
def get_fx_platform():
u = uname()
if u.system == "Darwin":
return "osx"
if u.system == "Linux":
if "64" in u.machine:
return "linux64"
return "linux"
if u.system == "Windows":
if u.machine == "AMD64" and not environ.get("GITHUB_ACTIONS"):
return "win64-aarch64"
if "64" in u.machine:
return "win64"
return "win"
def get_gd_platform():
u = uname()
if u.system == "Darwin":
return "macos"
if u.system == "Linux":
if u.machine == "AMD64":
return "linux-aarch64"
if "64" in u.machine:
return "linux64"
return "linux32"
if u.system == "Windows":
if u.machine == "AMD64" and not environ.get("GITHUB_ACTIONS"):
return "win-aarch64"
if "64" in u.machine:
return "win64"
return "win32"
if "-g" in argv:
gecko_rs_obj = requests.get(GECKO_API_URL).json()
# In mac, sometimes this request fails to produce a link
for _ in range(4):
if gecko_rs_obj:
break
sleep(2)
gecko_rs_obj = requests.get(GECKO_API_URL).json()
# If we failed, just dump any old link, maybe update this on new gecko release
if not gecko_rs_obj.get("assets"):
gd_platform = get_gd_platform()
ext = "zip" if "win" in gd_platform else "tar.gz"
print(
f"https://github.com/mozilla/geckodriver/releases/download/v0.35.0/geckodriver-v0.35.0-{gd_platform}.{ext}"
)
exit()
urls = [
a.get("browser_download_url")
for a in gecko_rs_obj.get("assets")
if not a.get("browser_download_url").endswith(".asc")
]
gecko_download_url = [u for u in urls if get_gd_platform() in u][0]
print(gecko_download_url)
else:
channel = environ.get("FX_CHANNEL")
# if channel doesn't exist use beta, if blank leave blank (for Release)
# ...otherwise prepend hyphen
if channel is None:
channel = "-beta"
elif channel:
channel = f"-{channel.lower()}"
language = environ.get("FX_LOCALE")
if not language:
language = "en-US"
fx_download_url = f"https://download.mozilla.org/?product=firefox{channel}-latest-ssl&os={get_fx_platform()}&lang={language}"
print(fx_download_url)