generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
124 lines (103 loc) · 5.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import subprocess
import re
import json
from glob import glob
import decky_plugin
# Directorio de configuración del plugin
confdir = os.environ["DECKY_PLUGIN_SETTINGS_DIR"]
if os.name == 'nt':
appdata_roaming_path = os.getenv('APPDATA')
class Plugin:
async def emudeck(self, command):
# Determinar el comando según el sistema operativo
if os.name == 'nt':
# Obtener la ruta completa del script .ps1 usando Python
ps1_file = os.path.join(os.environ['APPDATA'], 'EmuDeck', 'backend', 'functions', 'all.ps1')
# Construir el comando de PowerShell con la ruta absoluta
bash_command = fr'PowerShell -ExecutionPolicy Bypass -Command "& {{. \"{ps1_file}\"; {command}}}"'
else:
# Para sistemas basados en Unix
bash_command = f". $HOME/.config/EmuDeck/backend/functions/all.sh && {command}"
# Ejecutar el comando
result = subprocess.run(bash_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Limpiar la salida estándar (stdout)
cleaned_stdout = result.stdout.strip()
# Obtener la ruta al directorio del usuario y crear la carpeta "emudeck" si no existe
user_home = os.path.expanduser("~")
emudeck_log_dir = os.path.join(user_home, 'emudeck')
os.makedirs(emudeck_log_dir, exist_ok=True)
# Escribir el resultado en un archivo de log
log_file_path = os.path.join(emudeck_log_dir, 'decky.log')
with open(log_file_path, 'w') as archivo:
archivo.write("STDOUT:\n")
archivo.write(result.stdout)
archivo.write("\n\nSTDERR:\n")
archivo.write(result.stderr)
return cleaned_stdout
async def emudeck_dirty(self, command):
if os.name == 'nt':
bash_command = f". {appdata_roaming_path}/EmuDeck/backend/functions/all.ps1 && " + command
else:
bash_command = ". $HOME/.config/EmuDeck/backend/functions/all.sh && " + command
result = subprocess.run(bash_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout
# START QL
async def get_id(self):
with open(os.path.join(confdir, "scid.txt"), "r") as sc:
id = sc.read()
try:
id = int(id)
return id
except ValueError:
return -1
async def set_id(self, id):
with open(os.path.join(confdir, "scid.txt"), "w") as sc:
sc.write(str(id))
# END QL
async def getSettings(self):
pattern = re.compile(r'([A-Za-z_][A-Za-z0-9_]*)=(.*)')
user_home = os.path.expanduser("~")
if os.name == 'nt':
config_file_path = os.path.join(user_home, 'emudeck', 'settings.ps1')
else:
config_file_path = os.path.join(user_home, 'emudeck', 'settings.sh')
configuration = {}
with open(config_file_path, 'r') as file:
for line in file:
match = pattern.search(line)
if match:
variable = match.group(1)
value = match.group(2).strip('"')
configuration[variable] = value
if os.name == 'nt':
bash_command = f"cd {appdata_roaming_path}/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()
configuration["systemOS"] = os.name
json_configuration = json.dumps(configuration, indent=4)
return json_configuration
async def _main(self):
if os.name == 'nt':
bash_command = f"cd {appdata_roaming_path}/EmuDeck/backend/ && git reset --hard && git pull && . {appdata_roaming_path}/EmuDeck/backend/functions/all.ps1 && generateGameLists"
else:
bash_command = "cd $HOME/.config/EmuDeck/backend/ && git reset --hard && git pull && . $HOME/.config/EmuDeck/backend/functions/all.sh && generateGameLists"
result = subprocess.run(bash_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
try:
sc = open(os.path.join(confdir, "scid.txt"), "x")
sc.close()
except FileExistsError:
pass
async def _unload(self):
pass
async def _migration(self):
decky_plugin.migrate_logs(os.path.join(decky_plugin.DECKY_USER_HOME,
".config", "decky-template", "template.log"))
decky_plugin.migrate_settings(
os.path.join(decky_plugin.DECKY_HOME, "settings", "template.json"),
os.path.join(decky_plugin.DECKY_USER_HOME, ".config", "decky-template"))
decky_plugin.migrate_runtime(
os.path.join(decky_plugin.DECKY_HOME, "template"),
os.path.join(decky_plugin.DECKY_USER_HOME, ".local", "share", "decky-template"))