1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)
|