diff options
Diffstat (limited to 'codegen/lib/extract.py')
| -rw-r--r-- | codegen/lib/extract.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py index 4c2d2399..7c27d1ae 100644 --- a/codegen/lib/extract.py +++ b/codegen/lib/extract.py @@ -2,7 +2,9 @@ from lib.download import get_server_jar, get_burger, get_client_jar, get_generator_mod, get_yarn_data, get_fabric_api_versions from lib.utils import get_dir_location +import subprocess import json +import re import os @@ -31,15 +33,38 @@ def get_ordered_blocks_burger(version_id: str): burger_data = get_burger_data_for_version(version_id) return burger_data[0]['blocks']['ordered_blocks'] +python_command = None +def determine_python_command(): + global python_command + if python_command: + return python_command + + def try_python_command(version): + return os.system(f'{version} --version') == 0 + + for version in ('python3.9', 'python3.8', 'python3', 'python'): + if try_python_command(version): + python_command = version + return version + raise Exception('Couldn\'t determine python command to use to run burger with!') def get_burger_data_for_version(version_id: str): if not os.path.exists(get_dir_location(f'downloads/burger-{version_id}.json')): get_burger() get_client_jar(version_id) - os.system( - f'cd {get_dir_location("downloads/Burger")} && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json' - ) + for _ in range(10): + r = subprocess.run( + f'cd {get_dir_location("downloads/Burger")} && {determine_python_command()} munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json', + capture_output=True, + shell=True + ) + regex_match = re.search(r'ModuleNotFoundError: No module named \'(\w+?)\'', r.stderr.decode()) + if not regex_match: + break + missing_lib = regex_match.group(1) + print('Missing required lib for Burger:', missing_lib) + os.system(f'{determine_python_command()} -m pip install {missing_lib}') with open(get_dir_location(f'downloads/burger-{version_id}.json'), 'r') as f: return json.load(f) |
