请有人告诉我如何使用python获得usb海量存储设备的卷标签(浏览器中显示的名称,而不是设备名称::/dev/sdX)?库/模块,尽管HAL已经废弃,所以请不要建议它作为一个选项。
发布于 2014-03-20 20:21:50
您可以使用python中的dbus查询UDisks2:
安装python:
sudo apt-get install python-dbus运行下面这个小python片段:
cat <<EOF | python -
import dbus
bus = dbus.SystemBus()
ud_manager_obj = bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2')
om = dbus.Interface(ud_manager_obj, 'org.freedesktop.DBus.ObjectManager')
for k,v in om.GetManagedObjects().iteritems():
drive_info = v.get('org.freedesktop.UDisks2.Drive', {})
if drive_info.get('ConnectionBus') == 'usb' and drive_info.get('Removable'):
print("Device Label: %s" % drive_info['Id'])
EOF带着USB驱动器,我得到:
Device Label: Generic-Flash-Disk-EEA1EE5Bhttps://askubuntu.com/questions/437031
复制相似问题