HAL Access to DVD writer with blank media

Ferreira, Antonio Antonio.Ferreira at STJUDE.ORG
Tue Mar 17 13:32:23 PDT 2009


I have a question about detecting media through HAL via the Python dbus module.

I want my script to be able to detect a blank DVD-R/RW or DVD+R/RW in an external DVD drive so that I can determine the media type before writing.  (This is because -R is 4.38 GB and +R is 4.37 GB.)  Here is a little bit of code I've written to go looking for the device:




   bus = dbus.SystemBus()

   hal_obj = bus.get_object('org.freedesktop.Hal',\
                             '/org/freedesktop/Hal/Manager')
   hal = dbus.Interface(hal_obj, 'org.freedesktop.Hal.Manager')

   device_list = hal.FindDeviceByCapability ('volume')

   drives = {}
   for devID in device_list:
        dev_obj = bus.get_object ('org.freedesktop.Hal', devID)
        dev = dbus.Interface (dev_obj, 'org.freedesktop.Hal.Device')
        parent_obj = bus.get_object ('org.freedesktop.Hal',\
                                     dev.GetProperty("info.parent"))
        parent = dbus.Interface (parent_obj, 'org.freedesktop.Hal.Device')
        if (parent.GetProperty ('storage.hotpluggable') or\
            'storage.cdrom' in parent.GetProperty('info.capabilities')):
            try:
                if dev.GetProperty('volume.disc.type') in disc_types.keys():
                    device_name = dev.GetProperty ('block.device')
                    capacity = disc_types[dev.GetProperty('volume.disc.type')]
                    drive_name = parent.GetProperty('info.product')
                    drives[device_name] = [capacity, drive_name]
                    print "Found a %s in %s (%s)" % (dev.GetProperty('volume.disc.type'), device_name, drive_name  )
            except:
                continue
            else:
                continue


The only problem with this code is that if I put a blank DVD in a known drive, it will not detect that drive through HAL.  I am assuming this is because the volume is not mounted (nor should it be because it is blank).  How do I determine if a valid device /dev/scd0 (symlink: /dev/dvdwriter) has blank optical media in it and have that device ready for recording?

Thanks,
Tony



Antonio M. Ferreira, Ph.D.
Staff Scientist
Department of Structural Biology
St. Jude Children's Research Hospital
262 Danny Thomas Place, Mail Stop 311
Memphis, Tennessee 38105

e-mail: Antonio.Ferreira at stjude.org<mailto:Antonio.Ferreira at stjude.org>
Phone: (901) 595-4624
Fax: (901) 595-2945





  ________________________________
Email Disclaimer: www.stjude.org/emaildisclaimer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/hal/attachments/20090317/5d7f61c5/attachment.htm 


More information about the hal mailing list