aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib/download.py
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-05-31 08:56:17 +0500
committermat <git@matdoes.dev>2025-05-30 19:22:09 -0845
commitf27c87b291a920376e006a470efb353dee46ed17 (patch)
treef1720081b856c5b7b96ab8111e6de4233f884e75 /codegen/lib/download.py
parente37524899eef8a0034faee35cef4bbf1ba779a7d (diff)
downloadazalea-drasl-f27c87b291a920376e006a470efb353dee46ed17.tar.xz
more formatting fixes
Diffstat (limited to 'codegen/lib/download.py')
-rw-r--r--codegen/lib/download.py161
1 files changed, 85 insertions, 76 deletions
diff --git a/codegen/lib/download.py b/codegen/lib/download.py
index 43ca8d2a..238336e2 100644
--- a/codegen/lib/download.py
+++ b/codegen/lib/download.py
@@ -6,29 +6,33 @@ import json
import os
# make sure the cache directory exists
-print('Making __cache__')
-if not os.path.exists(get_dir_location('__cache__')):
- print('Made __cache__ directory.', get_dir_location('__cache__'))
- os.mkdir(get_dir_location('__cache__'))
+print("Making __cache__")
+if not os.path.exists(get_dir_location("__cache__")):
+ print("Made __cache__ directory.", get_dir_location("__cache__"))
+ os.mkdir(get_dir_location("__cache__"))
def get_burger():
- if not os.path.exists(get_dir_location('__cache__/Burger')):
- print('\033[92mDownloading Burger...\033[m')
+ if not os.path.exists(get_dir_location("__cache__/Burger")):
+ print("\033[92mDownloading Burger...\033[m")
os.system(
- f'cd {get_dir_location("__cache__")} && git clone https://github.com/mat-1/Burger && cd Burger && git pull')
+ f"cd {get_dir_location('__cache__')} && git clone https://github.com/mat-1/Burger && cd Burger && git pull"
+ )
- print('\033[92mInstalling dependencies...\033[m')
- os.system(f'cd {get_dir_location("__cache__")}/Burger && python -m venv venv && venv/bin/pip install six jawa')
+ print("\033[92mInstalling dependencies...\033[m")
+ os.system(
+ f"cd {get_dir_location('__cache__')}/Burger && python -m venv venv && venv/bin/pip install six jawa"
+ )
def get_pumpkin_extractor():
- if not os.path.exists(get_dir_location('__cache__/pumpkin-extractor')):
- print('\033[92mDownloading Pumpkin-MC/Extractor...\033[m')
+ if not os.path.exists(get_dir_location("__cache__/pumpkin-extractor")):
+ print("\033[92mDownloading Pumpkin-MC/Extractor...\033[m")
os.system(
- f'cd {get_dir_location("__cache__")} && git clone https://github.com/Pumpkin-MC/Extractor pumpkin-extractor && cd pumpkin-extractor && git pull')
-
- GIT_PATCH = '''diff --git a/src/main/kotlin/de/snowii/extractor/extractors/Blocks.kt b/src/main/kotlin/de/snowii/extractor/extractors/Blocks.kt
+ f"cd {get_dir_location('__cache__')} && git clone https://github.com/Pumpkin-MC/Extractor pumpkin-extractor && cd pumpkin-extractor && git pull"
+ )
+
+ GIT_PATCH = """diff --git a/src/main/kotlin/de/snowii/extractor/extractors/Blocks.kt b/src/main/kotlin/de/snowii/extractor/extractors/Blocks.kt
index 936cd7b..9876a4b 100644
--- a/src/main/kotlin/de/snowii/extractor/extractors/Blocks.kt
+++ b/src/main/kotlin/de/snowii/extractor/extractors/Blocks.kt
@@ -51,166 +55,171 @@ index 936cd7b..9876a4b 100644
for (blockEntity in Registries.BLOCK_ENTITY_TYPE) {
if (blockEntity.supports(state)) {
-'''
+"""
os.system(
- f'cd {get_dir_location("__cache__")}/pumpkin-extractor && git apply - <<EOF\n{GIT_PATCH}\nEOF'
+ f"cd {get_dir_location('__cache__')}/pumpkin-extractor && git apply - <<EOF\n{GIT_PATCH}\nEOF"
)
-
- return get_dir_location('__cache__/pumpkin-extractor')
+
+ return get_dir_location("__cache__/pumpkin-extractor")
def get_version_manifest():
- if not os.path.exists(get_dir_location(f'__cache__/version_manifest.json')):
- print(
- f'\033[92mDownloading version manifest...\033[m')
+ if not os.path.exists(get_dir_location("__cache__/version_manifest.json")):
+ print("\033[92mDownloading version manifest...\033[m")
version_manifest_data = requests.get(
- 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json').json()
- with open(get_dir_location(f'__cache__/version_manifest.json'), 'w') as f:
+ "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
+ ).json()
+ with open(get_dir_location("__cache__/version_manifest.json"), "w") as f:
json.dump(version_manifest_data, f)
else:
- with open(get_dir_location(f'__cache__/version_manifest.json'), 'r') as f:
+ with open(get_dir_location("__cache__/version_manifest.json"), "r") as f:
version_manifest_data = json.load(f)
return version_manifest_data
def get_version_data(version_id: str):
- if not os.path.exists(get_dir_location(f'__cache__/{version_id}.json')):
+ if not os.path.exists(get_dir_location(f"__cache__/{version_id}.json")):
version_manifest_data = get_version_manifest()
- print(
- f'\033[92mGetting data for \033[1m{version_id}..\033[m')
+ print(f"\033[92mGetting data for \033[1m{version_id}..\033[m")
try:
package_url = next(
- filter(lambda v: v['id'] == version_id, version_manifest_data['versions']))['url']
+ filter(
+ lambda v: v["id"] == version_id, version_manifest_data["versions"]
+ )
+ )["url"]
except StopIteration:
raise ValueError(
- f'No version with id {version_id} found. Maybe delete __cache__/version_manifest.json and try again?')
+ f"No version with id {version_id} found. Maybe delete __cache__/version_manifest.json and try again?"
+ )
package_data = requests.get(package_url).json()
- with open(get_dir_location(f'__cache__/{version_id}.json'), 'w') as f:
+ with open(get_dir_location(f"__cache__/{version_id}.json"), "w") as f:
json.dump(package_data, f)
else:
- with open(get_dir_location(f'__cache__/{version_id}.json'), 'r') as f:
+ with open(get_dir_location(f"__cache__/{version_id}.json"), "r") as f:
package_data = json.load(f)
return package_data
def get_client_jar(version_id: str):
- if not os.path.exists(get_dir_location(f'__cache__/client-{version_id}.jar')):
+ if not os.path.exists(get_dir_location(f"__cache__/client-{version_id}.jar")):
package_data = get_version_data(version_id)
- print('\033[92mDownloading client jar...\033[m')
- client_jar_url = package_data['downloads']['client']['url']
- with open(get_dir_location(f'__cache__/client-{version_id}.jar'), 'wb') as f:
+ print("\033[92mDownloading client jar...\033[m")
+ client_jar_url = package_data["downloads"]["client"]["url"]
+ with open(get_dir_location(f"__cache__/client-{version_id}.jar"), "wb") as f:
f.write(requests.get(client_jar_url).content)
def get_server_jar(version_id: str):
- if not os.path.exists(get_dir_location(f'__cache__/server-{version_id}.jar')):
+ if not os.path.exists(get_dir_location(f"__cache__/server-{version_id}.jar")):
package_data = get_version_data(version_id)
- print('\033[92mDownloading server jar...\033[m')
- server_jar_url = package_data['downloads']['server']['url']
- with open(get_dir_location(f'__cache__/server-{version_id}.jar'), 'wb') as f:
+ print("\033[92mDownloading server jar...\033[m")
+ server_jar_url = package_data["downloads"]["server"]["url"]
+ with open(get_dir_location(f"__cache__/server-{version_id}.jar"), "wb") as f:
f.write(requests.get(server_jar_url).content)
def get_mappings_for_version(version_id: str):
- if not os.path.exists(get_dir_location(f'__cache__/mappings-{version_id}.txt')):
+ if not os.path.exists(get_dir_location(f"__cache__/mappings-{version_id}.txt")):
package_data = get_version_data(version_id)
- client_mappings_url = package_data['downloads']['client_mappings']['url']
+ client_mappings_url = package_data["downloads"]["client_mappings"]["url"]
mappings_text = requests.get(client_mappings_url).text
- with open(get_dir_location(f'__cache__/mappings-{version_id}.txt'), 'w') as f:
+ with open(get_dir_location(f"__cache__/mappings-{version_id}.txt"), "w") as f:
f.write(mappings_text)
else:
- with open(get_dir_location(f'__cache__/mappings-{version_id}.txt'), 'r') as f:
+ with open(get_dir_location(f"__cache__/mappings-{version_id}.txt"), "r") as f:
mappings_text = f.read()
return Mappings.parse(mappings_text)
def get_yarn_versions():
# https://meta.fabricmc.net/v2/versions/yarn
- if not os.path.exists(get_dir_location('__cache__/yarn_versions.json')):
- print('\033[92mDownloading yarn versions...\033[m')
+ if not os.path.exists(get_dir_location("__cache__/yarn_versions.json")):
+ print("\033[92mDownloading yarn versions...\033[m")
yarn_versions_data = requests.get(
- 'https://meta.fabricmc.net/v2/versions/yarn').json()
- with open(get_dir_location('__cache__/yarn_versions.json'), 'w') as f:
+ "https://meta.fabricmc.net/v2/versions/yarn"
+ ).json()
+ with open(get_dir_location("__cache__/yarn_versions.json"), "w") as f:
json.dump(yarn_versions_data, f)
else:
- with open(get_dir_location('__cache__/yarn_versions.json'), 'r') as f:
+ with open(get_dir_location("__cache__/yarn_versions.json"), "r") as f:
yarn_versions_data = json.load(f)
return yarn_versions_data
def get_yarn_data(version_id: str):
for version in get_yarn_versions():
- if version['gameVersion'] == version_id:
+ if version["gameVersion"] == version_id:
return version
def get_fabric_api_versions():
# https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml
- if not os.path.exists(get_dir_location('__cache__/fabric_api_versions.json')):
- print('\033[92mDownloading Fabric API versions...\033[m')
+ if not os.path.exists(get_dir_location("__cache__/fabric_api_versions.json")):
+ print("\033[92mDownloading Fabric API versions...\033[m")
fabric_api_versions_xml_text = requests.get(
- 'https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml').text
+ "https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml"
+ ).text
# parse xml
- fabric_api_versions_data_xml = ET.fromstring(
- fabric_api_versions_xml_text)
+ fabric_api_versions_data_xml = ET.fromstring(fabric_api_versions_xml_text)
fabric_api_versions = []
- versioning_el = fabric_api_versions_data_xml.find('versioning')
+ versioning_el = fabric_api_versions_data_xml.find("versioning")
assert versioning_el
- versions_el = versioning_el.find('versions')
+ versions_el = versioning_el.find("versions")
assert versions_el
- for version_el in versions_el.findall('version'):
+ for version_el in versions_el.findall("version"):
fabric_api_versions.append(version_el.text)
- with open(get_dir_location('__cache__/fabric_api_versions.json'), 'w') as f:
+ with open(get_dir_location("__cache__/fabric_api_versions.json"), "w") as f:
f.write(json.dumps(fabric_api_versions))
else:
- with open(get_dir_location('__cache__/fabric_api_versions.json'), 'r') as f:
+ with open(get_dir_location("__cache__/fabric_api_versions.json"), "r") as f:
fabric_api_versions = json.loads(f.read())
return fabric_api_versions
def get_fabric_loader_versions():
# https://meta.fabricmc.net/v2/versions/loader
- if not os.path.exists(get_dir_location('__cache__/fabric_loader_versions.json')):
- print('\033[92mDownloading Fabric loader versions...\033[m')
+ if not os.path.exists(get_dir_location("__cache__/fabric_loader_versions.json")):
+ print("\033[92mDownloading Fabric loader versions...\033[m")
fabric_api_versions_json = requests.get(
- 'https://meta.fabricmc.net/v2/versions/loader').json()
+ "https://meta.fabricmc.net/v2/versions/loader"
+ ).json()
fabric_api_versions = []
for version in fabric_api_versions_json:
- fabric_api_versions.append(version['version'])
+ fabric_api_versions.append(version["version"])
- with open(get_dir_location('__cache__/fabric_loader_versions.json'), 'w') as f:
+ with open(get_dir_location("__cache__/fabric_loader_versions.json"), "w") as f:
f.write(json.dumps(fabric_api_versions))
else:
- with open(get_dir_location('__cache__/fabric_loader_versions.json'), 'r') as f:
+ with open(get_dir_location("__cache__/fabric_loader_versions.json"), "r") as f:
fabric_api_versions = json.loads(f.read())
return fabric_api_versions
def clear_version_cache():
- print('\033[92mClearing version cache...\033[m')
+ print("\033[92mClearing version cache...\033[m")
files = [
- 'version_manifest.json',
- 'yarn_versions.json',
- 'fabric_api_versions.json',
- 'fabric_loader_versions.json'
+ "version_manifest.json",
+ "yarn_versions.json",
+ "fabric_api_versions.json",
+ "fabric_loader_versions.json",
]
for file in files:
- if os.path.exists(get_dir_location(f'__cache__/{file}')):
- os.remove(get_dir_location(f'__cache__/{file}'))
+ if os.path.exists(get_dir_location(f"__cache__/{file}")):
+ os.remove(get_dir_location(f"__cache__/{file}"))
burger_path = get_dir_location("__cache__/Burger")
if os.path.exists(burger_path):
- os.system(
- f'cd {burger_path} && git pull')
- pumpkin_path = get_dir_location('__cache__/pumpkin-extractor')
+ os.system(f"cd {burger_path} && git pull")
+ pumpkin_path = get_dir_location("__cache__/pumpkin-extractor")
if os.path.exists(pumpkin_path):
os.system(
- f'cd {pumpkin_path} && git add . && git stash && git pull && git stash pop') \ No newline at end of file
+ f"cd {pumpkin_path} && git add . && git stash && git pull && git stash pop"
+ )