如何获取可用 DBus 接口属性的列表?
我正在编写一个脚本来跟踪特定类型的 USB 设备连接。我猜想将要跟踪的连接与所有 USB 连接区分开来的一种方法是检查 DBus 在 USB 连接上发送的信号接口的属性。我想获取所有此类属性的列表以选择相关的。
我的代码是:
import sys
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
def deviceAdded(udi):
device = bus.get_object("org.freedesktop.Hal", udi)
device_if = dbus.Interface(device, 'org.freedesktop.Hal.Device')
if device_if.GetPropertyString('info.subsystem') == 'usb_device':
#
# Properties can be accesed like this:
# vendor_id = device_if.GetPropertyInteger('usb_device.vendor_id')
#
# how to get the list of all properties?
#
# do something
def deviceRemoved(udi):
# do something
pass
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(
deviceAdded,
'DeviceAdded',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
bus.add_signal_receiver(
deviceRemoved,
'DeviceRemoved',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
loop = gobject.MainLoop()
try:
loop.run()
except KeyboardInterrupt:
print "usb-device-tracker: keyboad interrupt received, shutting down"
loop.quit()
sys.exit(0)