-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtime_capsule.py
69 lines (60 loc) · 2.45 KB
/
time_capsule.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
import logging
from modules.database_manager import DatabaseManager
from modules.plugin_manager import PluginManager
from modules.config_manager import config
import threading
class TimeCapsule:
def __init__(self):
# Initialize core components
self.db_manager = None
self.plugin_manager = PluginManager()
self.running = False
self.stop_event = threading.Event()
def initialize(self):
"""Initialize the TimeCapsule components."""
logging.info("Initializing Time Capsule...")
self.db_manager = DatabaseManager(config.get_database_path())
def start(self):
"""Start the TimeCapsule and its plugins."""
if self.running:
logging.warning("Time Capsule is already running")
return False
self.stop_event.clear()
enabled_plugins = self.plugin_manager.get_enabled_plugins()
for plugin_name, plugin_instance in enabled_plugins.items():
try:
plugin_instance.start(db_manager=self.db_manager)
logging.debug(f"Started plugin: {plugin_name}")
except Exception as e:
logging.error(f"Error starting plugin {plugin_name}: {e}")
self.running = True
logging.info("Time Capsule started.")
return True
def stop(self):
"""Stop the TimeCapsule and its plugins."""
if not self.running:
logging.warning("Time Capsule is not running")
return False
self.stop_event.set()
enabled_plugins = self.plugin_manager.get_enabled_plugins()
for plugin_name, plugin_instance in enabled_plugins.items():
try:
plugin_instance.stop()
logging.debug(f"Stopped plugin: {plugin_name}")
except Exception as e:
logging.error(f"Error stopping plugin {plugin_name}: {e}")
self.running = False
logging.info("Time Capsule stopped.")
return True
def get_plugins(self):
"""Get the list of available plugins."""
return self.plugin_manager.get_plugins()
def toggle_plugin(self, plugin_name):
"""Toggle the enabled state of a plugin."""
return self.plugin_manager.toggle_plugin(plugin_name)
def get_status(self):
"""Get the current status of the TimeCapsule and its plugins."""
return {
'running': self.running,
'plugins': self.plugin_manager.get_plugin_statuses(),
}