De acordo com as docs oficiais (em interfaces padrão ):
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.
Então aqui está um exemplo muito simplista que deve começar. Ele usa xml.etree.ElementTree
e 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')
Ele recursivamente faz a introspecção de org.freedesktop.UPower
a partir de, e. /org/freedesktop/UPower
e imprime todos os caminhos de objetos (nomes de nós):
/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
que é praticamente o que você teria se usasse d-feet
(não que você precisasse):
Claro,vocêpodeobterfacilmenteoscaminhosdeobjetovialinhadecomando,comgdbus
:
gdbusintrospect--system--destorg.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
Eunãotenhoqdbus
instalado,masdeacordocom
qdbus --system org.freedesktop.UPower
deve produzir um resultado semelhante.