Re: a humble request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 






Can we not have both? Linux is for the end user but also for the advanced user,
I hope!

You can use automount. That's another way.
 
Anyway, I am appending a python script that returns the mount point.
It is based on something I downloaded from the Internet sometime ago.
You can use it if you want.


--
Paulo Roma Cavalcanti
LCG - UFRJ
#!/usr/bin/python2.4
# Returns a CD mounting Point
# Author: Paulo Roma
# Date: 15 07 2006
#
import sys, os, time, re, string, pwd
import subprocess

# Search in /etc/mtab for a mount point
def GetCDMountPoint(): 
    mtab = "/etc/mtab" 

    # returns the suffix after the last "/"
    getName = lambda x: x.split("/")[-1] 
    if not os.path.exists(mtab): 
        Log("Wasn't able to locate mtab") 
        cd = GetCD() 
        return [(cd, getName(cd))] 

    list = [] 
    for line in file("/etc/mtab"): 
        mpoint, fsys = line.split()[1:3] 
        if fsys == "iso9660": #TODO: Some systems may call it cd9660? 
            Log(mpoint) 
            # if Found, return mount point
            return mpoint #TODO: Should we return a list if somebody has multiple drives? 
            list.append((mpoint, mpoint.split("/")[-1])) 

    if not list: 
	# Not Found, then search in /etc/fstab
        cd = GetCD() 
        # return [(cd, getName(cd))] 
        return cd

    return list 

def Log(s):
    # print "Detected CD drive:", s
    return

# Search in /etc/fstab for a mount point
def GetCD():
 	    cdpath = "None"
 	    # Lifted almost completely out of freevo (thanks dischi ;)
 	    if not os.path.isfile( '/etc/fstab' ):
 	        return cdpath
 	    re_cd        = re.compile( '^(/dev/cdrom[0-9]*|/dev/[am]?cd[0-9]+[a-z]?)[ \t]+([^ \t]+)[ \t]+', re.I )
 	    re_cdrec     = re.compile( '^(/dev/cdrecorder[0-9]*)[ \t]+([^ \t]+)[ \t]+', re.I )
 	    re_dvd       = re.compile( '^(/dev/dvd[0-9]*)[ \t]+([^ \t]+)[ \t]+', re.I )
 	    re_iso       = re.compile( '^([^ \t]+)[ \t]+([^ \t]+)[ \t]+(iso|cd)9660', re.I )
 	    re_automount = re.compile( '^none[ \t]+([^ \t]+).*supermount.*dev=([^,]+).*', re.I )
 	    re_bymountcd = re.compile( '^(/dev/[^ \t]+)[ \t]+([^ ]*cdrom[0-9]*)[ \t]+', re.I )
 	    re_bymountdvd= re.compile( '^(/dev/[^ \t]+)[ \t]+([^ ]*dvd[0-9]*)[ \t]+', re.I )
 	    fd_fstab = open( '/etc/fstab' )
 	    for line in fd_fstab:
 	        # Match on the devices /dev/cdrom, /dev/dvd, and fstype iso9660
 	        match_cd        = re_cd.match( line )
 	        match_cdrec     = re_cdrec.match( line )
 	        match_dvd       = re_dvd.match( line )
 	        match_iso       = re_iso.match( line )
 	        match_automount = re_automount.match( line )
 	        match_bymountcd = re_bymountcd.match( line )
 	        match_bymountdvd= re_bymountdvd.match( line )
 	        mntdir = ''
 	        if match_cd or match_bymountcd:
 	            m = match_cd or match_bymountcd
 	            mntdir = m.group( 2 )
 	        elif match_cdrec:
 	            mntdir = match_cdrec.group( 2 )
 	        elif match_dvd or match_bymountdvd:
 	            m = match_dvd or match_bymountdvd
 	            mntdir = m.group( 2 )
 	        elif match_iso:
 	            mntdir = match_iso.group( 2 )
 	        elif match_automount:
 	            mntdir = match_automount.group( 1 )
 	        if mntdir:
 	            cdpath = mntdir
 	    fd_fstab.close()
 	    if cdpath:
 	        Log(cdpath)
 	    return cdpath

# Main program.
#
def main(argv=None):
    if argv is None:
       argv = sys.argv
    return GetCDMountPoint()

# When main() calls sys.exit(), your interactive Python interpreter 
# will exit! The remedy is to let main()'s return value specify 
# the exit status. 
#
if __name__=='__main__':
    sys.exit(main())

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux