Skip to content

Commit 1c995e9

Browse files
author
arch
committed
improve installer
1 parent 766845e commit 1c995e9

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

contrib/Installer/mtfg-ofs-extension-installer.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import zipfile
66
import os
77
import sys
8+
import time
89
import traceback
910
import shutil
1011

@@ -41,16 +42,20 @@ def is_ofs_installed():
4142

4243

4344
def get_download_urls():
44-
try:
45-
html_text = requests.get(FUNSCRIPT_GENERATOR_RELEASE_URL).text
46-
download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \
47-
for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \
48-
if link.get('href').endswith(".zip") and "/releases/" in link.get('href')]
49-
}
50-
latest = max(download_urls)
51-
return download_urls, latest
52-
except:
53-
error("Download URL not found (" + FUNSCRIPT_GENERATOR_RELEASE_URL + ")")
45+
# sometimes requests failed to fetch the url so we try up to 3 times
46+
for i in range(3):
47+
try:
48+
html_text = requests.get(FUNSCRIPT_GENERATOR_RELEASE_URL).text
49+
download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \
50+
for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \
51+
if link.get('href').endswith(".zip") and "/releases/" in link.get('href')]
52+
}
53+
latest = max(download_urls)
54+
return download_urls, latest
55+
except:
56+
time.sleep(2)
57+
if i == 2:
58+
error("Download URL not found (" + FUNSCRIPT_GENERATOR_RELEASE_URL + ")")
5459

5560

5661
def is_latest_version_installed(version_file, version):
@@ -105,6 +110,7 @@ def update(download_urls, latest):
105110
if platform.system() != "Windows":
106111
error("This installer only work on Windows")
107112

113+
print("Start MTFG installation")
108114
is_ofs_installed()
109115
download_urls, latest = get_download_urls()
110116
update(download_urls, latest)

0 commit comments

Comments
 (0)