new mod generation script stable

This commit is contained in:
cyber-dream 2022-08-11 02:53:23 +03:00
parent a932a9434a
commit fc2bc306d0

60
main.py
View File

@ -51,6 +51,30 @@ def generate_forge_list(download_url, forge_version):
return forge_module 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): def parse_servers_config(config: ConfigParser):
servers = [] servers = []
@ -66,20 +90,30 @@ def parse_servers_config(config: ConfigParser):
forge_version = config.get(section, 'forge_version') forge_version = config.get(section, 'forge_version')
forge_module = generate_forge_list(download_url, 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(' ') 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(' ') 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(' ') config_client_optional_enabled_mods = config.get(section, 'client_optional_enabled_mods').split(' ')
forge_client_optional_modules = generate_mod_list(config_client_optional_mods, download_url, forge_client_optional_enabled_modules = generate_mod_list(config_client_optional_enabled_mods, download_url,
submodules_dict, False) 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 \ new_server_modules = forge_module \
+ forge_share_modules \ + forge_share_modules \
# + forge_client_modules \ + forge_client_modules \
# + forge_client_optional_modules + forge_client_optional_modules \
+ temp_files
new_server = {'id': (config.get(section, 'id')), new_server = {'id': (config.get(section, 'id')),
'name': (config.get(section, 'name')), 'name': (config.get(section, 'name')),
@ -134,7 +168,7 @@ def generate_submodules_dict():
return 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)) # mods_file_list = list_files_in_folder(os.path.join(mods_path))
mod_list = [] mod_list = []
@ -145,13 +179,17 @@ def generate_mod_list(mods_config_list, download_url, submodules_dict, is_requir
'id': mod, 'id': mod,
'name': get_name_in_dict(parsed_mod[1]), 'name': get_name_in_dict(parsed_mod[1]),
'type': 'ForgeMod', 'type': 'ForgeMod',
'artifact': {'size': 228, # sys.getsizeof(path_to_mod), 'artifact': {'size': mods_files_dict[mod + '.jar'].get('size'),
'MD5': '228', # calculate_md5(path_to_mod), 'MD5': mods_files_dict[mod + '.jar'].get('MD5'),
'url': download_url + 'mods/' + mod + '.jar' 'url': download_url + 'mods/' + mod + '.jar'
} }
} }
if is_required is not True: 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) mod_list.append(new_mod)
# try: # try: