diff options
author | Alexander Hayden <alexhayden25@gmail.com> | 2020-11-27 19:20:16 -0500 |
---|---|---|
committer | Alexander Hayden <alexhayden25@gmail.com> | 2020-11-27 19:20:16 -0500 |
commit | 48c5159402d4d5a6e0dcf3fac1c56d8a6b99c10d (patch) | |
tree | 6e68f542deb82d0ce1065eb6e5e8df52450a3217 /modpackman.py | |
parent | 55c7ef774db75e7ba37a3a121f749ab60f8d4117 (diff) | |
download | modpackman-48c5159402d4d5a6e0dcf3fac1c56d8a6b99c10d.tar.gz modpackman-48c5159402d4d5a6e0dcf3fac1c56d8a6b99c10d.zip |
refactor. hopefully it works.
Diffstat (limited to 'modpackman.py')
-rwxr-xr-x | modpackman.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/modpackman.py b/modpackman.py new file mode 100755 index 0000000..e5c355d --- /dev/null +++ b/modpackman.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +import argparse +import os +import sys +import shutil + +import util + + +parser = argparse.ArgumentParser( + description="A Simple Git-Based Modpack Manager", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog='''\ +Available commands: + 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', + nargs='?', + default='install', + help="The action to perform (default: install)") +parser.add_argument('filename', + nargs='?', + default="mods.txt", + help="Optional filename to specify latest mods (default: mods.txt)") +parser.add_argument('--version-file', + type=str, + 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)") +parser.add_argument('--whitelist-file', + type=str, + default="whitelist.txt", + help="Optional custom whitelist file that tells 'install' which files not to remove (default: whitelist.txt)") +parser.add_argument("--game-version", + type=str, + default=None, + help="The maximum game version to update mods to") + +COMMAND_MAP = ["install", "apply_updates", "check_updates"] + +if __name__ == "__main__": + args = parser.parse_args() + config = util.load_config() + mods = config['mods'] + pack = config['pack'] + + GAME_VERSION = util.game_version_from_string(pack["game_version"]) + if args.pack_location: + pack['location'] = args.pack_location + + 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 args.pack_location and not os.path.exists(args.pack_location): + print("Error: mod folder \"" + args.pack_location + "\" does not exist.") + parser.print_help() + sys.exit(1) + elif args.pack_location and not os.path.isdir(args.pack_location): + print("Error: mod folder \"" + args.pack_location + "\" is not actually a folder.") + parser.print_help() + sys.exit(1) + if not os.path.exists(args.whitelist_file): + print("Error: whitelist file \"" + args.whitelist_file + "\" does not exist.") + sys.exit(1) + if args.game_version: + GAME_VERSION = util.game_version_from_string(args.game_version) + + if not (args.command in COMMAND_MAP): + print("Error: command \"" + args.command + "\" does not exist") + parser.print_help() + sys.exit(1) + + # run the command + if args.command == "install": + util.install(args.version_file, args.whitelist_file, pack['location']) + elif args.command == "apply_updates": + util.apply_updates(mods, args.version_file, GAME_VERSION) + elif args.command == "check_updates": + util.check_updates(mods, args.version_file, GAME_VERSION) |