<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Arial, sans-serif" size="2">
<div>I have a question about detecting media through HAL via the Python dbus module.</div>
<div>&nbsp;</div>
<div>I want my script to be able to detect a blank DVD-R/RW or DVD&#43;R/RW in an external DVD drive so that I can determine the media type before writing.&nbsp; (This is because -R is 4.38 GB and &#43;R is 4.37 GB.)&nbsp; Here is a little bit of code I've written to go looking
for the device:</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><font face="Courier New, monospace">&nbsp;&nbsp; bus = dbus.SystemBus()</font></div>
<div><font face="Courier New, monospace">&nbsp;</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp; hal_obj = bus.get_object('org.freedesktop.Hal',\</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '/org/freedesktop/Hal/Manager')</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp; hal = dbus.Interface(hal_obj, 'org.freedesktop.Hal.Manager')</font></div>
<div><font face="Courier New, monospace">&nbsp;</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp; device_list = hal.FindDeviceByCapability ('volume')</font></div>
<div><font face="Courier New, monospace">&nbsp;</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp; drives = {}</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp; for devID in device_list:</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dev_obj = bus.get_object ('org.freedesktop.Hal', devID)</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dev = dbus.Interface (dev_obj, 'org.freedesktop.Hal.Device')</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent_obj = bus.get_object ('org.freedesktop.Hal',\</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dev.GetProperty(&quot;info.parent&quot;))</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent = dbus.Interface (parent_obj, 'org.freedesktop.Hal.Device')</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (parent.GetProperty ('storage.hotpluggable') or\</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'storage.cdrom' in parent.GetProperty('info.capabilities')):</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try:</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if dev.GetProperty('volume.disc.type') in disc_types.keys():</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; device_name = dev.GetProperty ('block.device')</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; capacity = disc_types[dev.GetProperty('volume.disc.type')]</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drive_name = parent.GetProperty('info.product')</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drives[device_name] = [capacity, drive_name]</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Found a %s in %s (%s)&quot; % (dev.GetProperty('volume.disc.type'), device_name, drive_name&nbsp; )</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; except:</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:</font></div>
<div><font face="Courier New, monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue</font></div>
<div><font face="Courier New, monospace">&nbsp;</font></div>
<div><font face="Courier New, monospace">&nbsp;</font></div>
<div>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.&nbsp; I am assuming this is because the volume is not mounted (nor should it be because it is blank).&nbsp; 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?</div>
<div>&nbsp;</div>
<div>Thanks,</div>
<div>Tony</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<table border="1" width="721" style="border:1 solid; border-collapse:collapse; margin-left: -2pt; ">
<col width="721">
<tr>
<td><font face="Times New Roman, serif" size="4" color="#711123">Antonio M. Ferreira, Ph.D.
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">Staff Scientist</font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">Department of Structural Biology</font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">St. Jude Children&#8217;s Research Hospital</font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">262 Danny Thomas Place, Mail Stop 311&nbsp;&nbsp; </font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">Memphis, Tennessee 38105</font></div>
<div><font face="Times New Roman, serif" size="4">&nbsp;</font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">e-mail: <a href="mailto:Antonio.Ferreira@stjude.org"><font color="#711123"><u>Antonio.Ferreira@stjude.org</u></font></a></font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">Phone: (901) 595-4624</font></div>
<div><font face="Times New Roman, serif" size="4" color="#8C7F70">Fax: (901) 595-2945</font></div>
<div style="text-align: right; "><font face="Times New Roman, serif" size="4">&nbsp;</font></div>
</font></td>
</tr>
</table>
<div><font face="Times New Roman, serif" size="4">&nbsp;</font></div>
<div><font face="Times New Roman, serif" size="4">&nbsp;</font></div>
<div><font size="3"><br>

</font></div>
<div><font size="3" color="#711123"><u>&nbsp; ________________________________ &nbsp;</u></font></div>
<div><font face="Arial, sans-serif" color="#808080">Email Disclaimer: <a href="http://www.stjude.org/emaildisclaimer">
www.stjude.org/emaildisclaimer</a><br>

</font></div>
</font>
</body>
</html>