Hi,
I'm using python-dbus
to interface with HAL, and I need to find a device's UDI based on it's path in the /dev
hierarchy.
So given a path such as /dev/sdb
, I want to get a value back like /org/freedesktop/Hal/devices/usb_device_10
.
Hi,
I'm using python-dbus
to interface with HAL, and I need to find a device's UDI based on it's path in the /dev
hierarchy.
So given a path such as /dev/sdb
, I want to get a value back like /org/freedesktop/Hal/devices/usb_device_10
.
I would spawn a hal-find-by-property
call from Python:
import subprocess
def get_UDI(path):
cmd = 'hal-find-by-property --key block.device --string %s' % path
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
output = proc.communicate()
# stdout
return output[0].strip()
print get_UDI('/dev/sdb') # /org/freedesktop/Hal/devices/xxxxxx
Pure python solution:
import dbus
bus = dbus.SystemBus()
obj = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
iface = dbus.Interface(obj, "org.freedesktop.Hal.Manager")
print iface.FindDeviceStringMatch("block.device", "/dev/sda")