How to use udev to find information about pasted video resources (e.g. DVD)

I am trying to port an application using HAL to use pure udev. It is written in python and will use the gudev library, although I would like to see examples in any language. I can get all connected video devices (e.g. cameras) through:

import gudev

client = gudev.Client(["video4linux"])
for device in client.get_devices():
    print device.get_sysfs_attr("name"), device.get_device_name()

It will print something like:

USB2.0 UVC WebCam /dev/video0

I can also get a list of block devices, but how can I:

  • Tell me, is this a CD / DVD drive?

  • Tell me, is media inserted if the drive supports removable media?

  • Say what is the name / label of the media (e.g. FUTURAMAS1 for DVD)?

The source code I'm trying to move is in 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

!

+3
1

:

import gudev

client = gudev.Client(['block'])
for device in client.query_by_subsystem("block"):
    print device
    for device_key in device.get_property_keys():
        print "   property %s: %s" % (device_key, device.get_property(device_key))
    print
+3

Source: https://habr.com/ru/post/1746069/


All Articles