-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.py
More file actions
57 lines (49 loc) · 2.6 KB
/
loader.py
File metadata and controls
57 lines (49 loc) · 2.6 KB
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
# -----------------------------------------------------------------------------
# Dynamic Module Loader
# -----------------------------------------------------------------------------
import importlib
from openscada_lite.modules.security.controller import SecurityController
from openscada_lite.modules.security.model import SecurityModel
from openscada_lite.modules.security.service import SecurityService
from openscada_lite.modules.base.base_controller import BaseController
import logging
logger = logging.getLogger(__name__)
async def module_loader(config: dict, socketio_obj, event_bus, app) -> dict:
for module_entry in config.get("modules", []):
if isinstance(module_entry, dict):
module_name = module_entry.get("name", "")
else:
module_name = str(module_entry)
if module_name == "security":
continue # Security module is loaded separately
base_path = f"openscada_lite.modules.{module_name}"
class_prefix = module_name.capitalize()
logger.info(f"[INIT] Loading module: {module_name}")
model_cls = getattr(importlib.import_module(f"{base_path}.model"), f"{class_prefix}Model")
logger.debug(f"[INIT] Model class loaded: {module_name}")
controller_cls = getattr(
importlib.import_module(f"{base_path}.controller"),
f"{class_prefix}Controller",
)
logger.debug(f"[INIT] Controller class loaded: {module_name}")
service_cls = getattr(
importlib.import_module(f"{base_path}.service"), f"{class_prefix}Service"
)
logger.debug(f"[INIT] Service class loaded: {module_name}")
model = model_cls()
logger.debug(f"[INIT] Model initialized: {module_name}")
controller: BaseController = controller_cls(model, socketio_obj, module_name, app)
logger.debug(f"[INIT] Controller initialized: {module_name}")
service = service_cls(event_bus, model, controller)
logger.debug(f"[INIT] Service initialized: {module_name}")
controller.set_service(service)
if hasattr(service, "async_init"):
logger.debug(f"[INIT] async_init: {module_name}")
await service.async_init()
logger.info("[INIT] Loading Security module")
# Security module is always loaded regardless of config
security_model = SecurityModel()
security_controller = SecurityController(security_model, socketio_obj, "security", app)
security_service = SecurityService(event_bus, security_model, security_controller)
security_controller.set_service(security_service)
logger.debug("[INIT] Security module loaded")