diff --git a/main.py b/main.py index 57847e9..02f51d4 100644 --- a/main.py +++ b/main.py @@ -26,10 +26,36 @@ def temp_forge_json(): return data +def generate_forge_list(forge_path, download_url): + forge_jar = scan_forge_folder(forge_path) + forge_submodules_list = generate_lib_list(os.path.join(forge_path, 'libs'), download_url) + forge_module = [{ + 'id': 'net.minecraftForge:forge:' + forge_jar.split('.')[0], + 'name': 'Minecraft Forge', + 'type': 'ForgeHosted', + 'subModules': forge_submodules_list + }] + return (forge_module) + + + + def parse_servers_config(config: ConfigParser): servers = [] + for section in config.sections(): if section.split(' ')[0] == 'Server' or section.split(' ')[0] == 'server': + download_url = config.get(section, 'download_url') + server_mods_path = os.path.join(config.get(section, 'path'), 'mods') + server_optional_mods_path = config.get(section, 'optional_mods_path') + forge_path = config.get(section, 'forge_reference_folder') + + + forge_required_modules = generate_mod_list(server_mods_path, download_url, True) + forge_optionals_modules = generate_mod_list(server_optional_mods_path, download_url, False) + forge_libs = generate_forge_list(forge_path, download_url) + new_server_modules = forge_libs + forge_required_modules + forge_optionals_modules + new_server = {'id': (config.get(section, 'id')), 'name': (config.get(section, 'name')), 'description': (config.get(section, 'description')), @@ -43,14 +69,19 @@ def parse_servers_config(config: ConfigParser): 'mainServer': (config.get(section, 'mainServer')), 'autoconnect': (config.get(section, 'autoconnect')), '_path': (config.get(section, 'path')), - '_download_url': (config.get(section, 'download_url')), - 'modules': generate_mod_list(config.get(section, 'path'), - config.get(section, 'download_url'))} + '_download_url': download_url, + 'modules': new_server_modules + } servers.append(new_server) return servers -def scan_mods(path): +def scan_forge_folder(forge_path): + forge_jar = list_files_in_folder(forge_path)[0] + return forge_jar + + +def list_files_in_folder(path): f = [] for (dirpath, dirnames, filenames) in os.walk(path): f.extend(filenames) @@ -58,30 +89,27 @@ def scan_mods(path): return f -def generate_mod_list(server_path, download_url): - mods_file_list = scan_mods(os.path.join(server_path, 'mods')) +def generate_mod_list(mods_path, download_url, isRequired): + mods_file_list = list_files_in_folder(os.path.join(mods_path)) mod_list = [] - mod_list.append(temp_forge_json()) + # mod_list.append(temp_forge_json()) for mod in mods_file_list: - path_to_mod = os.path.join(server_path, 'mods', mod) + path_to_mod = os.path.join(mods_path, mod) mod = mod[:-4] parsed_mod = mod.split('_') mod_id = parsed_mod[0] parsed_mod[0] = parsed_mod[0].split(':') parsed_mod[1] = parsed_mod[1].replace('-', ' ') - is_mod_required = True if parsed_mod[-1] is not None: if parsed_mod[-1] == 'ServerSide': continue - if parsed_mod[-1] == 'Optional': - is_mod_required = False new_mod = { 'id': mod_id, 'name': parsed_mod[1], 'type': 'ForgeMod', - 'required': is_mod_required, + 'required': isRequired, 'artifact': {'size': sys.getsizeof(path_to_mod), 'MD5': calculate_md5(path_to_mod), 'url': download_url + mod + '.jar' @@ -91,6 +119,30 @@ def generate_mod_list(server_path, download_url): return mod_list +def generate_lib_list(libs_path, download_url): + libs_file_list = list_files_in_folder(os.path.join(libs_path)) + lib_list = [] + for lib in libs_file_list: + path_to_lib = os.path.join(libs_path, lib) + parsed_lib = lib.split(':') + lib_id = parsed_lib[1] + + if lib.split('.')[-1] == 'xz': + lib_id += "@jar.pack.xz" + + new_lib = { + 'id': lib_id, + 'name': parsed_lib[1], + 'type': 'Library', + 'artifact': {'size': sys.getsizeof(path_to_lib), + 'MD5': calculate_md5(path_to_lib), + 'url': download_url + lib + } + } + lib_list.append(new_lib) + return lib_list + + def generate_json(config: ConfigParser): new_distribution = { 'version': (config.get('Basic', 'version')),