This repository has been archived on 2022-06-06. You can view files and clone it, but cannot push or open issues or pull requests.
minecraft-libs-parser/minecraft_libs/__main__.py

70 lines
2.0 KiB
Python
Raw Normal View History

2021-07-22 00:44:39 +03:00
"""Parse version.json file and return libs"""
2021-07-21 04:34:01 +03:00
import sys
import json
import click
@click.command()
@click.option("--platform", default=sys.platform, help="Output platform (win32, linux, darwin).")
@click.option("--output", default="tty", help="Output option (tty, txt).")
def make_output(platform, output):
2021-07-22 00:44:39 +03:00
"""Return libraries list"""
2021-07-21 04:34:01 +03:00
libraries = parse_libs()
# OS libs separate
_ = {"win32": ";", "linux": ":", "darwin": ":"}
out_lib = str()
# Generate libraries list
for lib in libraries:
out_lib = out_lib + "$MC_DIR/libraries/{0}".format(lib) + _[platform]
out_lib = out_lib + "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar"
# Replace for OS shell variable symbol
if platform == "win32":
out_lib = out_lib.replace("$MC_DIR", "%MC_DIR%")
out_lib = out_lib.replace("$GAME_VERSION", "%GAME_VERSION%")
if output == "tty":
click.echo(out_lib)
if platform == "win32":
print("\nWindows generate libraries list complete!")
2021-07-22 00:44:39 +03:00
elif ("linux", "darwin") in platform:
2021-07-21 04:34:01 +03:00
print("\nUnix generate libraries list complete!")
elif output == "txt":
with open("./libs.txt", "w", encoding="utf-8") as f:
f.write(out_lib)
if platform == "win32":
print("\nWindows generate libraries list complete!\n" "See libs.txt file.")
2021-07-22 00:44:39 +03:00
elif ("linux", "darwin") in platform:
2021-07-21 04:34:01 +03:00
print("\nUnix generate libraries list complete!\n" "See libs.txt file.")
def parse_libs():
2021-07-22 00:44:39 +03:00
"""Make libraries list from version.json file"""
2021-07-21 04:34:01 +03:00
_ = []
2021-07-22 00:44:39 +03:00
try:
with open("./version.json", "r", encoding="utf-8") as f:
file_data = json.loads(f.read())
2021-07-21 04:34:01 +03:00
2021-07-22 00:44:39 +03:00
for lib in file_data["libraries"]:
_.append(lib["downloads"]["artifact"]["path"])
except FileNotFoundError:
print("ERROR: File version.json not found.")
sys.exit(-1)
2021-07-21 04:34:01 +03:00
return _
if __name__ == "__main__":
2021-07-22 01:05:02 +03:00
# pylint: disable=no-value-for-parameter
make_output()