Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use udev to find info about inserted video media (e.g. DVDs)
    text
    copied!<p>I'm trying to port an application from using HAL to using pure udev. It is written in python and will use the gudev library, though I would love to see examples in any language. I'm able to get all attached video devices (such as cameras) via:</p> <pre><code>import gudev client = gudev.Client(["video4linux"]) for device in client.get_devices(): print device.get_sysfs_attr("name"), device.get_device_name() </code></pre> <p>This prints out something like:</p> <pre><code>USB2.0 UVC WebCam /dev/video0 </code></pre> <p>I am also able to get a list of block devices, but how can I:</p> <ol> <li><p>Tell if it is a CD/DVD drive?</p></li> <li><p>Tell if media is currently inserted if the drive supports removable media?</p></li> <li><p>Tell what the name/label of the media is (e.g. FUTURAMAS1 for a DVD)?</p></li> </ol> <p>The original code I am trying to port over is located at <a href="http://github.com/danielgtaylor/arista/blob/045a4d48ebfda44bc5d0609618ff795604ee134f/arista/inputs.py" rel="nofollow noreferrer">http://github.com/danielgtaylor/arista/blob/045a4d48ebfda44bc5d0609618ff795604ee134f/arista/inputs.py</a></p> <p>Any and all help would be greatly appreciated!</p> <hr/> <p>Update: adding answer below.</p> <pre><code>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" </code></pre> <p>The code above will output data like:</p> <pre><code>Found CD/DVD drive at /dev/sr0 Found disc: Ubuntu_10.04_i386 </code></pre> <p>Thanks for the help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload