finding mount points

John Clonts jclonts at mastnet.net
Wed Jul 12 02:28:35 EDT 2000


Suchandra Thapa wrote:
> 
> John Clonts <jclonts at mastnet.net> wrote:
> >Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>>> import posixpath
> >>>> posixpath.ismount("/")
> >1
> >>>> posixpath.ismount("/mnt")
> >0
> >>>> posixpath.ismount("/mnt/dosd")
> >1
> >>>> posixpath.ismount("/home")
> >1
> >>>> posixpath.ismount("/home/john")
> >0
> 
>     Actually, I wanted something like
> >>>mountpoint('/home/john')
> >/home
> >>>mountpoint('/home')
> >/home
> 
> I suppose I could do a recursive solution where I start with the full path
> and take away directories and check to see if its a mount point using
> ismount but I was hoping there was a module or way to find the mount point
> directly.
> 

Oh, sorry, I misread your question.

I didn't find anything already extant, so here's this:

def mountpoint(s):
    import os
    if (os.path.ismount(s) or len(s)==0): return s
    else: return mountpoint(os.path.split(s)[0])

def testit():
    print mountpoint("/home/john/scheme/cmucl")
    print mountpoint("/usr/local")
    print mountpoint("/lib/")
    print mountpoint("lib")


Cheers,
John



More information about the Python-list mailing list