-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect_keys.py
More file actions
65 lines (58 loc) · 1.98 KB
/
collect_keys.py
File metadata and controls
65 lines (58 loc) · 1.98 KB
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
#!/usr/bin/env python3
import modset_common as common
import argparse
import shutil
import glob
parser = argparse.ArgumentParser(
prog="collect_keys.py",
usage="%(prog)s {-l [load_order] OR -p [modset]} [options]",
description="Collect the .bikey files from the downloaded mods contained a preset or workshop collection or load order string.",
)
parser.add_argument(
"-m",
"--modset",
help="preset or workshop collection (id or url) to select mods from",
default=None,
)
parser.add_argument(
"-l", "--load-order", help="load order to select mods from", default=None
)
parser.add_argument(
"-i", "--input", help="directory to search for mods in", default="./"
)
parser.add_argument(
"-o", "--output", help="directory to output the collected keys to", default="./keys"
)
args = parser.parse_args()
possible_mod_paths = []
if not args.modset is None:
modset = common.ModSet.from_collection_preset(args.modset)
possible_mod_paths = [["@" + mod.name, mod.id] for mod in modset.mods]
elif not args.load_order is None:
mod_folders = args.load_order.split(";")
possible_mod_paths = [[(mod_folder) for mod_folder in mod_folders]]
else:
raise Exception("You must specify either a -l/--load-order or -m/--modset.")
all_keys = []
for possible_path in possible_mod_paths:
keys = []
for mod in possible_path:
keys.extend(
glob.glob(args.input + "/" + glob.escape(mod) + "/*.bikey", recursive=True)
)
keys.extend(
glob.glob(
args.input + "/" + glob.escape(mod) + "/[kK]eys/*.bikey", recursive=True
)
)
keys.extend(
glob.glob(
args.input + "/" + glob.escape(mod) + "/[kK]ey/*.bikey", recursive=True
)
)
if len(keys) == 0:
print("Key was not found for '" + possible_path[0] + "'.")
all_keys.extend(keys)
for key in all_keys:
print("Copying '" + key + "' to '" + args.output + "'")
shutil.copy(key, args.output)