mirror of
https://github.com/dragoonDorise/EmuDeck.git
synced 2025-05-05 16:02:48 +00:00
Quick refactor of python tools modules (#1456)
This commit is contained in:
parent
251a3974cf
commit
f252f9bb46
@ -8,9 +8,9 @@ import subprocess
|
||||
import hashlib
|
||||
|
||||
from vars import home_dir, msg_file
|
||||
from utils import getSettings, log_message
|
||||
from utils import get_settings, log_message
|
||||
|
||||
settings = getSettings()
|
||||
settings = get_settings()
|
||||
storage_path = os.path.expandvars(settings["storagePath"])
|
||||
|
||||
# Path for the JSON and target folder from command-line arguments
|
||||
|
@ -1,17 +1,16 @@
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
import requests
|
||||
import zipfile
|
||||
from io import BytesIO
|
||||
import sys
|
||||
import re
|
||||
from vars import home_dir, msg_file
|
||||
from utils import getSettings, log_message
|
||||
from utils import get_settings, log_message
|
||||
|
||||
settings = getSettings()
|
||||
|
||||
settings = get_settings()
|
||||
storage_path = os.path.expandvars(settings["storagePath"])
|
||||
|
||||
|
||||
def download_and_extract(output_dir):
|
||||
# Fixed path to the JSON file
|
||||
json_file_path = os.path.join(storage_path, "retrolibrary/cache/missing_systems.json")
|
||||
|
@ -1,12 +1,11 @@
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
import re
|
||||
import subprocess
|
||||
from vars import home_dir, msg_file, excluded_systems
|
||||
from utils import getSettings, log_message, clean_name, collect_game_data, get_valid_system_dirs, parse_metadata_file
|
||||
from vars import excluded_systems
|
||||
from utils import get_settings, log_message, clean_name, collect_game_data, get_valid_system_dirs, parse_metadata_file
|
||||
|
||||
settings = getSettings()
|
||||
|
||||
settings = get_settings()
|
||||
storage_path = os.path.expandvars(settings["storagePath"])
|
||||
saves_path = os.path.expandvars(settings["savesPath"])
|
||||
|
||||
|
@ -1,14 +1,11 @@
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
import re
|
||||
import subprocess
|
||||
import hashlib
|
||||
from vars import excluded_systems
|
||||
from utils import get_settings, log_message, collect_game_data, get_valid_system_dirs, parse_metadata_file
|
||||
|
||||
from vars import home_dir, msg_file, excluded_systems
|
||||
from utils import getSettings, log_message, clean_name, collect_game_data, get_valid_system_dirs, parse_metadata_file
|
||||
|
||||
settings = getSettings()
|
||||
settings = get_settings()
|
||||
storage_path = os.path.expandvars(settings["storagePath"])
|
||||
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
import re
|
||||
import subprocess
|
||||
from vars import excluded_systems
|
||||
from utils import get_settings, log_message, get_valid_system_dirs
|
||||
|
||||
from vars import home_dir, msg_file, excluded_systems
|
||||
from utils import getSettings, log_message, get_valid_system_dirs
|
||||
|
||||
settings = getSettings()
|
||||
settings = get_settings()
|
||||
storage_path = os.path.expandvars(settings["storagePath"])
|
||||
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from vars import home_dir, msg_file
|
||||
from vars import msg_file
|
||||
|
||||
def getSettings():
|
||||
|
||||
def get_settings():
|
||||
pattern = re.compile(r'([A-Za-z_][A-Za-z0-9_]*)=(.*)')
|
||||
user_home = os.path.expanduser("~")
|
||||
|
||||
bash_command = "cd $HOME/.config/EmuDeck/backend/ && git rev-parse --abbrev-ref HEAD"
|
||||
config_file_path = os.path.join(user_home, '.config', 'EmuDeck',
|
||||
'settings.sh')
|
||||
if os.name == 'nt':
|
||||
bash_command = f"cd {os.path.join(user_home, 'AppData', 'Roaming', 'EmuDeck', 'backend')} && git rev-parse --abbrev-ref HEAD"
|
||||
config_file_path = os.path.join(user_home, 'AppData', 'Roaming', 'EmuDeck', 'settings.ps1')
|
||||
else:
|
||||
config_file_path = os.path.join(user_home, '.config' , 'EmuDeck', 'settings.sh')
|
||||
|
||||
configuration = {}
|
||||
|
||||
@ -23,12 +25,6 @@ def getSettings():
|
||||
expanded_value = os.path.expandvars(value.replace('"', '').replace("'", ""))
|
||||
configuration[variable] = expanded_value
|
||||
|
||||
# Obtener rama actual del repositorio backend
|
||||
if os.name == 'nt':
|
||||
bash_command = f"cd {os.path.join(user_home, 'AppData', 'Roaming', 'EmuDeck', 'backend')} && git rev-parse --abbrev-ref HEAD"
|
||||
else:
|
||||
bash_command = "cd $HOME/.config/EmuDeck/backend/ && git rev-parse --abbrev-ref HEAD"
|
||||
|
||||
result = subprocess.run(bash_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
configuration["branch"] = result.stdout.strip()
|
||||
|
||||
@ -36,21 +32,23 @@ def getSettings():
|
||||
|
||||
return configuration
|
||||
|
||||
|
||||
def log_message(message):
|
||||
with open(msg_file, "w") as log_file: # "a" to append messages without overwriting
|
||||
log_file.write(message + "\n")
|
||||
|
||||
|
||||
def clean_name(name):
|
||||
name_cleaned = re.sub(r'\(.*?\)', '', name)
|
||||
name_cleaned = re.sub(r'\[.*?\]', '', name_cleaned)
|
||||
name_cleaned = name_cleaned.strip().replace(' ', '_').replace('-', '_')
|
||||
name_cleaned = re.sub(r'_+', '_', name_cleaned)
|
||||
name_cleaned = name_cleaned.replace('+', '').replace('&', '').replace('!', '').replace("'", '').replace('.', '').replace('_decrypted','').replace('decrypted','').replace('.ps3', '')
|
||||
name_cleaned_pegasus = name.replace(',_', ',')
|
||||
name_cleaned = name_cleaned.replace('+', '').replace('&', '').replace('!', '').replace("'", '').replace('.', '').replace('_decrypted', '').replace('decrypted', '').replace('.ps3', '')
|
||||
name_cleaned = name_cleaned.lower()
|
||||
return name_cleaned
|
||||
|
||||
def collect_game_data(system_dir, extensions, images_path = None):
|
||||
|
||||
def collect_game_data(system_dir, extensions, images_path=None):
|
||||
game_data = []
|
||||
|
||||
#PS3
|
||||
@ -169,9 +167,6 @@ def collect_game_data(system_dir, extensions, images_path = None):
|
||||
"filename": file_path
|
||||
}
|
||||
game_data.append(game_info)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
game_info = {
|
||||
"name": name_cleaned,
|
||||
@ -212,6 +207,7 @@ def get_valid_system_dirs(roms_dir, valid_system_dirs):
|
||||
log_message(f"GGL: Valid system directory found: {full_path}")
|
||||
return valid_system_dirs
|
||||
|
||||
|
||||
def parse_metadata_file(metadata_path):
|
||||
if not os.path.exists(metadata_path):
|
||||
raise FileNotFoundError(f"Metadata file not found: {metadata_path}")
|
||||
|
@ -1,9 +1,10 @@
|
||||
import os
|
||||
|
||||
home_dir = os.environ.get("HOME")
|
||||
msg_file = os.path.join(home_dir, ".config/EmuDeck/logs/msg.log")
|
||||
|
||||
if os.name == 'nt':
|
||||
home_dir = os.environ.get("USERPROFILE")
|
||||
msg_file = os.path.join(home_dir, 'AppData', 'Roaming', 'EmuDeck', 'logs/msg.log')
|
||||
else:
|
||||
home_dir = os.environ.get("HOME")
|
||||
msg_file = os.path.join(home_dir, ".config/EmuDeck/logs/msg.log")
|
||||
|
||||
excluded_systems = ["/model2", "/genesiswide", "/mame", "/emulators", "/desktop", "/sneswide"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user