|
|
|
|
@@ -10,7 +10,6 @@ from glob import glob
|
|
|
|
|
from logging import getLogger
|
|
|
|
|
from os import X_OK, access
|
|
|
|
|
from os.path import exists, join
|
|
|
|
|
from threading import Thread
|
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
|
|
from pydbus import SystemBus
|
|
|
|
|
@@ -555,11 +554,7 @@ def configure_gui(action: ConfigActions):
|
|
|
|
|
return gui_available
|
|
|
|
|
|
|
|
|
|
bus = SystemBus()
|
|
|
|
|
systemd = bus.get(
|
|
|
|
|
"org.freedesktop.systemd1",
|
|
|
|
|
"/org/freedesktop/systemd1",
|
|
|
|
|
)
|
|
|
|
|
systemd_manager = systemd["org.freedesktop.systemd1.Manager"]
|
|
|
|
|
systemd_manager = bus.get(".systemd1")
|
|
|
|
|
|
|
|
|
|
if action is ConfigActions.ENABLE:
|
|
|
|
|
systemd_manager.SetDefaultTarget("graphical.target", True)
|
|
|
|
|
@@ -659,51 +654,21 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|
|
|
|
ValueError: If the specified action is not supported.
|
|
|
|
|
"""
|
|
|
|
|
bus = SystemBus()
|
|
|
|
|
systemd = bus.get(
|
|
|
|
|
"org.freedesktop.systemd1",
|
|
|
|
|
"/org/freedesktop/systemd1",
|
|
|
|
|
)
|
|
|
|
|
systemd_manager = systemd["org.freedesktop.systemd1.Manager"]
|
|
|
|
|
systemd_manager = bus.get(".systemd1")
|
|
|
|
|
|
|
|
|
|
if action is ConfigActions.ENABLE:
|
|
|
|
|
|
|
|
|
|
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.UnmaskUnitFiles([unit], False)
|
|
|
|
|
systemd_manager.EnableUnitFiles([unit], False, False)
|
|
|
|
|
systemd_manager.StartUnit(unit, "replace")
|
|
|
|
|
|
|
|
|
|
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.DisableUnitFiles([unit], False)
|
|
|
|
|
|
|
|
|
|
elif action is ConfigActions.STATUS:
|
|
|
|
|
try:
|
|
|
|
|
unit_path = systemd_manager.LoadUnit(unit)
|
|
|
|
|
properties = bus.get("org.freedesktop.systemd1", unit_path)
|
|
|
|
|
properties = bus.get(".systemd1", unit_path)
|
|
|
|
|
except Exception:
|
|
|
|
|
log.warning(f"could not get systemd unit {unit}")
|
|
|
|
|
return False
|
|
|
|
|
@@ -713,7 +678,7 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|
|
|
|
elif action is ConfigActions.AVAILABLE:
|
|
|
|
|
try:
|
|
|
|
|
unit_path = systemd_manager.LoadUnit(unit)
|
|
|
|
|
properties = bus.get("org.freedesktop.systemd1", unit_path)
|
|
|
|
|
properties = bus.get(".systemd1", unit_path)
|
|
|
|
|
except Exception:
|
|
|
|
|
log.warning(f"could not get systemd unit {unit}")
|
|
|
|
|
return False
|
|
|
|
|
@@ -723,8 +688,6 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError(f"action {action} not supported")
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
rc = RevPiConfig()
|
|
|
|
|
|