Skip to content

Commit

Permalink
feat: status events
Browse files Browse the repository at this point in the history
split feedback events to allow GUI integration via systemdhooks
  • Loading branch information
JarbasAl committed Dec 3, 2024
1 parent 5b1bea6 commit 636b015
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions ovos_PHAL_plugin_system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ def __init__(self, bus=None, config=None):
self.bus.on("system.ssh.status", self.handle_ssh_status)
self.bus.on("system.ssh.enable", self.handle_ssh_enable_request)
self.bus.on("system.ssh.disable", self.handle_ssh_disable_request)
self.bus.on("system.ssh.enabled", self.handle_ssh_enabled)
self.bus.on("system.ssh.disabled", self.handle_ssh_disabled)
self.bus.on("system.reboot", self.handle_reboot_request)
self.bus.on("system.reboot.start", self.handle_rebooting)
self.bus.on("system.shutdown", self.handle_shutdown_request)
self.bus.on("system.shutdown.start", self.handle_shutting_down)
self.bus.on("system.factory.reset", self.handle_factory_reset_request)
self.bus.on("system.factory.reset.register", self.handle_reset_register)
self.bus.on("system.configure.language",
self.handle_configure_language_request)
self.bus.on("system.mycroft.service.restart",
self.handle_mycroft_restart_request)
self.bus.on("system.configure.language", self.handle_configure_language_request)
self.bus.on("system.mycroft.service.restart", self.handle_mycroft_restart_request)
self.bus.on("system.mycroft.service.restart.start", self.handle_mycroft_restarting)

self.core_service_name = config.get("core_service") or "ovos.service"
# In Debian, ssh stays active, but sshd is removed when ssh is disabled
Expand Down Expand Up @@ -194,6 +197,9 @@ def on_done(message):
def handle_ssh_enable_request(self, message):
subprocess.call(f"systemctl enable {self.ssh_service}", shell=True)
subprocess.call(f"systemctl start {self.ssh_service}", shell=True)
self.bus.emit(message.forward("system.ssh.enabled", message.data))

def handle_ssh_enabled(self, message):
# ovos-shell does not want to display
if message.data.get("display", True):
self.gui["status"] = "Enabled"
Expand All @@ -203,34 +209,48 @@ def handle_ssh_enable_request(self, message):
def handle_ssh_disable_request(self, message):
subprocess.call(f"systemctl stop {self.ssh_service}", shell=True)
subprocess.call(f"systemctl disable {self.ssh_service}", shell=True)
self.bus.emit(message.forward("system.ssh.disabled", message.data))

def handle_ssh_disabled(self, message):
# ovos-shell does not want to display
if message.data.get("display", True):
self.gui["status"] = "Disabled"
self.gui["label"] = "SSH Disabled"
self.gui.show_page("Status")

def handle_reboot_request(self, message):
def handle_rebooting(self, message):
"""
Shut down and restart the system
reboot has started
"""
if message.data.get("display", True):
self.gui.show_page("Reboot", override_animations=True,
override_idle=True)

def handle_reboot_request(self, message: Message):
"""
Shut down and restart the system
"""
self.bus.emit(message.forward("system.reboot.start", message.data))
script = os.path.expanduser(self.config.get("reboot_script") or "")
LOG.info(f"Reboot requested. script={script}")
if script and os.path.isfile(script):
subprocess.call(script, shell=True)
else:
subprocess.call("systemctl reboot -i", shell=True)

def handle_shutdown_request(self, message):
def handle_shutting_down(self, message):
"""
Turn the system completely off (with no option to inhibit it)
shutdown has started
"""
if message.data.get("display", True):
self.gui.show_page("Shutdown", override_animations=True,
override_idle=True)

def handle_shutdown_request(self, message):
"""
Turn the system completely off (with no option to inhibit it)
"""
self.bus.emit(message.forward("system.shutdown.start", message.data))
script = os.path.expanduser(self.config.get("shutdown_script") or "")
LOG.info(f"Shutdown requested. script={script}")
if script and os.path.isfile(script):
Expand Down Expand Up @@ -259,11 +279,14 @@ def handle_configure_language_request(self, message):
self.bus.emit(Message('system.configure.language.complete',
{"lang": language_code}))

def handle_mycroft_restart_request(self, message):
def handle_mycroft_restarting(self, message):
if message.data.get("display", True):
self.gui.show_page("Restart", override_animations=True,
override_idle=True)

def handle_mycroft_restart_request(self, message):
service = self.core_service_name
self.bus.emit(message.forward("system.mycroft.service.restart.start", message.data))
# TODO - clean up this mess
try:
restart_service(service, sudo=False, user=True)
Expand All @@ -284,16 +307,17 @@ def handle_ssh_status(self, message):
def shutdown(self):
self.bus.remove("system.ssh.enable", self.handle_ssh_enable_request)
self.bus.remove("system.ssh.disable", self.handle_ssh_disable_request)
self.bus.remove("system.ssh.enabled", self.handle_ssh_enabled)
self.bus.remove("system.ssh.disabled", self.handle_ssh_disabled)
self.bus.remove("system.reboot", self.handle_reboot_request)
self.bus.remove("system.reboot.start", self.handle_rebooting)
self.bus.remove("system.shutdown", self.handle_shutdown_request)
self.bus.remove("system.factory.reset",
self.handle_factory_reset_request)
self.bus.remove("system.factory.reset.register",
self.handle_reset_register)
self.bus.remove("system.configure.language",
self.handle_configure_language_request)
self.bus.remove("system.mycroft.service.restart",
self.handle_mycroft_restart_request)
self.bus.remove("system.shutdown.start", self.handle_shutting_down)
self.bus.remove("system.factory.reset", self.handle_factory_reset_request)
self.bus.remove("system.factory.reset.register", self.handle_reset_register)
self.bus.remove("system.configure.language", self.handle_configure_language_request)
self.bus.remove("system.mycroft.service.restart", self.handle_mycroft_restart_request)
self.bus.remove("system.mycroft.service.restarting", self.handle_mycroft_restarting)
super().shutdown()


Expand Down

0 comments on commit 636b015

Please sign in to comment.