azalea/codegen/lib/download.py

184 lines
7.4 KiB
Python
Raw Normal View History

2022-05-27 06:11:42 +00:00
from lib.utils import get_dir_location
import xml.etree.ElementTree as ET
2022-05-25 01:28:08 +00:00
from .mappings import Mappings
2022-05-25 00:50:19 +00:00
import requests
import json
import os
2022-05-25 01:28:08 +00:00
# make sure the downloads directory exists
2022-06-22 00:05:44 +00:00
print('Making downloads')
2022-05-27 06:11:42 +00:00
if not os.path.exists(get_dir_location('downloads')):
2022-06-22 00:05:44 +00:00
print('Made downloads directory.', get_dir_location('downloads'))
2022-05-27 06:11:42 +00:00
os.mkdir(get_dir_location('downloads'))
2022-05-25 00:50:19 +00:00
2022-05-25 01:28:08 +00:00
def get_burger():
2022-05-27 06:11:42 +00:00
if not os.path.exists(get_dir_location('downloads/Burger')):
2022-05-25 01:28:08 +00:00
print('\033[92mDownloading Burger...\033[m')
os.system(
2022-05-27 06:11:42 +00:00
f'cd {get_dir_location("downloads")} && git clone https://github.com/pokechu22/Burger && cd Burger && git pull')
2022-05-25 01:28:08 +00:00
print('\033[92mInstalling dependencies...\033[m')
1.19.3 (#34) * start updating to 22w42a * work a bit more on 22w42a * player chat packet * serverbound hello packet * Update mod.rs * add more stuff to clientbound player chat packet * ClientboundPlayerInfoUpdatePacket * features enabled and container closed * serverbound chat packets * make it compile * 22w43a * ServerboundChatSessionUpdatePacket * profile_public_key isn't Option anymore * Update bitset.rs * joining a server works * fix entitydatavalue * backtraces + fix clientbound chat message * fix some warnings and add more ecomments * 22w44a * generate en_us.json * add updating guide to codegen/readme * fix some markdown * update list of generated things * metadata stuff * Replace PJS generator mod with PixLyzer (#38) * pixlizer extractor * start working on shape extraction * fix generating language * fix pixlyzer shape generation * use empty_shape * generate blocks and shapes * update pixlyzer dir * Revert "update pixlyzer dir" This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71. * fix * fix * Revert "fix" This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d. * fix * detect pixlyzer fail * fix pixlyzer * 22w45a * gen entities * add async-trait dep * update codegen/readme.md * explain when rust_log should be used * remove some unused code * start fixing pixlyzer issues * fix a thing in codegen * almost fixed * more progress towards 1.19.3 * 1.19.3-pre2 * fixes * revert some hardcoded property names * Delete clientbound_player_info_packet.rs * handle 1.19.3 player info packets * handle playerinforemove * start updating to 1.19.3-rc1 * optional registries work * fix some issues with 1.19.3 chat doesn't work yet * aaaaaaaaaaaaaaaaa * oh * ignore unused shapes * uncomment generate_blocks * fix migrate * 1.19.3-rc2 * fix clippy warnings * 1.19.3-rc3 * split the azalea-buf macro into separate modules * improve Recipe in protocol * 1.19.3
2022-12-08 03:09:58 +00:00
os.system(f'cd {get_dir_location("downloads")}/Burger && pip install six jawa')
2022-05-25 00:50:19 +00:00
1.19.3 (#34) * start updating to 22w42a * work a bit more on 22w42a * player chat packet * serverbound hello packet * Update mod.rs * add more stuff to clientbound player chat packet * ClientboundPlayerInfoUpdatePacket * features enabled and container closed * serverbound chat packets * make it compile * 22w43a * ServerboundChatSessionUpdatePacket * profile_public_key isn't Option anymore * Update bitset.rs * joining a server works * fix entitydatavalue * backtraces + fix clientbound chat message * fix some warnings and add more ecomments * 22w44a * generate en_us.json * add updating guide to codegen/readme * fix some markdown * update list of generated things * metadata stuff * Replace PJS generator mod with PixLyzer (#38) * pixlizer extractor * start working on shape extraction * fix generating language * fix pixlyzer shape generation * use empty_shape * generate blocks and shapes * update pixlyzer dir * Revert "update pixlyzer dir" This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71. * fix * fix * Revert "fix" This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d. * fix * detect pixlyzer fail * fix pixlyzer * 22w45a * gen entities * add async-trait dep * update codegen/readme.md * explain when rust_log should be used * remove some unused code * start fixing pixlyzer issues * fix a thing in codegen * almost fixed * more progress towards 1.19.3 * 1.19.3-pre2 * fixes * revert some hardcoded property names * Delete clientbound_player_info_packet.rs * handle 1.19.3 player info packets * handle playerinforemove * start updating to 1.19.3-rc1 * optional registries work * fix some issues with 1.19.3 chat doesn't work yet * aaaaaaaaaaaaaaaaa * oh * ignore unused shapes * uncomment generate_blocks * fix migrate * 1.19.3-rc2 * fix clippy warnings * 1.19.3-rc3 * split the azalea-buf macro into separate modules * improve Recipe in protocol * 1.19.3
2022-12-08 03:09:58 +00:00
def get_pixlyzer():
if not os.path.exists(get_dir_location('downloads/pixlyzer')):
print('\033[92mDownloading bixilon/pixlyzer...\033[m')
os.system(
1.19.3 (#34) * start updating to 22w42a * work a bit more on 22w42a * player chat packet * serverbound hello packet * Update mod.rs * add more stuff to clientbound player chat packet * ClientboundPlayerInfoUpdatePacket * features enabled and container closed * serverbound chat packets * make it compile * 22w43a * ServerboundChatSessionUpdatePacket * profile_public_key isn't Option anymore * Update bitset.rs * joining a server works * fix entitydatavalue * backtraces + fix clientbound chat message * fix some warnings and add more ecomments * 22w44a * generate en_us.json * add updating guide to codegen/readme * fix some markdown * update list of generated things * metadata stuff * Replace PJS generator mod with PixLyzer (#38) * pixlizer extractor * start working on shape extraction * fix generating language * fix pixlyzer shape generation * use empty_shape * generate blocks and shapes * update pixlyzer dir * Revert "update pixlyzer dir" This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71. * fix * fix * Revert "fix" This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d. * fix * detect pixlyzer fail * fix pixlyzer * 22w45a * gen entities * add async-trait dep * update codegen/readme.md * explain when rust_log should be used * remove some unused code * start fixing pixlyzer issues * fix a thing in codegen * almost fixed * more progress towards 1.19.3 * 1.19.3-pre2 * fixes * revert some hardcoded property names * Delete clientbound_player_info_packet.rs * handle 1.19.3 player info packets * handle playerinforemove * start updating to 1.19.3-rc1 * optional registries work * fix some issues with 1.19.3 chat doesn't work yet * aaaaaaaaaaaaaaaaa * oh * ignore unused shapes * uncomment generate_blocks * fix migrate * 1.19.3-rc2 * fix clippy warnings * 1.19.3-rc3 * split the azalea-buf macro into separate modules * improve Recipe in protocol * 1.19.3
2022-12-08 03:09:58 +00:00
f'cd {get_dir_location("downloads")} && git clone https://gitlab.bixilon.de/bixilon/pixlyzer.git && cd pixlyzer && git pull')
return get_dir_location('downloads/pixlyzer')
2022-05-25 00:50:19 +00:00
def get_version_manifest():
2022-05-27 06:11:42 +00:00
if not os.path.exists(get_dir_location(f'downloads/version_manifest.json')):
2022-05-25 00:50:19 +00:00
print(
f'\033[92mDownloading version manifest...\033[m')
version_manifest_data = requests.get(
'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json').json()
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/version_manifest.json'), 'w') as f:
2022-05-25 00:50:19 +00:00
json.dump(version_manifest_data, f)
else:
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/version_manifest.json'), 'r') as f:
2022-05-25 00:50:19 +00:00
version_manifest_data = json.load(f)
return version_manifest_data
def get_version_data(version_id: str):
2022-05-27 06:11:42 +00:00
if not os.path.exists(get_dir_location(f'downloads/{version_id}.json')):
2022-05-25 00:50:19 +00:00
version_manifest_data = get_version_manifest()
print(
f'\033[92mGetting data for \033[1m{version_id}..\033[m')
2022-05-26 01:09:48 +00:00
try:
package_url = next(
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 downloads/version_manifest.json and try again?')
2022-05-25 00:50:19 +00:00
package_data = requests.get(package_url).json()
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/{version_id}.json'), 'w') as f:
2022-05-25 00:50:19 +00:00
json.dump(package_data, f)
else:
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/{version_id}.json'), 'r') as f:
2022-05-25 00:50:19 +00:00
package_data = json.load(f)
return package_data
def get_client_jar(version_id: str):
2022-05-27 06:11:42 +00:00
if not os.path.exists(get_dir_location(f'downloads/client-{version_id}.jar')):
2022-05-25 00:50:19 +00:00
package_data = get_version_data(version_id)
print('\033[92mDownloading client jar...\033[m')
client_jar_url = package_data['downloads']['client']['url']
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/client-{version_id}.jar'), 'wb') as f:
2022-05-25 00:50:19 +00:00
f.write(requests.get(client_jar_url).content)
def get_server_jar(version_id: str):
if not os.path.exists(get_dir_location(f'downloads/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'downloads/server-{version_id}.jar'), 'wb') as f:
f.write(requests.get(server_jar_url).content)
2022-05-25 00:50:19 +00:00
def get_mappings_for_version(version_id: str):
2022-05-27 06:11:42 +00:00
if not os.path.exists(get_dir_location(f'downloads/mappings-{version_id}.txt')):
2022-05-25 00:50:19 +00:00
package_data = get_version_data(version_id)
client_mappings_url = package_data['downloads']['client_mappings']['url']
mappings_text = requests.get(client_mappings_url).text
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/mappings-{version_id}.txt'), 'w') as f:
2022-05-25 00:50:19 +00:00
f.write(mappings_text)
else:
2022-05-27 06:11:42 +00:00
with open(get_dir_location(f'downloads/mappings-{version_id}.txt'), 'r') as f:
2022-05-25 00:50:19 +00:00
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('downloads/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('downloads/yarn_versions.json'), 'w') as f:
json.dump(yarn_versions_data, f)
else:
with open(get_dir_location('downloads/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:
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('downloads/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
# parse xml
fabric_api_versions_data_xml = ET.fromstring(
fabric_api_versions_xml_text)
fabric_api_versions = []
2022-06-22 00:57:18 +00:00
versioning_el = fabric_api_versions_data_xml.find('versioning')
assert versioning_el
versions_el = versioning_el.find('versions')
assert versions_el
for version_el in versions_el.findall('version'):
fabric_api_versions.append(version_el.text)
with open(get_dir_location('downloads/fabric_api_versions.json'), 'w') as f:
f.write(json.dumps(fabric_api_versions))
else:
with open(get_dir_location('downloads/fabric_api_versions.json'), 'r') as f:
fabric_api_versions = json.loads(f.read())
return fabric_api_versions
2022-08-20 21:48:08 +00:00
def get_fabric_loader_versions():
# https://meta.fabricmc.net/v2/versions/loader
if not os.path.exists(get_dir_location('downloads/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()
fabric_api_versions = []
for version in fabric_api_versions_json:
fabric_api_versions.append(version['version'])
with open(get_dir_location('downloads/fabric_loader_versions.json'), 'w') as f:
f.write(json.dumps(fabric_api_versions))
else:
with open(get_dir_location('downloads/fabric_loader_versions.json'), 'r') as f:
fabric_api_versions = json.loads(f.read())
return fabric_api_versions
def clear_version_cache():
2022-06-22 00:05:44 +00:00
print('\033[92mClearing version cache...\033[m')
files = [
'version_manifest.json',
'yarn_versions.json',
2022-08-20 21:48:08 +00:00
'fabric_api_versions.json',
'fabric_loader_versions.json'
]
2022-06-22 00:05:44 +00:00
for file in files:
if os.path.exists(get_dir_location(f'downloads/{file}')):
os.remove(get_dir_location(f'downloads/{file}'))
os.system(
f'cd {get_dir_location("downloads/Burger")} && git pull')
os.system(
1.19.3 (#34) * start updating to 22w42a * work a bit more on 22w42a * player chat packet * serverbound hello packet * Update mod.rs * add more stuff to clientbound player chat packet * ClientboundPlayerInfoUpdatePacket * features enabled and container closed * serverbound chat packets * make it compile * 22w43a * ServerboundChatSessionUpdatePacket * profile_public_key isn't Option anymore * Update bitset.rs * joining a server works * fix entitydatavalue * backtraces + fix clientbound chat message * fix some warnings and add more ecomments * 22w44a * generate en_us.json * add updating guide to codegen/readme * fix some markdown * update list of generated things * metadata stuff * Replace PJS generator mod with PixLyzer (#38) * pixlizer extractor * start working on shape extraction * fix generating language * fix pixlyzer shape generation * use empty_shape * generate blocks and shapes * update pixlyzer dir * Revert "update pixlyzer dir" This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71. * fix * fix * Revert "fix" This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d. * fix * detect pixlyzer fail * fix pixlyzer * 22w45a * gen entities * add async-trait dep * update codegen/readme.md * explain when rust_log should be used * remove some unused code * start fixing pixlyzer issues * fix a thing in codegen * almost fixed * more progress towards 1.19.3 * 1.19.3-pre2 * fixes * revert some hardcoded property names * Delete clientbound_player_info_packet.rs * handle 1.19.3 player info packets * handle playerinforemove * start updating to 1.19.3-rc1 * optional registries work * fix some issues with 1.19.3 chat doesn't work yet * aaaaaaaaaaaaaaaaa * oh * ignore unused shapes * uncomment generate_blocks * fix migrate * 1.19.3-rc2 * fix clippy warnings * 1.19.3-rc3 * split the azalea-buf macro into separate modules * improve Recipe in protocol * 1.19.3
2022-12-08 03:09:58 +00:00
f'cd {get_dir_location("downloads/pixlyzer")} && git pull')