From fc2bc306d037c91587a335396a180a2fd24f0f83 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Thu, 11 Aug 2022 02:53:23 +0300 Subject: [PATCH] new mod generation script stable --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index b78a696..209f96b 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,30 @@ def generate_forge_list(download_url, forge_version): return forge_module +def scan_mods_folder(minecraft_version): + mods_files_dict = {} + + path = os.path.join(config.get('Basic', 'modules_' + minecraft_version), 'mods') + + mods_files = list_files_in_folder(path) + for mod_file in mods_files: + mod_file_path = os.path.join(path, mod_file) + new_mod = { + 'MD5': calculate_md5(mod_file_path), + 'size': os.stat(mod_file_path).st_size + } + mods_files_dict[mod_file] = new_mod + print(mods_files_dict) + + return mods_files_dict + + +def temp_files_json(): + with open('temp_files.json') as json_file: + data = json.load(json_file) + return [data] + + def parse_servers_config(config: ConfigParser): servers = [] @@ -66,20 +90,30 @@ def parse_servers_config(config: ConfigParser): forge_version = config.get(section, 'forge_version') forge_module = generate_forge_list(download_url, forge_version) + mods_files_dict = scan_mods_folder(config.get(section, 'minecraftVersion')) + config_share_mods = config.get(section, 'share_mods').split(' ') - forge_share_modules = generate_mod_list(config_share_mods, download_url, submodules_dict, True) + forge_share_modules = generate_mod_list(config_share_mods, download_url, submodules_dict, True, True, mods_files_dict) config_client_mods = config.get(section, 'client_mods').split(' ') - forge_client_modules = generate_mod_list(config_client_mods, download_url, submodules_dict, True) + forge_client_modules = generate_mod_list(config_client_mods, download_url, submodules_dict, True, True, mods_files_dict) - config_client_optional_mods = config.get(section, 'client_optional_mods').split(' ') - forge_client_optional_modules = generate_mod_list(config_client_optional_mods, download_url, - submodules_dict, False) + config_client_optional_enabled_mods = config.get(section, 'client_optional_enabled_mods').split(' ') + forge_client_optional_enabled_modules = generate_mod_list(config_client_optional_enabled_mods, download_url, + submodules_dict, False, True, mods_files_dict) + config_client_optional_disabled_mods = config.get(section, 'client_optional_disabled_mods').split(' ') + forge_client_optional_disabled_modules = generate_mod_list(config_client_optional_disabled_mods, download_url, + submodules_dict, False, False, mods_files_dict) + forge_client_optional_modules = forge_client_optional_enabled_modules + forge_client_optional_disabled_modules + + temp_files = temp_files_json() + new_server_modules = forge_module \ + forge_share_modules \ - # + forge_client_modules \ - # + forge_client_optional_modules + + forge_client_modules \ + + forge_client_optional_modules \ + + temp_files new_server = {'id': (config.get(section, 'id')), 'name': (config.get(section, 'name')), @@ -134,7 +168,7 @@ def generate_submodules_dict(): return submodules_dict -def generate_mod_list(mods_config_list, download_url, submodules_dict, is_required): +def generate_mod_list(mods_config_list, download_url, submodules_dict, is_required, is_enabled, mods_files_dict): # mods_file_list = list_files_in_folder(os.path.join(mods_path)) mod_list = [] @@ -145,13 +179,17 @@ def generate_mod_list(mods_config_list, download_url, submodules_dict, is_requir 'id': mod, 'name': get_name_in_dict(parsed_mod[1]), 'type': 'ForgeMod', - 'artifact': {'size': 228, # sys.getsizeof(path_to_mod), - 'MD5': '228', # calculate_md5(path_to_mod), + 'artifact': {'size': mods_files_dict[mod + '.jar'].get('size'), + 'MD5': mods_files_dict[mod + '.jar'].get('MD5'), 'url': download_url + 'mods/' + mod + '.jar' } } if is_required is not True: - new_mod['required'] = {'value': is_required}, + new_mod['required'] = { + 'value': is_required, + 'def': is_enabled + } + mod_list.append(new_mod) # try: