-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathfeather.py
More file actions
96 lines (79 loc) · 3.08 KB
/
Copy pathfeather.py
File metadata and controls
96 lines (79 loc) · 3.08 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import sys
import subprocess
MAPPINGS_DIR = 'mappings'
GRADLE_TASKS = ['clean', 'enigma', 'enigmaWithoutUnpick', 'build', 'javadoc', 'javadocJar', 'checkMappings',
'mapMinecraftToIntermediary', 'mapMinecraftToNamed', 'decompileWithCfr', 'decompileWithVineflower',
'publish', 'loadMappings', 'insertMappings', 'saveMappingsDown', 'saveMappingsUp', 'saveMappings']
GRADLEW = 'gradlew' if os.name == 'nt' else './gradlew'
# some jank to hide versions that are giving problems
UNAVAILABLE_VERSIONS = []
# shortcuts for versions with ugly ids
VERSION_SHORTCUTS = {
'1.0': '1.0.0'
}
def main():
possible_versions = list(set(find_minecraft_versions()))
versions = []
tasks = []
options = []
args = sys.argv
for i in range(1, len(args)):
arg = args[i]
parsed_arg = parse_minecraft_version(arg, possible_versions)
if parsed_arg:
for version in parsed_arg:
versions.append(version)
else:
if arg in GRADLE_TASKS:
tasks.append(arg)
elif arg.startswith('--') or arg.startswith('-D'):
options.append(arg)
else:
raise Exception('unrecognized arg ' + arg + '!')
if len(versions) == 0:
if 'MC_VERSION' in os.environ:
parsed_arg = parse_minecraft_version(os.environ['MC_VERSION'], possible_versions)
if parsed_arg:
for version in parsed_arg:
versions.append(version)
else:
raise Exception('no minecraft version given!')
else:
raise Exception('no minecraft version given!')
if len(tasks) == 0:
raise Exception('no gradle tasks given!')
command = [GRADLEW]
command.extend(tasks)
command.extend(options)
command.append('--stacktrace')
if len(versions) == 1:
os.environ['MC_VERSION'] = versions[0]
else:
os.environ['MC_VERSIONS'] = ",".join(versions)
subprocess.run(" ".join(command), shell=True, check=True)
def find_minecraft_versions():
for filename in os.listdir("mappings"):
if filename.endswith(".tiny"):
yield filename[:-len(".tiny")]
elif filename.endswith(".tinydiff"):
if len(pair := filename[:-len(".tinydiff")].split("#")) == 2:
yield pair[-1]
def parse_minecraft_version(arg, possible_versions):
if arg in VERSION_SHORTCUTS.keys():
return parse_minecraft_version(VERSION_SHORTCUTS[arg], possible_versions)
versions = []
if arg in possible_versions:
versions.append(arg)
elif '&' not in arg:
for possible_version in possible_versions:
if '&' in possible_version:
for mc_version in possible_version.split('&'):
if arg == mc_version:
versions.append(possible_version)
for version in versions:
if version in UNAVAILABLE_VERSIONS:
raise Exception('version ' + version + ' is unavailable at the moment!')
return versions
if __name__ == '__main__':
main()