mc-get/mc-get.py

66 lines
2.4 KiB
Python

import argparse
import api
import mcfs
import npyscreen
import os
def validate():
pass
def version_selector_GUI(vers:list, project:str):
def form(*args):
F = npyscreen.Form(name=f"Select {project} version")
sel = F.add(npyscreen.TitleSelectOne, value=[1,], name="versions:",\
values=[ver.version_number + " for " +\
", ".join(ver.game_versions)\
for ver in vers[::-1]], scroll_exit=True)
F.edit()
for ver in vers:
if ver.version_number == sel.get_selected_objects()[0].split()[0]:
return ver
return vers[0]
return form
def install(projects:list):
to_install = []
for project in projects:
project_data = api.project(project=project)
to_install.append(project_data)
for project in to_install:
versions = api.versions(ids=str(project.versions).replace("'", '"')) #i hate this
version = npyscreen.wrapper_basic(version_selector_GUI(versions,\
project.slug))
file = type("mc_file", (object, ), version.files[0])
filename = file.url.split("/")[-1]
cache_file_path = os.path.join(mcfs.cache_dir, filename)
if not mcfs.is_path_exist(mcfs.cache_dir):
os.mkdir(mcfs.cache_dir)
if not mcfs.is_path_exist(cache_file_path):
api.download(file.url, file.size, cache_file_path)
else:
print(f"{filename} is in cache.")
mcfs.install(filename)
def search():
pass
if __name__ == "__main__":
desc = '''Minecraft mods packet\
manager based on modrinth API\n\nMethods:\n install - install mod\n \
validate - validate mods installation\n search - search mods'''
parser = argparse.ArgumentParser(description=desc,\
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("method", choices=['install', 'search', 'validate'],\
metavar="method")
parser.add_argument("method_args", nargs="*")
args = parser.parse_args()
match args.method:
case "install":
install(args.method_args)
case "search":
search()
case "validate":
validate()
case _:
print("Unknown method", args.method)
parser.print_help()