-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
85 lines (70 loc) · 3.33 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
import os
import subprocess
import re
import json
from glob import glob
import decky_plugin
def log(txt):
decky_plugin.logger.info(txt)
def warn(txt):
decky_plugin.logger.warn(txt)
def error(txt):
decky_plugin.logger.error(txt)
confdir = os.environ["DECKY_PLUGIN_SETTINGS_DIR"]
if os.name == 'nt':
appdata_roaming_path = os.getenv('APPDATA')
class Plugin:
@staticmethod
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, 'AppData', 'Roaming', '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().strip('"')
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 {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 emudeck(self, command):
if os.name == 'nt':
ps1_file = os.path.join(os.environ['APPDATA'], 'EmuDeck', 'backend', 'functions', 'all.ps1')
bash_command = fr'PowerShell -ExecutionPolicy Bypass -Command "& {{. \"{ps1_file}\"; {command}}}"'
else:
bash_command = f". $HOME/.config/EmuDeck/backend/functions/all.sh && {command}"
result = subprocess.run(bash_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
cleaned_stdout = result.stdout.strip()
user_home = os.path.expanduser("~")
emudeck_log_dir = os.path.join(user_home, '.config/EmuDeck/logs')
if os.name == 'nt':
emudeck_log_dir = os.path.join(os.environ['APPDATA'], 'EmuDeck', 'logs')
os.makedirs(emudeck_log_dir, exist_ok=True)
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