After some experimentation, it seems like a working approach is to call the Linux "volname" command (hat-tip to Steven D'Aprano on the python-tutors list for identifying the command for me) to find out the volume, and then use the volume name to specify the directory in /media. Here's what I'm doing now:
Code:
import subprocess, os
def getvolid(mountpoint):
p = subprocess.Popen(["volname", mountpoint],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(response, errmsg) = p.communicate()
volid=response.rstrip()
errmsg = errmsg.rstrip()
if len(response)==0:
volid=None
return (volid, errmsg)
I use it thus:
Code:
cdrom_dev="/dev/sr0"
(volid, errmsg) = getvolid(cdrom_dev)
if volid is not None:
for (r, d, f) in os.walk("/media/"+volid):
print (r, d, f)
else:
print "Error retrieving volume id, '%s'" %(errmsg)
Bookmarks