On Fri, 5 Nov 2010, Terry Carroll wrote:
Aha, this looks like it will work; I was starting to think along these lines; I was thinking of reading the output of df, but this is cleaner.
Just to close this out, here's what's working for me. It will need to be prettied up, and the "/media/" parameterized, but it's my proof of concept that lets me know how to solve my problem:
######################################################### 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) # Test it things_to_try = ["/dev/sr0", # VBOXADDITIONS_3.2.6_63112 "/dev/cdrom1", # symlink to sr0 "/dev/sr1", # MP_04_074 "/dev/cdrom", # symlink to sr1 "/dev/sr2"] # no such mount point, return an error for thing in things_to_try: volid, error = getvolid(thing) print "mount point=%s; volid=%s; errormsg=%s" % (thing, volid, error) # Try the os.walk: (volid, errmsg) = getvolid("/dev/sr0") for (r, d, f) in os.walk("/media/"+volid): print (r, d, f) ######################################################### _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor