我正在尝试将应用程序从使用 HAL 移植到使用纯 udev。它是用 python 编写的,将使用 gudev 库,尽管我希望看到任何语言的示例。我可以通过以下方式获取所有连接的视频设备(例如相机):
import gudev
client = gudev.Client(["video4linux"])
for device in client.get_devices():
print device.get_sysfs_attr("name"), device.get_device_name()
这会打印出如下内容:
USB2.0 UVC WebCam /dev/video0
我还可以获得块设备列表,但我怎样才能:
判断它是否是 CD/DVD 驱动器?
如果驱动器支持可移动媒体,请判断当前是否插入了媒体?
告诉媒体的名称/标签是什么(例如 DVD 的 FUTURAMAS1)?
我试图移植的原始代码位于http://github.com/danielgtaylor/arista/blob/045a4d48ebfda44bc5d0609618ff795604ee134f/arista/inputs.py
任何和所有的帮助将不胜感激!
更新:在下面添加答案。
import gudev
client = gudev.Client(['block'])
for device in client.query_by_subsystem("block"):
if device.has_property("ID_CDROM"):
print "Found CD/DVD drive at %s" % device.get_device_file()
if device.has_property("ID_FS_LABEL"):
print "Found disc: %s" % device.get_property("ID_FS_LABEL")
elif device.has_property("ID_FS_TYPE"):
print "Found disc"
else:
print "No disc"
上面的代码将输出如下数据:
Found CD/DVD drive at /dev/sr0
Found disc: Ubuntu_10.04_i386
谢谢您的帮助!