Skip to main content
deleted 300 characters in body
Source Link
don_crissti
  • 85.6k
  • 31
  • 234
  • 262

QT setups provide the most convenient way to do it, via qdbus:

qdbus --system org.freedesktop.UPower

prints

/
/org
/org/freedesktop
/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/line_power_ADP0
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0

As to the python way... per the official docs (under standard interfaces):

enter image description here


Sure, you can easily get the object paths via command line e.g. with gdbus:

gdbus introspect --system --dest org.freedesktop.UPower --object-path \
/org/freedesktop/UPower --recurse | awk '/^ *node /{print $2}'
/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

I don't have qdbus installed but according to this page

qdbus --system org.freedesktop.UPower

should produce a similar result.

As per the official docs (under standard interfaces):

enter image description here


Sure, you can easily get the object paths via command line e.g. with gdbus:

gdbus introspect --system --dest org.freedesktop.UPower --object-path \
/org/freedesktop/UPower --recurse | awk '/^ *node /{print $2}'
/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

I don't have qdbus installed but according to this page

qdbus --system org.freedesktop.UPower

should produce a similar result.

QT setups provide the most convenient way to do it, via qdbus:

qdbus --system org.freedesktop.UPower

prints

/
/org
/org/freedesktop
/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/line_power_ADP0
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0

As to the python way... per the official docs (under standard interfaces):

enter image description here

added 766 characters in body
Source Link
don_crissti
  • 85.6k
  • 31
  • 234
  • 262

As per the official docs (under standard interfaces):

There are some standard interfaces that may be useful across various D-Bus applications.

org.freedesktop.DBus.Introspectable

This interface has one method:

org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)

Objects instances may implement Introspect which returns an XML description of the object, including its interfaces (with signals and methods), objects below it in the object path tree, and its properties.

So here's a very simplistic example that should get you started. It uses xml.etree.ElementTree and dbus:

#!/usr/bin/env python

import dbus
from xml.etree import ElementTree

def rec_intro(bus, service, object_path):
    print(object_path)
    obj = bus.get_object(service, object_path)
    iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
    xml_string = iface.Introspect()
    for child in ElementTree.fromstring(xml_string):
        if child.tag == 'node':
            if object_path == '/':
                object_path = ''
            new_path = '/'.join((object_path, child.attrib['name']))
            rec_intro(bus, service, new_path)

bus = dbus.SystemBus()
rec_intro(bus, 'org.freedesktop.UPower', '/org/freedesktop/UPower')

It recursively introspects org.freedesktop.UPower starting from e.g. /org/freedesktop/UPower and prints all object paths (node names):

/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

which is pretty much what you'd get if you used d-feet (not that you'd need it):

enter image description here


Sure, you can easily get the object paths via command line e.g. with gdbus:

gdbus introspect --system --dest org.freedesktop.UPower --object-path \
/org/freedesktop/UPower --recurse | awk '/^ *node /{print $2}'
/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

I don't have qdbus installed but according to this page

qdbus --system org.freedesktop.UPower

should produce a similar result.

As per the official docs (under standard interfaces):

There are some standard interfaces that may be useful across various D-Bus applications.

org.freedesktop.DBus.Introspectable

This interface has one method:

org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)

Objects instances may implement Introspect which returns an XML description of the object, including its interfaces (with signals and methods), objects below it in the object path tree, and its properties.

So here's a very simplistic example that should get you started. It uses xml.etree.ElementTree and dbus:

#!/usr/bin/env python

import dbus
from xml.etree import ElementTree

def rec_intro(bus, service, object_path):
    print(object_path)
    obj = bus.get_object(service, object_path)
    iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
    xml_string = iface.Introspect()
    for child in ElementTree.fromstring(xml_string):
        if child.tag == 'node':
            if object_path == '/':
                object_path = ''
            new_path = '/'.join((object_path, child.attrib['name']))
            rec_intro(bus, service, new_path)

bus = dbus.SystemBus()
rec_intro(bus, 'org.freedesktop.UPower', '/org/freedesktop/UPower')

It recursively introspects org.freedesktop.UPower starting from e.g. /org/freedesktop/UPower and prints all object paths (node names):

/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

which is pretty much what you'd get if you used d-feet (not that you'd need it):

enter image description here

As per the official docs (under standard interfaces):

There are some standard interfaces that may be useful across various D-Bus applications.

org.freedesktop.DBus.Introspectable

This interface has one method:

org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)

Objects instances may implement Introspect which returns an XML description of the object, including its interfaces (with signals and methods), objects below it in the object path tree, and its properties.

So here's a very simplistic example that should get you started. It uses xml.etree.ElementTree and dbus:

#!/usr/bin/env python

import dbus
from xml.etree import ElementTree

def rec_intro(bus, service, object_path):
    print(object_path)
    obj = bus.get_object(service, object_path)
    iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
    xml_string = iface.Introspect()
    for child in ElementTree.fromstring(xml_string):
        if child.tag == 'node':
            if object_path == '/':
                object_path = ''
            new_path = '/'.join((object_path, child.attrib['name']))
            rec_intro(bus, service, new_path)

bus = dbus.SystemBus()
rec_intro(bus, 'org.freedesktop.UPower', '/org/freedesktop/UPower')

It recursively introspects org.freedesktop.UPower starting from e.g. /org/freedesktop/UPower and prints all object paths (node names):

/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

which is pretty much what you'd get if you used d-feet (not that you'd need it):

enter image description here


Sure, you can easily get the object paths via command line e.g. with gdbus:

gdbus introspect --system --dest org.freedesktop.UPower --object-path \
/org/freedesktop/UPower --recurse | awk '/^ *node /{print $2}'
/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

I don't have qdbus installed but according to this page

qdbus --system org.freedesktop.UPower

should produce a similar result.

Source Link
don_crissti
  • 85.6k
  • 31
  • 234
  • 262

As per the official docs (under standard interfaces):

There are some standard interfaces that may be useful across various D-Bus applications.

org.freedesktop.DBus.Introspectable

This interface has one method:

org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)

Objects instances may implement Introspect which returns an XML description of the object, including its interfaces (with signals and methods), objects below it in the object path tree, and its properties.

So here's a very simplistic example that should get you started. It uses xml.etree.ElementTree and dbus:

#!/usr/bin/env python

import dbus
from xml.etree import ElementTree

def rec_intro(bus, service, object_path):
    print(object_path)
    obj = bus.get_object(service, object_path)
    iface = dbus.Interface(obj, 'org.freedesktop.DBus.Introspectable')
    xml_string = iface.Introspect()
    for child in ElementTree.fromstring(xml_string):
        if child.tag == 'node':
            if object_path == '/':
                object_path = ''
            new_path = '/'.join((object_path, child.attrib['name']))
            rec_intro(bus, service, new_path)

bus = dbus.SystemBus()
rec_intro(bus, 'org.freedesktop.UPower', '/org/freedesktop/UPower')

It recursively introspects org.freedesktop.UPower starting from e.g. /org/freedesktop/UPower and prints all object paths (node names):

/org/freedesktop/UPower
/org/freedesktop/UPower/Wakeups
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_ADP0

which is pretty much what you'd get if you used d-feet (not that you'd need it):

enter image description here