minecraft-launcher/tools/make_libs_list.py

55 lines
1.2 KiB
Python
Raw Normal View History

2020-07-02 22:46:42 +03:00
#!/usr/bin/env python3
import json
2020-10-05 03:14:05 +03:00
import click
2020-07-02 22:46:42 +03:00
2020-10-05 03:19:23 +03:00
__author__ = "Alexander Popov"
2020-10-10 02:29:27 +03:00
__version__ = "1.0.1"
2020-10-05 03:19:23 +03:00
__license__ = "Unlicense"
2020-07-02 22:46:42 +03:00
2020-10-05 03:14:05 +03:00
@click.command()
2020-10-05 03:19:23 +03:00
@click.option("--platform", default="win", help="Output platform (win, unix).")
2020-10-05 03:14:05 +03:00
def make_output(platform):
""" Return libraries list """
libraries = parse_libs()
2020-10-05 03:19:23 +03:00
_ = {"win": ";", "unix": ":"}
2020-10-05 03:14:05 +03:00
output = str()
for lib in libraries:
2020-10-05 03:19:23 +03:00
output = output + "$MC_DIR/libraries/{0}".format(lib) + _[platform]
2020-10-05 03:14:05 +03:00
2020-10-05 03:19:23 +03:00
output = output + "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar"
2020-10-05 03:14:05 +03:00
2020-10-05 03:19:23 +03:00
if platform == "win":
output = output.replace("$MC_DIR", "%MC_DIR%")
output = output.replace("$GAME_VERSION", "%GAME_VERSION%")
2020-10-05 03:14:05 +03:00
click.echo(output)
2020-10-10 02:29:27 +03:00
if platform == "win":
print("\nWindows generate libraries list complete!")
elif platform == "unix":
print("\nLinux generate libraries list complete!")
2020-10-05 03:14:05 +03:00
2020-07-02 22:46:42 +03:00
def parse_libs():
2020-07-02 22:52:36 +03:00
""" Make libraries list from version.json file """
2020-07-02 22:46:42 +03:00
_ = []
2020-10-05 03:19:23 +03:00
with open("./version.json", "r", encoding="utf-8") as f:
2020-07-02 22:46:42 +03:00
file_data = json.loads(f.read())
2020-10-05 03:19:23 +03:00
for lib in file_data["libraries"]:
_.append(lib["downloads"]["artifact"]["path"])
2020-07-02 22:46:42 +03:00
2020-10-05 03:19:23 +03:00
return _
2020-07-02 22:46:42 +03:00
2020-10-05 03:19:23 +03:00
if __name__ == "__main__":
2020-10-05 03:14:05 +03:00
make_output()