diff options
Diffstat (limited to 'update.py')
-rwxr-xr-x | update.py | 37 |
1 files changed, 27 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) |