diff --git a/mc-get.py b/mc-get.py index 284336b..577eabd 100755 --- a/mc-get.py +++ b/mc-get.py @@ -6,7 +6,6 @@ import os import mcgetdb from colorama import Fore, Style -db = mcgetdb.McGetDB(mcfs.mc_dir) def validate(): raise NotImplementedError @@ -92,7 +91,8 @@ def install(projects: list, version, loader): else: unavailable.append(project_data) if to_install: - print("To install:", *[project.title + " " + version.version_number for project, version in to_install], sep="\n\t") + print("To install:", *[project.title + " " + version.version_number for project, version in to_install], + sep="\n\t") if dependencies_to_install: print("With dependencies:", *[project.title + " " + version.version_number for project, version in dependencies_to_install], @@ -159,37 +159,55 @@ def clean(): if __name__ == "__main__": + def exit(): + import sys + sys.exit("MC installation not found. If the program is not installed in the default location, " + "then specify the path to the installation through the MC_DIR environment variable.") + + if not mcfs.is_path_exist(mcfs.mc_dir): + exit() + + db = mcgetdb.McGetDB(mcfs.mc_dir) + + def __select_version(versions): - if len(versions) > 0: - print("Installed MC versions: ") - for id, version in enumerate(versions): - print(id + 1, version.version_number + (f" with {version.modloader}" if version.is_modified else ""), - sep=": ") - if len(versions) > 1: - id_to_use = -1 - while id_to_use not in range(1, len(versions)): - id_input = input(f"Select MC version to use [1-{len(versions)}]: ") - if not id_input.isnumeric(): - continue - id_to_use = int(id_input) - else: - id_to_use = 1 - selected_version = versions[id_to_use - 1] - print("Selected MC version:", selected_version.version_number + - (f" with {selected_version.modloader}" if selected_version.is_modified else "")) - return selected_version + if not versions: + return None + print("Installed MC versions: ") + for id, version in enumerate(versions): + print(id + 1, + version.version_number + (f" with {version.modloader}" if version.is_modified else ""), + sep=": ") + if len(versions) > 1: + id_to_use = -1 + while id_to_use not in range(1, len(versions)): + id_input = input(f"Select MC version to use [1-{len(versions)}]: ") + if not id_input.isnumeric(): + continue + id_to_use = int(id_input) + else: + id_to_use = 1 + selected_version = versions[id_to_use - 1] + print("Selected MC version:", selected_version.version_number + + (f" with {selected_version.modloader}" if selected_version.is_modified else "")) + return selected_version properties = db.get_properties() if not properties: version_to_use = __select_version(mcfs.get_installed_mc_versions()) - if version_to_use.is_modified: # TODO: Добавить иерархию каталогов - db.set_properties(version_to_use.version_number, version_to_use.modloader) + if version_to_use: + if version_to_use.is_modified: # TODO: Добавить иерархию каталогов + db.set_properties(version_to_use.version_number, version_to_use.modloader) + else: + db.set_properties(version_to_use.version_number) + properties = db.get_properties() else: - db.set_properties(version_to_use.version_number) - properties = db.get_properties() - print(properties) - _, mc_ver, loader, _ = properties + properties = None + if properties: + _, mc_ver, loader, _ = properties + else: + mc_ver, loader = None, None desc = "Minecraft mods packet manager based on Modrinth API" parser = argparse.ArgumentParser(description=desc, @@ -208,8 +226,9 @@ if __name__ == "__main__": parser_validate = subparsers.add_parser("validate", help="Validate the installation") parser_clean = subparsers.add_parser("clean", help="Clean the cache of this program") - kwargs = vars(parser.parse_args()) # Получаем все поля получившегося Namespace и пихаем в словарь + if not properties: + exit() globals()[kwargs.pop("method")](**kwargs) # Из глобального контекста получаем функцию с названием как в method, # заодно вытаскивая название метода из списка аргументов, # затем вызываем функцию с распакованным словарём в качестве аргумента