feat(dbus): Add GUI configuration handling to interface_config.py
Introduced the `configure_gui` function to manage GUI enabling, disabling, availability, and status retrieval. Updated the `AVAILABLE_FEATURES` dictionary to include GUI management functionality, leveraging systemd and os module operations.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
from os import X_OK, access
|
||||||
|
|
||||||
from pydbus import SystemBus
|
from pydbus import SystemBus
|
||||||
|
|
||||||
@@ -70,6 +71,28 @@ class InterfaceRevpiConfig(DbusInterface):
|
|||||||
return list(AVAILABLE_FEATURES.keys())
|
return list(AVAILABLE_FEATURES.keys())
|
||||||
|
|
||||||
|
|
||||||
|
def configure_gui(action: ConfigActions):
|
||||||
|
gui_available = access("/usr/bin/startx", X_OK)
|
||||||
|
|
||||||
|
if action is ConfigActions.AVAILABLE:
|
||||||
|
return gui_available
|
||||||
|
|
||||||
|
bus = SystemBus()
|
||||||
|
systemd_manager = bus.get(".systemd1")
|
||||||
|
|
||||||
|
if action is ConfigActions.ENABLE:
|
||||||
|
systemd_manager.SetDefaultTarget("graphical.target", True)
|
||||||
|
|
||||||
|
elif action is ConfigActions.DISABLE:
|
||||||
|
systemd_manager.SetDefaultTarget("multi-user.target", True)
|
||||||
|
|
||||||
|
elif action is ConfigActions.STATUS:
|
||||||
|
return systemd_manager.GetDefaultTarget() == "graphical.target"
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError(f"action {action} not supported")
|
||||||
|
|
||||||
|
|
||||||
def get_feature(feature: str) -> FeatureFunction:
|
def get_feature(feature: str) -> FeatureFunction:
|
||||||
if feature not in AVAILABLE_FEATURES:
|
if feature not in AVAILABLE_FEATURES:
|
||||||
raise ValueError(f"feature {feature} does not exist")
|
raise ValueError(f"feature {feature} does not exist")
|
||||||
@@ -117,7 +140,7 @@ def simple_systemd(action: ConfigActions, unit: str):
|
|||||||
|
|
||||||
|
|
||||||
AVAILABLE_FEATURES = {
|
AVAILABLE_FEATURES = {
|
||||||
"gui": False,
|
"gui": FeatureFunction(configure_gui, []),
|
||||||
"revpi-con-can": False,
|
"revpi-con-can": False,
|
||||||
"var-log.mount": False,
|
"var-log.mount": False,
|
||||||
"dphys-swapfile": False,
|
"dphys-swapfile": False,
|
||||||
|
|||||||
Reference in New Issue
Block a user