Finding a CDROM device (Python, if it matters)
I'm a casual programmer (i.e., I'm no longer a professional, I just program for fun or for my own projects), usually in Python (although I don't think this is a Python-specific question).
I'm writing a program that catalogs CDROMs, and need to go through the directory of the CDROM given the device.
On Windows, I use something like
Is there an equivalent starting point in Linux?
for (root, dirs, files) in os.walk(startpoint):
but no luck.
What does work is
where VOLUMENAME is the name of the mounted CDROM volume; but I need to be able to do this without knowing the volume name.
Re: Finding a CDROM device (Python, if it matters)
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:
I use it thus:
import subprocess, os
p = subprocess.Popen(["volname", mountpoint],
(response, errmsg) = p.communicate()
errmsg = errmsg.rstrip()
return (volid, errmsg)
(volid, errmsg) = getvolid(cdrom_dev)
if volid is not None:
for (r, d, f) in os.walk("/media/"+volid):
print (r, d, f)
print "Error retrieving volume id, '%s'" %(errmsg)