Compare commits
8 Commits
acdb814007
...
v0.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
| cc560770ce | |||
| 4df903783c | |||
| 8db1f59cfe | |||
| 7051eba9b9 | |||
| 04780bd0dd | |||
| 41fb2b3c61 | |||
| 41d9b13e71 | |||
| 463a61a001 |
@@ -1,4 +1,4 @@
|
|||||||
<!-- /etc/dbus-1/system.d/revpi-middleware.conf -->
|
<!-- /usr/share/dbus-1/system.d/com.revolutionpi.middleware1.conf -->
|
||||||
<busconfig>
|
<busconfig>
|
||||||
<!-- Allow full access to root as the bus owner -->
|
<!-- Allow full access to root as the bus owner -->
|
||||||
<policy user="root">
|
<policy user="root">
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<allow send_destination="com.revolutionpi.middleware1"
|
<allow send_destination="com.revolutionpi.middleware1"
|
||||||
send_interface="org.freedesktop.DBus.Introspectable"/>
|
send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||||
<allow send_destination="com.revolutionpi.middleware1"
|
<allow send_destination="com.revolutionpi.middleware1"
|
||||||
send_interface="com.revolutionpi.middleware1.picontrol"/>
|
send_interface="com.revolutionpi.middleware1.PiControl"/>
|
||||||
</policy>
|
</policy>
|
||||||
|
|
||||||
<!-- Standard-Policy -->
|
<!-- Standard-Policy -->
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from glob import glob
|
|||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from os import X_OK, access
|
from os import X_OK, access
|
||||||
from os.path import exists, join
|
from os.path import exists, join
|
||||||
|
from threading import Thread
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydbus import SystemBus
|
from pydbus import SystemBus
|
||||||
@@ -554,7 +555,11 @@ def configure_gui(action: ConfigActions):
|
|||||||
return gui_available
|
return gui_available
|
||||||
|
|
||||||
bus = SystemBus()
|
bus = SystemBus()
|
||||||
systemd_manager = bus.get(".systemd1")
|
systemd = bus.get(
|
||||||
|
"org.freedesktop.systemd1",
|
||||||
|
"/org/freedesktop/systemd1",
|
||||||
|
)
|
||||||
|
systemd_manager = systemd["org.freedesktop.systemd1.Manager"]
|
||||||
|
|
||||||
if action is ConfigActions.ENABLE:
|
if action is ConfigActions.ENABLE:
|
||||||
systemd_manager.SetDefaultTarget("graphical.target", True)
|
systemd_manager.SetDefaultTarget("graphical.target", True)
|
||||||
@@ -654,21 +659,51 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|||||||
ValueError: If the specified action is not supported.
|
ValueError: If the specified action is not supported.
|
||||||
"""
|
"""
|
||||||
bus = SystemBus()
|
bus = SystemBus()
|
||||||
systemd_manager = bus.get(".systemd1")
|
systemd = bus.get(
|
||||||
|
"org.freedesktop.systemd1",
|
||||||
|
"/org/freedesktop/systemd1",
|
||||||
|
)
|
||||||
|
systemd_manager = systemd["org.freedesktop.systemd1.Manager"]
|
||||||
|
|
||||||
if action is ConfigActions.ENABLE:
|
if action is ConfigActions.ENABLE:
|
||||||
systemd_manager.UnmaskUnitFiles([unit], False)
|
|
||||||
systemd_manager.EnableUnitFiles([unit], False, False)
|
def thread_unit_config():
|
||||||
|
"""Change configuration asynchronously."""
|
||||||
|
# Dbus call: UnmaskUnitFiles(in as files, in b runtime, out a(sss) changes
|
||||||
|
lst_change_unmask = systemd_manager.UnmaskUnitFiles([unit], False)
|
||||||
|
|
||||||
|
# Dbus call: EnableUnitFiles(in as files, in b runtime, in b force,
|
||||||
|
# out b carries_install_info, out a(sss) changes
|
||||||
|
lst_change_enable = systemd_manager.EnableUnitFiles([unit], False, False)
|
||||||
|
if lst_change_unmask or lst_change_enable:
|
||||||
|
# Reload systemd after modified unit property
|
||||||
|
systemd_manager.Reload()
|
||||||
|
|
||||||
|
Thread(target=thread_unit_config, daemon=True).start()
|
||||||
|
|
||||||
|
# Dbus call: StartUnit(in s name, in s mode, out o job
|
||||||
systemd_manager.StartUnit(unit, "replace")
|
systemd_manager.StartUnit(unit, "replace")
|
||||||
|
|
||||||
elif action is ConfigActions.DISABLE:
|
elif action is ConfigActions.DISABLE:
|
||||||
|
|
||||||
|
def thread_unit_config():
|
||||||
|
"""Change configuration asynchronously."""
|
||||||
|
# Dbus call: DisableUnitFiles (in as files, in b runtime, out a(sss) changes)
|
||||||
|
change = systemd_manager.DisableUnitFiles([unit], False)
|
||||||
|
if change:
|
||||||
|
# Reload systemd after modified unit property
|
||||||
|
systemd_manager.Reload()
|
||||||
|
|
||||||
|
Thread(target=thread_unit_config, daemon=True).start()
|
||||||
|
|
||||||
|
# Dbus call: StopUnit(in s name,in s mode, out o job
|
||||||
systemd_manager.StopUnit(unit, "replace")
|
systemd_manager.StopUnit(unit, "replace")
|
||||||
systemd_manager.DisableUnitFiles([unit], False)
|
|
||||||
|
|
||||||
elif action is ConfigActions.STATUS:
|
elif action is ConfigActions.STATUS:
|
||||||
try:
|
try:
|
||||||
unit_path = systemd_manager.LoadUnit(unit)
|
unit_path = systemd_manager.LoadUnit(unit)
|
||||||
properties = bus.get(".systemd1", unit_path)
|
properties = bus.get("org.freedesktop.systemd1", unit_path)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.warning(f"could not get systemd unit {unit}")
|
log.warning(f"could not get systemd unit {unit}")
|
||||||
return False
|
return False
|
||||||
@@ -678,7 +713,7 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|||||||
elif action is ConfigActions.AVAILABLE:
|
elif action is ConfigActions.AVAILABLE:
|
||||||
try:
|
try:
|
||||||
unit_path = systemd_manager.LoadUnit(unit)
|
unit_path = systemd_manager.LoadUnit(unit)
|
||||||
properties = bus.get(".systemd1", unit_path)
|
properties = bus.get("org.freedesktop.systemd1", unit_path)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.warning(f"could not get systemd unit {unit}")
|
log.warning(f"could not get systemd unit {unit}")
|
||||||
return False
|
return False
|
||||||
@@ -688,6 +723,8 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|||||||
else:
|
else:
|
||||||
raise ValueError(f"action {action} not supported")
|
raise ValueError(f"action {action} not supported")
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
rc = RevPiConfig()
|
rc = RevPiConfig()
|
||||||
|
|||||||
Reference in New Issue
Block a user