Compare commits
5 Commits
604cb61870
...
bc50f0160e
| Author | SHA1 | Date | |
|---|---|---|---|
| bc50f0160e | |||
| 6cd351d8b8 | |||
| 0e513cd179 | |||
| b2a6a184a4 | |||
| 555c781aed |
@@ -29,6 +29,11 @@ def setup_command_line_arguments():
|
|||||||
help="RevPi PiControl object",
|
help="RevPi PiControl object",
|
||||||
)
|
)
|
||||||
cli_picontrol.add_subparsers(obj_picontrol)
|
cli_picontrol.add_subparsers(obj_picontrol)
|
||||||
|
obj_config = rpictl_obj.add_parser(
|
||||||
|
"config",
|
||||||
|
help="RevPi configuration object (revpi-config)",
|
||||||
|
)
|
||||||
|
cli_config.add_subparsers(obj_config)
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
@@ -39,6 +44,9 @@ def main() -> int:
|
|||||||
if obj == "picontrol":
|
if obj == "picontrol":
|
||||||
rc = cli_picontrol.main()
|
rc = cli_picontrol.main()
|
||||||
|
|
||||||
|
elif obj == "config":
|
||||||
|
rc = cli_config.main()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.error(f"Unknown object: {obj}")
|
log.error(f"Unknown object: {obj}")
|
||||||
rc = 1
|
rc = 1
|
||||||
|
|||||||
93
src/revpi_middleware/cli_commands/cli_config.py
Normal file
93
src/revpi_middleware/cli_commands/cli_config.py
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
"""Command-Line for the picontrol object of CLI."""
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from logging import getLogger
|
||||||
|
|
||||||
|
from .dbus_helper import BusType, get_properties, simple_call
|
||||||
|
from .. import proginit as pi
|
||||||
|
from ..dbus_middleware1 import extend_interface
|
||||||
|
|
||||||
|
log = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def add_subparsers(parent_parser: ArgumentParser):
|
||||||
|
parent_parser.add_argument(
|
||||||
|
"action",
|
||||||
|
choices=["enable", "disable", "status", "available", "list-features"],
|
||||||
|
help="Action to be executed: enable, disable, status or available. "
|
||||||
|
"To get all available features, use 'list-features'.",
|
||||||
|
)
|
||||||
|
parent_parser.add_argument(
|
||||||
|
"feature",
|
||||||
|
nargs="?",
|
||||||
|
default="",
|
||||||
|
help="Name of the feature to configer. To list all features use 'list-features' as action.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
action = pi.pargs.action
|
||||||
|
dbus_value = False
|
||||||
|
try:
|
||||||
|
|
||||||
|
if action == "list-features":
|
||||||
|
dbus_value = get_properties(
|
||||||
|
"available_features",
|
||||||
|
interface=extend_interface("RevpiConfig"),
|
||||||
|
bus_type=BusType.SESSION if pi.pargs.use_session_bus else BusType.SYSTEM,
|
||||||
|
)
|
||||||
|
for feature in dbus_value:
|
||||||
|
print(feature)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# For the following actions, a feature name is required
|
||||||
|
if pi.pargs.feature == "":
|
||||||
|
raise Exception("Feature name is required")
|
||||||
|
|
||||||
|
if action == "enable":
|
||||||
|
simple_call(
|
||||||
|
"Enable",
|
||||||
|
pi.pargs.feature,
|
||||||
|
interface=extend_interface("RevpiConfig"),
|
||||||
|
bus_type=BusType.SESSION if pi.pargs.use_session_bus else BusType.SYSTEM,
|
||||||
|
)
|
||||||
|
|
||||||
|
elif action == "disable":
|
||||||
|
simple_call(
|
||||||
|
"Disable",
|
||||||
|
pi.pargs.feature,
|
||||||
|
interface=extend_interface("RevpiConfig"),
|
||||||
|
bus_type=BusType.SESSION if pi.pargs.use_session_bus else BusType.SYSTEM,
|
||||||
|
)
|
||||||
|
|
||||||
|
elif action == "status":
|
||||||
|
dbus_value = simple_call(
|
||||||
|
"GetStatus",
|
||||||
|
pi.pargs.feature,
|
||||||
|
interface=extend_interface("RevpiConfig"),
|
||||||
|
bus_type=BusType.SESSION if pi.pargs.use_session_bus else BusType.SYSTEM,
|
||||||
|
)
|
||||||
|
|
||||||
|
elif action == "available":
|
||||||
|
dbus_value = simple_call(
|
||||||
|
"GetAvailability",
|
||||||
|
pi.pargs.feature,
|
||||||
|
interface=extend_interface("RevpiConfig"),
|
||||||
|
bus_type=BusType.SESSION if pi.pargs.use_session_bus else BusType.SYSTEM,
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise Exception(f"Unknown action: {action}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f"Error: {e}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
log.debug(
|
||||||
|
f"D-Bus call of method {action} for feature {pi.pargs.feature} returned: {dbus_value}"
|
||||||
|
)
|
||||||
|
print(int(dbus_value))
|
||||||
|
|
||||||
|
return 0
|
||||||
@@ -17,6 +17,18 @@ class BusType(Enum):
|
|||||||
SYSTEM = "system"
|
SYSTEM = "system"
|
||||||
|
|
||||||
|
|
||||||
|
def get_properties(
|
||||||
|
property_name: str,
|
||||||
|
interface: str,
|
||||||
|
object_path=REVPI_DBUS_BASE_PATH,
|
||||||
|
bus_type=BusType.SYSTEM,
|
||||||
|
):
|
||||||
|
bus = SessionBus() if bus_type is BusType.SESSION else SystemBus()
|
||||||
|
revpi = bus.get(REVPI_DBUS_NAME, object_path)
|
||||||
|
iface = revpi[interface]
|
||||||
|
return getattr(iface, property_name)
|
||||||
|
|
||||||
|
|
||||||
def simple_call(
|
def simple_call(
|
||||||
method: str,
|
method: str,
|
||||||
*args,
|
*args,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from pydbus import SessionBus, SystemBus
|
|||||||
|
|
||||||
from . import REVPI_DBUS_NAME
|
from . import REVPI_DBUS_NAME
|
||||||
from .process_image import InterfacePiControl
|
from .process_image import InterfacePiControl
|
||||||
|
from .system_config import InterfaceRevpiConfig
|
||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ class BusProvider(Thread):
|
|||||||
# ("Subdir2/Whatever", Example())
|
# ("Subdir2/Whatever", Example())
|
||||||
lst_interfaces = [
|
lst_interfaces = [
|
||||||
InterfacePiControl(self.picontrol_device, self.config_rsc),
|
InterfacePiControl(self.picontrol_device, self.config_rsc),
|
||||||
|
InterfaceRevpiConfig(),
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user