In Python, how can I get the file system of a given file path
Question: In python, given a directory or file path like /usr/local, I need to get the
file system where its available. In some systems it could be / (root) itself
and in some others it could be /usr.

I tried os.statvfs it doesnt help. Do I have to run the df command with the
path name and extract the file system from the output? Is there a better
solution?

Its for linux/unix platforms only.

Thanks


Answer: Here is a slightly modified version of a recipe found
[here](http://stackoverflow.com/questions/1138383/python-get-mount-point-on-
windows-or-linux). `os.path.realpath` was added so symlinks are handled
correctly.

    
    
    import os
    def getmount(path):        
        path = os.path.realpath(os.path.abspath(path))
        while path != os.path.sep:
            if os.path.ismount(path):
                return path
            path = os.path.abspath(os.path.join(path, os.pardir))
        return path
    

