dbus check

This commit is contained in:
Roy 2024-02-29 05:32:16 -08:00 committed by GitHub
parent 1b445e7514
commit b7c0100f25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,14 +19,20 @@ import logging
# Create and configure a logger object
logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(levelname)s:%(message)s')
handler.setFormatter(formatter)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
# Get the session bus
bus = dbus.SessionBus()
# Check the value of the DBUS_SESSION_BUS_ADDRESS environment variable
dbus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS')
if not dbus_address or not dbus_address.startswith('unix:path='):
# Set the value of the DBUS_SESSION_BUS_ADDRESS environment variable
dbus_address = f'unix:path=/run/user/{os.getuid()}/bus'
os.environ['DBUS_SESSION_BUS_ADDRESS'] = dbus_address
logger.info(f'Set the DBUS_SESSION_BUS_ADDRESS to {dbus_address}')
# Get the NetworkManager service object
try:
nm = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
@ -55,6 +61,7 @@ except dbus.DBusException as e:
print(props)
# Path to the env_vars file
env_vars_path = f"{os.environ['HOME']}/.config/systemd/user/env_vars"