add forge libs generation and optional mods generations
This commit is contained in:
parent
a91fb0e098
commit
f89bf9cab0
76
main.py
76
main.py
@ -26,10 +26,36 @@ def temp_forge_json():
|
|||||||
return data
|
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):
|
def parse_servers_config(config: ConfigParser):
|
||||||
servers = []
|
servers = []
|
||||||
|
|
||||||
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')
|
||||||
|
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')),
|
new_server = {'id': (config.get(section, 'id')),
|
||||||
'name': (config.get(section, 'name')),
|
'name': (config.get(section, 'name')),
|
||||||
'description': (config.get(section, 'description')),
|
'description': (config.get(section, 'description')),
|
||||||
@ -43,14 +69,19 @@ def parse_servers_config(config: ConfigParser):
|
|||||||
'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')),
|
'_path': (config.get(section, 'path')),
|
||||||
'_download_url': (config.get(section, 'download_url')),
|
'_download_url': download_url,
|
||||||
'modules': generate_mod_list(config.get(section, 'path'),
|
'modules': new_server_modules
|
||||||
config.get(section, 'download_url'))}
|
}
|
||||||
servers.append(new_server)
|
servers.append(new_server)
|
||||||
return servers
|
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 = []
|
f = []
|
||||||
for (dirpath, dirnames, filenames) in os.walk(path):
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
f.extend(filenames)
|
f.extend(filenames)
|
||||||
@ -58,30 +89,27 @@ def scan_mods(path):
|
|||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
def generate_mod_list(server_path, download_url):
|
def generate_mod_list(mods_path, download_url, isRequired):
|
||||||
mods_file_list = scan_mods(os.path.join(server_path, 'mods'))
|
mods_file_list = list_files_in_folder(os.path.join(mods_path))
|
||||||
|
|
||||||
mod_list = []
|
mod_list = []
|
||||||
mod_list.append(temp_forge_json())
|
# mod_list.append(temp_forge_json())
|
||||||
for mod in mods_file_list:
|
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]
|
mod = mod[:-4]
|
||||||
parsed_mod = mod.split('_')
|
parsed_mod = mod.split('_')
|
||||||
mod_id = parsed_mod[0]
|
mod_id = parsed_mod[0]
|
||||||
parsed_mod[0] = parsed_mod[0].split(':')
|
parsed_mod[0] = parsed_mod[0].split(':')
|
||||||
parsed_mod[1] = parsed_mod[1].replace('-', ' ')
|
parsed_mod[1] = parsed_mod[1].replace('-', ' ')
|
||||||
|
|
||||||
is_mod_required = True
|
|
||||||
if parsed_mod[-1] is not None:
|
if parsed_mod[-1] is not None:
|
||||||
if parsed_mod[-1] == 'ServerSide':
|
if parsed_mod[-1] == 'ServerSide':
|
||||||
continue
|
continue
|
||||||
if parsed_mod[-1] == 'Optional':
|
|
||||||
is_mod_required = False
|
|
||||||
new_mod = {
|
new_mod = {
|
||||||
'id': mod_id,
|
'id': mod_id,
|
||||||
'name': parsed_mod[1],
|
'name': parsed_mod[1],
|
||||||
'type': 'ForgeMod',
|
'type': 'ForgeMod',
|
||||||
'required': is_mod_required,
|
'required': isRequired,
|
||||||
'artifact': {'size': sys.getsizeof(path_to_mod),
|
'artifact': {'size': sys.getsizeof(path_to_mod),
|
||||||
'MD5': calculate_md5(path_to_mod),
|
'MD5': calculate_md5(path_to_mod),
|
||||||
'url': download_url + mod + '.jar'
|
'url': download_url + mod + '.jar'
|
||||||
@ -91,6 +119,30 @@ def generate_mod_list(server_path, download_url):
|
|||||||
return mod_list
|
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):
|
def generate_json(config: ConfigParser):
|
||||||
new_distribution = {
|
new_distribution = {
|
||||||
'version': (config.get('Basic', 'version')),
|
'version': (config.get('Basic', 'version')),
|
||||||
|
Loading…
Reference in New Issue
Block a user