From 802af0c909bbf843df01e423b89dd4b8e2c18169 Mon Sep 17 00:00:00 2001 From: Alexander Hayden Date: Wed, 30 Jan 2019 10:21:29 -0500 Subject: Make code nicer --- downloads.txt | 4 +-- prev-downloads.txt | 36 --------------------------- thaumplified-downloads.txt | 36 +++++++++++++++++++++++++++ update.py | 62 ++++++++++++++++------------------------------ 4 files changed, 60 insertions(+), 78 deletions(-) delete mode 100644 prev-downloads.txt create mode 100644 thaumplified-downloads.txt diff --git a/downloads.txt b/downloads.txt index 6549d94..96a4981 100644 --- a/downloads.txt +++ b/downloads.txt @@ -1,6 +1,6 @@ # Format: +twilightforest.jar 418e55d39800696341d888dd9f407daee3748276 https://media.forgecdn.net/files/2618/264/twilightforest-1.12.2-3.8.689-universal.jar +baubles.jar cb13fcfb18a9cb0cbd825fd5fe8d813c77368549 https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar opencomputers.jar 70feadd549255477810dff7145cade9d507b2dec https://media.forgecdn.net/files/2638/675/OpenComputers-MC1.12.2-1.7.3.146.jar thaumcraft.jar fe0899048f1796df04e9727bbf1898df30492a00 https://media.forgecdn.net/files/2629/23/Thaumcraft-1.12.2-6.1.BETA26.jar -twilightforest.jar 418e55d39800696341d888dd9f407daee3748276 https://media.forgecdn.net/files/2618/264/twilightforest-1.12.2-3.8.689-universal.jar connectedtextures.jar 03be3e20dacf6b52abcee09436b2d06c06f2add0 https://media.forgecdn.net/files/2642/375/CTM-MC1.12.2-0.3.3.22.jar -baubles.jar cb13fcfb18a9cb0cbd825fd5fe8d813c77368549 https://media.forgecdn.net/files/2518/667/Baubles-1.12-1.5.2.jar diff --git a/prev-downloads.txt b/prev-downloads.txt deleted file mode 100644 index 0e3c6d2..0000000 --- a/prev-downloads.txt +++ /dev/null @@ -1,36 +0,0 @@ -thaumcraft-01.jar https://minecraft.curseforge.com/projects/thaumcraft/files/2629023/download -baubles-01.jar https://minecraft.curseforge.com/projects/baubles/files/2518667/download -ae2-01.jar https://media.forgecdn.net/files/2630/108/appliedenergistics2-rv6-stable-3.jar -tech-reborn-01.jar https://media.forgecdn.net/files/2633/989/TechReborn-1.12.2-2.17.7.840-universal.jar -rftools-01.jar https://media.forgecdn.net/files/2616/385/rftools-1.12-7.56.jar -tinkers-01.jar https://media.forgecdn.net/files/2571/785/TConstruct-1.12.2-2.10.1.87.jar -enderio-01.jar https://media.forgecdn.net/files/2632/831/EnderIO-1.12.2-5.0.37.jar -imersiveengineering-01.jar https://media.forgecdn.net/files/2625/312/ImmersiveEngineering-0.12-86.jar -thermalexpansion-01.jar https://media.forgecdn.net/files/2624/855/ThermalExpansion-1.12.2-5.5.2.39-universal.jar -thermaldynamics-01.jar https://media.forgecdn.net/files/2624/182/ThermalDynamics-1.12.2-2.5.3.16-universal.jar -wirelesscraftingterminal-02.jar https://media.forgecdn.net/files/2619/932/WirelessCraftingTerminal-1.12.2-3.10.82.jar -projectredcore-01.jar https://media.forgecdn.net/files/2572/409/MrTJPCore-1.12.2-2.1.3.35-universal.jar -projectred-01.jar https://media.forgecdn.net/files/2572/421/ProjectRed-1.12.2-4.9.1.92-world.jar -projectredcompat-01.jar https://media.forgecdn.net/files/2572/420/ProjectRed-1.12.2-4.9.1.92-compat.jar -projectredmech-01.jar https://media.forgecdn.net/files/2572/422/ProjectRed-1.12.2-4.9.1.92-mechanical.jar -projectredinteg-01.jar https://media.forgecdn.net/files/2572/427/ProjectRed-1.12.2-4.9.1.92-integration.jar -translocators-01.jar https://media.forgecdn.net/files/2594/249/Translocators-1.12.2-2.5.1.77-universal.jar -opencomputers-02.jar https://minecraft.curseforge.com/projects/opencomputers/files/2638675/download -jei-01.jar https://media.forgecdn.net/files/2635/239/jei_1.12.2-4.13.1.222.jar -thermalfoundation-01.jar https://media.forgecdn.net/files/2623/991/ThermalFoundation-1.12.2-2.6.1.22-universal.jar -chickenchunks-01.jar https://media.forgecdn.net/files/2594/241/ChickenChunks-1.12.2-2.4.1.73-universal.jar -enderstorage-01.jar https://media.forgecdn.net/files/2594/243/EnderStorage-1.12.2-2.4.5.135-universal.jar -codechickenlib-01.jar https://media.forgecdn.net/files/2618/630/CodeChickenLib-1.12.2-3.2.2.353-universal.jar -endercore-01.jar https://media.forgecdn.net/files/2632/476/EnderCore-1.12.2-0.5.43.jar -forgemultipart-01.jar https://media.forgecdn.net/files/2626/992/ForgeMultipart-1.12.2-2.6.0.79-universal.jar -cofhcore-01.jar https://media.forgecdn.net/files/2623/990/CoFHCore-1.12.2-4.6.1.22-universal.jar -mantle-01.jar https://media.forgecdn.net/files/2630/843/Mantle-1.12-1.3.3.39.jar -passwordlib-01.jar https://media.forgecdn.net/files/2616/338/p455w0rdslib-1.12-2.0.35.jar -cofhworld-01.jar https://media.forgecdn.net/files/2623/91/CoFHWorld-1.12.2-1.3.0.6-universal.jar -redstoneflux-01.jar https://media.forgecdn.net/files/2623/90/RedstoneFlux-1.12-2.1.0.6-universal.jar -projectredcore2-01.jar https://media.forgecdn.net/files/2572/423/ProjectRed-1.12.2-4.9.1.92-Base.jar -idklib-01.jar https://media.forgecdn.net/files/2626/982/mcjtylib-1.12-3.0.6.jar -reborncore-01.jar https://media.forgecdn.net/files/2634/706/RebornCore-1.12.2-3.10.4.348-universal.jar -twilightforest-01.jar https://minecraft.curseforge.com/projects/the-twilight-forest/files/2618264/download -connectedtextures-01.jar https://minecraft.curseforge.com/projects/ctm/files/2629306/download -# planarartiface-01.jar https://minecraft.curseforge.com/projects/planarartifice/files/2624612/download diff --git a/thaumplified-downloads.txt b/thaumplified-downloads.txt new file mode 100644 index 0000000..0e3c6d2 --- /dev/null +++ b/thaumplified-downloads.txt @@ -0,0 +1,36 @@ +thaumcraft-01.jar https://minecraft.curseforge.com/projects/thaumcraft/files/2629023/download +baubles-01.jar https://minecraft.curseforge.com/projects/baubles/files/2518667/download +ae2-01.jar https://media.forgecdn.net/files/2630/108/appliedenergistics2-rv6-stable-3.jar +tech-reborn-01.jar https://media.forgecdn.net/files/2633/989/TechReborn-1.12.2-2.17.7.840-universal.jar +rftools-01.jar https://media.forgecdn.net/files/2616/385/rftools-1.12-7.56.jar +tinkers-01.jar https://media.forgecdn.net/files/2571/785/TConstruct-1.12.2-2.10.1.87.jar +enderio-01.jar https://media.forgecdn.net/files/2632/831/EnderIO-1.12.2-5.0.37.jar +imersiveengineering-01.jar https://media.forgecdn.net/files/2625/312/ImmersiveEngineering-0.12-86.jar +thermalexpansion-01.jar https://media.forgecdn.net/files/2624/855/ThermalExpansion-1.12.2-5.5.2.39-universal.jar +thermaldynamics-01.jar https://media.forgecdn.net/files/2624/182/ThermalDynamics-1.12.2-2.5.3.16-universal.jar +wirelesscraftingterminal-02.jar https://media.forgecdn.net/files/2619/932/WirelessCraftingTerminal-1.12.2-3.10.82.jar +projectredcore-01.jar https://media.forgecdn.net/files/2572/409/MrTJPCore-1.12.2-2.1.3.35-universal.jar +projectred-01.jar https://media.forgecdn.net/files/2572/421/ProjectRed-1.12.2-4.9.1.92-world.jar +projectredcompat-01.jar https://media.forgecdn.net/files/2572/420/ProjectRed-1.12.2-4.9.1.92-compat.jar +projectredmech-01.jar https://media.forgecdn.net/files/2572/422/ProjectRed-1.12.2-4.9.1.92-mechanical.jar +projectredinteg-01.jar https://media.forgecdn.net/files/2572/427/ProjectRed-1.12.2-4.9.1.92-integration.jar +translocators-01.jar https://media.forgecdn.net/files/2594/249/Translocators-1.12.2-2.5.1.77-universal.jar +opencomputers-02.jar https://minecraft.curseforge.com/projects/opencomputers/files/2638675/download +jei-01.jar https://media.forgecdn.net/files/2635/239/jei_1.12.2-4.13.1.222.jar +thermalfoundation-01.jar https://media.forgecdn.net/files/2623/991/ThermalFoundation-1.12.2-2.6.1.22-universal.jar +chickenchunks-01.jar https://media.forgecdn.net/files/2594/241/ChickenChunks-1.12.2-2.4.1.73-universal.jar +enderstorage-01.jar https://media.forgecdn.net/files/2594/243/EnderStorage-1.12.2-2.4.5.135-universal.jar +codechickenlib-01.jar https://media.forgecdn.net/files/2618/630/CodeChickenLib-1.12.2-3.2.2.353-universal.jar +endercore-01.jar https://media.forgecdn.net/files/2632/476/EnderCore-1.12.2-0.5.43.jar +forgemultipart-01.jar https://media.forgecdn.net/files/2626/992/ForgeMultipart-1.12.2-2.6.0.79-universal.jar +cofhcore-01.jar https://media.forgecdn.net/files/2623/990/CoFHCore-1.12.2-4.6.1.22-universal.jar +mantle-01.jar https://media.forgecdn.net/files/2630/843/Mantle-1.12-1.3.3.39.jar +passwordlib-01.jar https://media.forgecdn.net/files/2616/338/p455w0rdslib-1.12-2.0.35.jar +cofhworld-01.jar https://media.forgecdn.net/files/2623/91/CoFHWorld-1.12.2-1.3.0.6-universal.jar +redstoneflux-01.jar https://media.forgecdn.net/files/2623/90/RedstoneFlux-1.12-2.1.0.6-universal.jar +projectredcore2-01.jar https://media.forgecdn.net/files/2572/423/ProjectRed-1.12.2-4.9.1.92-Base.jar +idklib-01.jar https://media.forgecdn.net/files/2626/982/mcjtylib-1.12-3.0.6.jar +reborncore-01.jar https://media.forgecdn.net/files/2634/706/RebornCore-1.12.2-3.10.4.348-universal.jar +twilightforest-01.jar https://minecraft.curseforge.com/projects/the-twilight-forest/files/2618264/download +connectedtextures-01.jar https://minecraft.curseforge.com/projects/ctm/files/2629306/download +# planarartiface-01.jar https://minecraft.curseforge.com/projects/planarartifice/files/2624612/download diff --git a/update.py b/update.py index 70f3d51..68e598a 100755 --- a/update.py +++ b/update.py @@ -14,19 +14,9 @@ with open("pack-location.txt", "r") as f: # Apply updates to the actual mod pack def install(): print("Updating pack...") - # (fname, url) - mods = [] - # Set of jar file names - names = set() - - with open("downloads.txt", "r") as f: - for line in f: - mod = line.strip().split(" ") - if len(line) >= 1 and line[0] != '#': - # run strip on each element - mod = tuple(map(lambda x: x.strip(), mod)) - mods.append(mod) - names.add(mod[0]) + # (fname, checksum, url) + mods = read_file("downloads.txt") + names = [mod[0] for mod in mods] for mod in mods: if mod[0] in os.listdir(INSTALL_DIR) and hashlib.sha1(open(os.path.join(INSTALL_DIR, mod[0]), 'rb').read()).hexdigest() == mod[1]: print("Skipping " + mod[0] + ", already up to date") @@ -49,14 +39,7 @@ def install(): # Using the latest urls, update downloads.txt to match the urls and have the correct sha1 def apply_updates(): print("Reading update file...") - mods = set() - with open('latest-urls.txt') as f: - for line in f: - mod = line.strip().split() - if len(line) >= 1 and line[0] != '#': - # run strip on each element - mod = tuple(map(lambda x: x.strip(), mod)) - mods.add(mod) + mods = read_file("latest-urls.txt") print("Downloading new versions of all mods...") with open('downloads.txt', 'w') as f: f.write('# Format: \n') @@ -70,28 +53,27 @@ def apply_updates(): # Find if any updates are available def check_updates(): print("Reading update files...") - latest_urls = {} - with open('latest-urls.txt') as f: - for line in f: - mod = line.strip().split() - if len(line) >= 1 and line[0] != '#': - # run strip on each element - mod = tuple(map(lambda x: x.strip(), mod)) - latest_urls[mod[0]] = mod[1] - old_urls = {} - with open('downloads.txt') as f: + latest = read_file("latest-urls.txt") + old = read_file("downloads.txt") + old_urls = [mod[2] for mod in old] + + print("Checking updates...\nThe following mods have updates available:\n") + for mod in latest: + resp = requests.get(mod[1]) + if not resp.url in old_urls: + print(f" -> Found update for {mod[0]}: {resp.url.split('/')[-1]}") + print("\nFinished checking for updates!") + +def read_file(fil): + strings = set() + with open(fil) as f: for line in f: - mod = line.strip().split() + string = line.strip().split() if len(line) >= 1 and line[0] != '#': # run strip on each element - mod = tuple(map(lambda x: x.strip(), mod)) - old_urls[mod[0]] = mod[2] - print("Checking updates...\nThe following mods have updates available:\n") - for mod in latest_urls: - resp = requests.get(latest_urls[mod]) - if resp.url != old_urls[mod]: - print(f" -> Found update for {mod}!") - print("Finished checking for updates!") + string = tuple(map(lambda x: x.strip(), string)) + strings.add(string) + return strings if len(sys.argv) < 2: -- cgit v1.2.3