diff options
-rwxr-xr-x | update.py | 37 | ||||
-rw-r--r-- | version.txt (renamed from downloads.txt) | 1 |
2 files changed, 28 insertions, 10 deletions
@@ -13,9 +13,9 @@ parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, epilog='''\ Available commands: - install : Downloads mods listed in downloads.txt and populates the mods folder specified in pack-location.txt - apply_updates : Using the urls in mods.txt, repopulates downloads.txt to reflect the most recent mod versions - check_updates : Compares downloads.txt and mods.txt to see if any mods can be updated + install : Downloads mods listed in version.txt and populates the mods folder specified in pack-location.txt + apply_updates : Using the urls in mods.txt, repopulates version.txt to reflect the most recent mod versions + check_updates : Compares version.txt and mods.txt to see if any mods can be updated ''') parser.add_argument('command', @@ -28,12 +28,15 @@ parser.add_argument('filename', help="Optional filename to specify latest mods (default: mods.txt)") parser.add_argument('--version-file', type=str, - default="downloads.txt", - help="Optional custom version file to download mods from (default: downloads.txt)") + default="version.txt", + help="Optional custom version file to download mods from (default: version.txt)") parser.add_argument('--pack-location', type=str, help="Optional custom modpack folder location (default: read from pack-location.txt)") +## loaded from version.txt +VERSION = 0 + def read_file(fil): strings = [] with open(fil) as f: @@ -43,11 +46,13 @@ def read_file(fil): # run strip on each element string = tuple(map(lambda x: x.strip(), string)) strings.append(string) + return strings # Apply updates to the actual mod pack def install(args): - print("Updating pack...") + print("Updating pack with version " + str(VERSION) + "...") + print() # (fname, checksum, url) mods = read_file(args.version_file) names = [mod[0] for mod in mods] @@ -78,11 +83,12 @@ def install(args): # Using the latest urls, update downloads.txt to match and have the correct sha1 def apply_updates(args): - print("Populating URL File...") + print("Populating version File...") mods = read_file(args.filename) print("Getting new versions of all mods...") with open(args.version_file, 'w') as f: f.write('# Format: <jarname> <hex digested sha1> <direct download url>\n') + f.write("#VERSION " + str(VERSION + 1) + "\n") for mod in mods: print("Fetching {mod[0]}...".format(mod=mod)) resp = requests.get(mod[1]) @@ -91,12 +97,13 @@ def apply_updates(args): print() print("Done!") print("Updates applied to {args.version_file}".format(args=args)) + print("New pack version is " + str(VERSION + 1)) print("[!] No mods were installed. To update your mods folder, run 'update.py install'") # Find if any updates are available def check_updates(args): - print("Checking for updates to mods...") + print("Checking for updates to version " + str(VERSION) + "...") latest = read_file(args.filename) old = read_file(args.version_file) old_urls = [mod[2] for mod in old] @@ -126,7 +133,11 @@ if __name__ == "__main__": # initialize from config with open("pack-location.txt", "r") as f: args.pack_location = f.read().strip() - + + if not os.path.exists(args.version_file): + print("Error: version file\"" + args.version_file + "\" does not exist.") + parser.print_help() + sys.exit(1) if not os.path.exists(args.pack_location): print("Error: mod folder \"" + args.pack_location + "\" does not exist.") parser.print_help() @@ -140,6 +151,12 @@ if __name__ == "__main__": print("Error: command \"" + args.command + "\" does not exist") parser.print_help() sys.exit(1) - + + # fetch version + with open(args.version_file) as f: + for line in f: + if line.strip().split()[0] == "#VERSION": + VERSION = int(line.strip().split()[1]) + break # run the command COMMAND_MAP[args.command](args) diff --git a/downloads.txt b/version.txt index 7695dac..7bb3137 100644 --- a/downloads.txt +++ b/version.txt @@ -1,4 +1,5 @@ # Format: <jarname> <hex digested sha1> <direct download url> +#VERSION 0 thaumcraft.jar fe0899048f1796df04e9727bbf1898df30492a00 https://media.forgecdn.net/files/2629/23/Thaumcraft-1.12.2-6.1.BETA26.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 |