generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
120 lines (90 loc) · 4.19 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
import signal
import decky_plugin
import plugin_config
import process_utils
import logger_utils
from rclone_setup_manager import RcloneSetupManager
from rclone_sync_manager import RcloneSyncManager
class Plugin:
manager_setup = RcloneSetupManager()
manager_sync = RcloneSyncManager()
# rclone.conf Setup
async def spawn(self, backend_type: str):
decky_plugin.logger.debug(
"Executing: RcloneSetupManager.spawn(%s)", backend_type)
return await self.manager_setup.spawn(backend_type)
async def spawn_probe(self):
decky_plugin.logger.debug("Executing: RcloneSetupManager.probe()")
return await self.manager_setup.probe()
async def get_backend_type(self):
decky_plugin.logger.debug(
"Executing: RcloneSetupManager.get_backend_type()")
return await self.manager_setup.get_backend_type()
# Sync Paths
async def get_syncpaths(self, file: str):
decky_plugin.logger.debug(
"Executing: RcloneSetupManager.get_syncpaths(%s)", file)
return await self.manager_setup.get_syncpaths(file)
async def test_syncpath(self, path: str):
decky_plugin.logger.debug(
"Executing: RcloneSetupManager.test_syncpath(%s)", path)
return await self.manager_setup.test_syncpath(path)
async def add_syncpath(self, path: str, file: str):
decky_plugin.logger.debug(
"Executing: RcloneSetupManager.add_syncpath(%s, %s)", path, file)
return await self.manager_setup.add_syncpath(path, file)
async def remove_syncpath(self, path: str, file: str):
decky_plugin.logger.debug(
"Executing: RcloneSetupManager.remove_syncpath(%s, %s)", path, file)
return await self.manager_setup.remove_syncpath(path, file)
# Syncing
async def sync_now_internal(self, winner: str, resync: bool):
decky_plugin.logger.info(
"Executing: RcloneSyncManager.sync_now(%s, %b)", winner, resync)
return await self.manager_sync.sync_now(winner, resync)
async def sync_now_probe(self):
decky_plugin.logger.debug("Executing: RcloneSyncManager.probe()")
return await self.manager_sync.probe()
async def delete_lock_files(self):
decky_plugin.logger.debug(
"Executing: RcloneSyncManager.delete_lock_files()")
return await self.manager_sync.delete_lock_files()
# Processes
async def signal(self, pid: int, s: str):
decky_plugin.logger.debug("Executing: send_signal(%s)", pid, s)
if s == "SIGSTOP":
return process_utils.send_signal(pid, signal.SIGSTOP)
elif s == "SIGCONT":
return process_utils.send_signal(pid, signal.SIGCONT)
# Configuration
async def get_log_level(self):
decky_plugin.logger.debug("Executing: get_log_level()")
return decky_plugin.logger.level
async def get_config(self):
decky_plugin.logger.debug("Executing: get_config()")
return plugin_config.get_config()
async def set_config(self, key: str, value: str):
decky_plugin.logger.debug("Executing: set_config(%s, %s)", key, value)
plugin_config.set_config(key, value)
# Logger
async def log(self, level: str, msg: str) -> int:
decky_plugin.logger.debug("Executing: log()")
return logger_utils.log(level, msg)
async def get_last_sync_log(self) -> str:
decky_plugin.logger.debug("Executing: get_last_sync_log()")
return logger_utils.get_last_sync_log()
async def get_plugin_log(self) -> str:
decky_plugin.logger.debug("Executing: get_plugin_log()")
return logger_utils.get_plugin_log()
# Lifecycle
async def _main(self):
logger_level = plugin_config.get_config_item("log_level", "INFO")
decky_plugin.logger.setLevel(logger_level)
decky_plugin.logger.debug(
"rclone exe path: %s", plugin_config.rclone_bin)
decky_plugin.logger.debug(
"rclone cfg path: %s", plugin_config.rclone_cfg)
async def _unload(self):
self.manager_setup.cleanup()
async def _migration(self):
plugin_config.migrate()