Compare commits

...

2 Commits

Author SHA1 Message Date
fc2bc306d0 new mod generation script stable 2022-08-11 02:53:23 +03:00
a932a9434a create mods generation from config 2022-08-10 04:48:48 +03:00

173
main.py
View File

@ -26,35 +26,94 @@ def temp_forge_json():
return data return data
def generate_forge_list(forge_path, download_url): def temp_forge_libs():
forge_jar = scan_forge_folder(forge_path) with open('temp_forge_libs.json') as json_file:
forge_submodules_list = generate_lib_list(os.path.join(forge_path, 'libs'), download_url) data = json.load(json_file)
return data
def generate_forge_list(download_url, forge_version):
# forge_jar = scan_forge_folder(forge_path)
forge_submodules_list = generate_lib_list('none', download_url)
forge_module = [{ forge_module = [{
'id': 'net.minecraftForge:forge:' + forge_jar.split('.')[0], # 'id': 'net.minecraftForge:forge:' + forge_version,
'id': "net.minecraftforge:forge:1.12.2-14.23.5.2847",
'name': 'Minecraft Forge', 'name': 'Minecraft Forge',
'type': 'ForgeHosted', 'type': 'ForgeHosted',
'subModules': forge_submodules_list 'artifact': {
"size": 4884700,
"MD5": "90734a5a713e24902d24c45c15caa42c",
# 'url': download_url + 'forge/' + 'net.minecraftForge:forge:' + forge_version + '.jar',
'url': "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.12.2/forge-1.12.2-14.23.5.2847-universal.jar",
},
'subModules': temp_forge_libs()
}] }]
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 = []
submodules_dict = generate_submodules_dict()
for section in config.sections(): for section in config.sections():
if section.split(' ')[0] == 'Server' or section.split(' ')[0] == 'server': if section.split(' ')[0] == 'Server' or section.split(' ')[0] == 'server':
download_url = config.get(section, 'download_url') download_url = config.get(section, 'download_url')
server_mods_path = os.path.join(config.get(section, 'path'), 'mods') # server_mods_path = os.path.join(config.get(section, 'path'), 'mods')
server_optional_mods_path = config.get(section, 'optional_mods_path') # server_optional_mods_path = config.get(section, 'optional_mods_path')
forge_path = config.get(section, 'forge_reference_folder') # forge_path = config.get(section, 'forge_reference_folder')
forge_version = config.get(section, 'forge_version')
forge_module = generate_forge_list(download_url, forge_version)
forge_required_modules = generate_mod_list(server_mods_path, download_url, True) mods_files_dict = scan_mods_folder(config.get(section, 'minecraftVersion'))
forge_optionals_modules = generate_mod_list(server_optional_mods_path, download_url, False)
forge_libs = generate_forge_list(forge_path, download_url) config_share_mods = config.get(section, 'share_mods').split(' ')
new_server_modules = forge_libs + forge_required_modules + forge_optionals_modules 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, True, mods_files_dict)
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 \
+ 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')),
@ -68,8 +127,6 @@ def parse_servers_config(config: ConfigParser):
'discord_largeImageKey': (config.get(section, 'discord_largeImageKey')), 'discord_largeImageKey': (config.get(section, 'discord_largeImageKey')),
'mainServer': (config.get(section, 'mainServer')), 'mainServer': (config.get(section, 'mainServer')),
'autoconnect': (config.get(section, 'autoconnect')), 'autoconnect': (config.get(section, 'autoconnect')),
'_path': (config.get(section, 'path')),
'_download_url': download_url,
'modules': new_server_modules 'modules': new_server_modules
} }
servers.append(new_server) servers.append(new_server)
@ -89,57 +146,63 @@ def list_files_in_folder(path):
return f return f
def generate_mod_list(mods_path, download_url, isRequired): def get_name_in_dict(mod):
mods_file_list = list_files_in_folder(os.path.join(mods_path)) try:
human_mod_name = config.get('Mods Names', mod)
except:
print('Not find human name for: ' + mod)
return mod
return human_mod_name
def check_for_submodule(param):
return False
def generate_submodules_dict():
mods_with_submodules = config.items('Mods Submodules')
submodules_dict = {}
for mod in mods_with_submodules:
for submodule in mod[1].split(' '):
submodules_dict[submodule] = mod[0]
return submodules_dict
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 = [] mod_list = []
# mod_list.append(temp_forge_json()) for mod in mods_config_list:
for mod in mods_file_list: # path_to_mod = os.path.join(mods_path, mod)
path_to_mod = os.path.join(mods_path, mod) parsed_mod = mod.split(':')
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('-', ' ')
if parsed_mod[-1] is not None:
if parsed_mod[-1] == 'ServerSide':
continue
new_mod = { new_mod = {
'id': mod_id, 'id': mod,
'name': parsed_mod[1], 'name': get_name_in_dict(parsed_mod[1]),
'type': 'ForgeMod', 'type': 'ForgeMod',
'required': isRequired, 'artifact': {'size': mods_files_dict[mod + '.jar'].get('size'),
'artifact': {'size': sys.getsizeof(path_to_mod), 'MD5': mods_files_dict[mod + '.jar'].get('MD5'),
'MD5': calculate_md5(path_to_mod), 'url': download_url + 'mods/' + mod + '.jar'
'url': download_url + mod + '.jar'
} }
} }
if is_required is not True:
new_mod['required'] = {
'value': is_required,
'def': is_enabled
}
mod_list.append(new_mod) mod_list.append(new_mod)
# try:
# master_mod = submodules_dict.get(parsed_mod[1])
# kek = list(filter(lambda master_mod_dict: master_mod_dict['name'] == master_mod, mod_list))
# pprint(kek)
# except:
# pass
return mod_list return mod_list
def generate_lib_list(libs_path, download_url): def generate_lib_list(libs_path, download_url):
libs_file_list = list_files_in_folder(os.path.join(libs_path))
lib_list = [] 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 return lib_list
@ -165,7 +228,7 @@ if __name__ == '__main__':
config = read_config(sys.argv[1]) config = read_config(sys.argv[1])
distribution = generate_json(config) distribution = generate_json(config)
pprint(distribution) # pprint(distribution)
with open('distribution.json', 'w', encoding='utf-8') as f: with open('distribution.json', 'w', encoding='utf-8') as f:
json.dump(distribution, f, ensure_ascii=False, indent=4) json.dump(distribution, f, ensure_ascii=False, indent=4)