Skip to content

Commit 3afc5b6

Browse files
committed
Load installer metadata from Github Releases
- Try to fix "Error 429: Too Many Requests" when downloading from https://raw.githubusercontent.com/ - See Issue #236 for details - Installer metadata is now hosted on the python-patcher-metadata repository as releases
1 parent 89f581c commit 3afc5b6

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This repository contains the mod installer, used for installing all 07th-mod mod
1010

1111
### Updating landing page and mod page "update" banners
1212

13-
The HTML for the landing page and update banners for each mod is dynamically fetched from this github repo [https://github.com/07th-mod/python-patcher-updates](https://github.com/07th-mod/python-patcher-updates).
13+
The HTML for the landing page and update banners for each mod is dynamically fetched from this github repo [https://github.com/07th-mod/python-patcher-metadata](https://github.com/07th-mod/python-patcher-metadata).
1414

1515
To update the html:
1616

common.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ def printErrorMessage(text):
127127

128128
################################################## Global Variables#####################################################
129129
class Globals:
130-
GITHUB_MASTER_BASE_URL = "https://raw.githubusercontent.com/07th-mod/python-patcher/master/"
130+
# On startup, the installer will download a zip file containing the following files
131+
# and extract them to the INSTALLER_META_DATA_FOLDER
132+
INSTALLER_META_DATA_ZIP_URL = "https://github.com/07th-mod/python-patcher-metadata/releases/latest/download/installerMetadata.zip"
133+
INSTALLER_META_DATA_FOLDER = "installerMetadata"
134+
META_PATH__INSTALL_DATA = os.path.join(INSTALLER_META_DATA_FOLDER, "installData.json")
135+
META_PATH__VERSION_DATA = os.path.join(INSTALLER_META_DATA_FOLDER, "versionData.json")
136+
META_PATH__DOWNLOAD_SIZES = os.path.join(INSTALLER_META_DATA_FOLDER, "cachedDownloadSizes.json")
137+
META_PATH__UPDATES = os.path.join(INSTALLER_META_DATA_FOLDER, "updates.json")
138+
131139
# The installer info version this installer is compatibile with
132140
# Increment it when you make breaking changes to the json files
133141
JSON_VERSION = 12
@@ -377,7 +385,7 @@ def loadCachedDownloadSizes(modList):
377385
if Globals.DEVELOPER_MODE:
378386
downloadSizesDict, _error = getJSON('cachedDownloadSizes.json', isURL=False)
379387
else:
380-
downloadSizesDict, _error = getJSON(Globals.GITHUB_MASTER_BASE_URL + 'cachedDownloadSizes.json', isURL=True)
388+
downloadSizesDict, _error = getJSON(Globals.META_PATH__DOWNLOAD_SIZES, isURL=False)
381389

382390
if downloadSizesDict is None:
383391
print("ERROR: Failed to retrieve cachedDownloadSizes.json file")
@@ -749,7 +757,7 @@ def sevenZipTest(archive_path):
749757
return runProcessOutputToTempFile(arguments, sevenZipMode=True)
750758

751759
def preloadModUpdatesHTML():
752-
html, errorInfo = getJSON("https://github.com/07th-mod/python-patcher-updates/releases/latest/download/updates.json", isURL=True)
760+
html, errorInfo = getJSON(Globals.META_PATH__UPDATES, isURL=False)
753761

754762
if errorInfo is not None:
755763
print('WARNING: Failed to get mod updates from server')
@@ -1483,6 +1491,7 @@ def downloadFile(url, is_text):
14831491
:return:
14841492
"""
14851493
def downloadUsingURLOpen(download_url):
1494+
print("Downloading [{}] using Python urlopen...".format(download_url))
14861495
file = urlopen(Request(download_url, headers={"User-Agent": ""}), context=Globals.getURLOpenContext())
14871496
data = file.read()
14881497
file.close()

fileVersionManagement.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,11 @@ def getLocalVersion(localVersionFilePath):
246246

247247

248248
def getRemoteVersion(remoteTargetID):
249-
remoteVersionURL = common.Globals.GITHUB_MASTER_BASE_URL + "versionData.json"
250-
251249
# Get remote version
252250
if common.Globals.DEVELOPER_MODE and os.path.exists("versionData.json"):
253251
allRemoteVersions, remoteError = common.getJSON("versionData.json", isURL=False)
254252
else:
255-
allRemoteVersions, remoteError = common.getJSON(remoteVersionURL, isURL=True)
253+
allRemoteVersions, remoteError = common.getJSON(common.Globals.META_PATH__VERSION_DATA, isURL=False)
256254

257255
if remoteError is not None:
258256
print("Error retrieving remote version".format(remoteError))

main.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def getModList(is_developer=True):
4242
if is_developer and os.path.exists('installData.json'):
4343
return common.getModList("installData.json", isURL=False)
4444
else:
45-
return common.getModList(common.Globals.GITHUB_MASTER_BASE_URL + "installData.json", isURL=True)
45+
return common.getModList(common.Globals.META_PATH__INSTALL_DATA, isURL=False)
4646

4747
def getSubModConfigList(modList):
4848
subModconfigList = []
@@ -207,6 +207,28 @@ def installerCommonStartupTasks():
207207
installerGUI = httpGUI.InstallerGUI()
208208

209209
def thread_getSubModConfigList():
210+
# Download and extract the installer meta data zip file, containing download links, file versions, file size etc.
211+
# If you've cloned the repo (developer) then the installer will download these files, but won't use them except for
212+
# the updates.json file, which is located in the other repo "python-patcher-status"
213+
214+
# Delete the old file to be sure we're using the latest metadata.
215+
installerMetadataZipPath = "installerMetadata.zip"
216+
common.removeFileWithCheck(installerMetadataZipPath)
217+
218+
# Download and extract the installer metadata zip
219+
# Abort installation if we can't download/extract this file
220+
url = common.Globals.INSTALLER_META_DATA_ZIP_URL
221+
if common.aria(url=url, outputFile="installerMetadata.zip") != 0:
222+
raise Exception("ERROR - could not download [{}] with aria2c".format(url))
223+
224+
# Extract the zip file. This should overwrite existing files so we don't get old metadata.
225+
common.extractOrCopyFile(
226+
filename = "installerMetadata.zip",
227+
sourceFolder = ".",
228+
destinationFolder = common.Globals.INSTALLER_META_DATA_FOLDER
229+
)
230+
231+
# Now parse/load the downloaded files. Note that some files may be used later in the installer.
210232
modList = getModList(common.Globals.DEVELOPER_MODE)
211233
common.Globals.loadCachedDownloadSizes(modList)
212234
return getSubModConfigList(modList)

0 commit comments

Comments
 (0)