Python 基于/dev节点路径查找HAL对象
我正在使用Python 基于/dev节点路径查找HAL对象,python,dbus,hal,Python,Dbus,Hal,我正在使用pythondbus与HAL进行接口,我需要根据设备在/dev层次结构中的路径找到设备的UDI 因此,给定一个路径,如/dev/sdb,我想得到一个值,比如/org/freedesktop/Hal/devices/usb\u device\u 10我将从Python生成一个Hal find by property调用: import subprocess def get_UDI(path): cmd = 'hal-find-by-property --key block.dev
pythondbus
与HAL进行接口,我需要根据设备在/dev
层次结构中的路径找到设备的UDI
因此,给定一个路径,如
/dev/sdb
,我想得到一个值,比如/org/freedesktop/Hal/devices/usb\u device\u 10
我将从Python生成一个Hal find by property
调用:
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
纯python解决方案:
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")
此错误不适用于我:dbuseException:org.freedesktop.DBus.error.AccessDenied:拒绝发送消息,1个匹配规则;type=“method_call”,sender=“:1.74”(uid=1000 pid=3181 comm=“python/usr/bin/ipython”)interface=“org.freedesktop.Hal.Manager”member=“FindDeviceStringMatch”error name=“(unset)”请求的_-reply=“0”destination=“:1.77”(uid=0 pid=4111 comm=“/usr/sbin/hald”),可能是因为我不是根用户。