feat: Add session bus option for local testing and development
Introduced a `--use-session-bus` flag to optionally use the D-Bus session bus instead of the system bus. This allows better flexibility for local testing and development scenarios without requiring system-level changes. Updated related classes and functions to respect the new flag.
This commit is contained in:
@@ -5,8 +5,9 @@ from threading import Thread
|
||||
from time import sleep
|
||||
|
||||
from gi.repository import GLib
|
||||
from pydbus import SystemBus
|
||||
from pydbus import SessionBus, SystemBus
|
||||
|
||||
from .. import proginit as pi
|
||||
from ..dbus_middleware1 import REVPI_DBUS_BASE_PATH
|
||||
from ..dbus_middleware1 import REVPI_DBUS_NAME
|
||||
|
||||
@@ -34,7 +35,7 @@ def simple_call(method: str, *args, interface: str, object_path=REVPI_DBUS_BASE_
|
||||
Any
|
||||
The result of the method invocation on the targeted D-Bus interface.
|
||||
"""
|
||||
bus = SystemBus()
|
||||
bus = SessionBus() if pi.pargs.use_session_bus else SystemBus()
|
||||
revpi = bus.get(REVPI_DBUS_NAME, object_path)
|
||||
iface = revpi[interface]
|
||||
return getattr(iface, method)(*args)
|
||||
@@ -55,7 +56,7 @@ def await_signal(signal_name: str, timeout: int, interface: str, object_path=REV
|
||||
detected_signal = True
|
||||
loop.quit()
|
||||
|
||||
bus = SystemBus()
|
||||
bus = SessionBus() if pi.pargs.use_session_bus else SystemBus()
|
||||
revpi = bus.get(REVPI_DBUS_NAME, object_path)
|
||||
iface = revpi[interface]
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class MiddlewareDaemon:
|
||||
if self.bus_provider and self.bus_provider.is_alive():
|
||||
return
|
||||
|
||||
self.bus_provider = BusProvider()
|
||||
self.bus_provider = BusProvider(use_system_bus=not pi.pargs.use_session_bus)
|
||||
self.bus_provider.start()
|
||||
|
||||
log.debug("leave MiddlewareDaemon.dbus_start")
|
||||
|
||||
@@ -6,7 +6,7 @@ from logging import getLogger
|
||||
from threading import Thread
|
||||
|
||||
from gi.repository import GLib
|
||||
from pydbus import SystemBus
|
||||
from pydbus import SessionBus, SystemBus
|
||||
|
||||
from . import REVPI_DBUS_NAME
|
||||
from .process_image import InterfacePiControl
|
||||
@@ -20,11 +20,12 @@ class BusProvider(Thread):
|
||||
self,
|
||||
picontrol_device="/dev/piControl0",
|
||||
config_rsc="/etc/revpi/config.rsc",
|
||||
use_system_bus=True,
|
||||
):
|
||||
log.debug("enter BusProvider.__init__")
|
||||
super().__init__()
|
||||
|
||||
self._bus = SystemBus()
|
||||
self._bus = SystemBus() if use_system_bus else SessionBus()
|
||||
self._loop = GLib.MainLoop()
|
||||
|
||||
self.picontrol_device = picontrol_device
|
||||
|
||||
@@ -9,7 +9,7 @@ __version__ = "1.4.0"
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from argparse import ArgumentParser, Namespace
|
||||
from argparse import ArgumentParser, Namespace, SUPPRESS
|
||||
from configparser import ConfigParser
|
||||
from enum import Enum
|
||||
from os import R_OK, W_OK, access, environ, getpid, remove
|
||||
@@ -262,6 +262,16 @@ parser = ArgumentParser(
|
||||
prog=programname,
|
||||
description="Program description",
|
||||
)
|
||||
|
||||
# Use session bus of D-Bus for local testing and development proposes (hidden)
|
||||
parser.add_argument(
|
||||
"--use-session-bus",
|
||||
dest="use_session_bus",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help=SUPPRESS,
|
||||
)
|
||||
|
||||
parser.add_argument("--version", action="version", version=f"%(prog)s {program_version}")
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
|
||||
Reference in New Issue
Block a user