Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load either user or admin #24

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions ovos_PHAL/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ class AdminPHAL(PHAL):
def __init__(self, config=None, bus=None, on_ready=on_admin_ready, on_error=on_admin_error,
on_stopping=on_admin_stopping, on_started=on_admin_started, on_alive=on_admin_alive,
watchdog=lambda: None, name="PHAL.admin", **kwargs):
if not config:
try:
config = Configuration()
config = config.get("PHAL", {}).get("admin", {})
except:
config = {}
if config and "admin" not in config:
config = {"admin": config}
super().__init__(config, bus, on_ready, on_error, on_stopping, on_started, on_alive, watchdog, name, **kwargs)

def load_plugins(self):
for name, plug in find_admin_plugins().items():
config = self.config.get(name) or {}
# load the plugin only if not defined as user plugin
# (for plugins that can be used as admin or user plugins)
if name in self.user_config:
LOG.debug(f"PHAL plugin {name} runs as user plugin, skipping")
continue

config = self.admin_config.get(name) or {}
enabled = config.get("enabled")
if not enabled:
continue # require explicit enabling by user
Expand Down
14 changes: 12 additions & 2 deletions ovos_PHAL/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ def __init__(self, config=None, bus=None,
on_started=started_hook)
self.status = ProcessStatus("PHAL", callback_map=callbacks)
self._watchdog = watchdog # TODO implement
self.config = config or Configuration().get("PHAL") or {}
self.user_config = config or Configuration().get("PHAL") or {}
if "admin" in self.user_config:
self.admin_config = self.user_config.pop("admin")
else:
self.admin_config = {}
self.drivers = {}
self.status.bind(self.bus)

def load_plugins(self):
for name, plug in find_phal_plugins().items():
config = self.config.get(name) or {}
# load the plugin only if not defined as admin plugin
# (for plugins that can be used as admin or user plugins)
if name in self.admin_config:
LOG.debug(f"PHAL plugin {name} runs as admin plugin, skipping")
continue

config = self.user_config.get(name) or {}
if hasattr(plug, "validator"):
enabled = plug.validator.validate(config)
else:
Expand Down
Loading