Mount Filesystem

A Mount FS is a virtual filesystem which can seamlessly map sub-directories on to other filesystems.

For example, lets say we have two filesystems containing config files and resources respectively:

|-- config.cfg
`-- defaults.cfg

|-- images
|   |-- logo.jpg
|   `-- photo.jpg
`-- data.dat

We can combine these filesystems in to a single filesystem with the following code:

from fs.mountfs import MountFS
combined_fs = MountFS()
combined_fs.mount('config', config_fs)
combined_fs.mount('resources', resources_fs)

This will create a filesystem where paths under config/ map to config_fs, and paths under resources/ map to resources_fs:

|-- config
|   |-- config.cfg
|   `-- defaults.cfg
`-- resources
    |-- images
    |   |-- logo.jpg
    |   `-- photo.jpg
    `-- data.dat

Now both filesystems may be accessed with the same path structure:

read_jpg('/resources/images/logo.jpg', 'rb')
class fs.mountfs.MountFS(auto_close=True)[source]

A virtual filesystem that maps directories on to other file-systems.

Parameters:auto_close (bool) – If True (the default), the child filesystems will be closed when MountFS is closed.
mount(path, fs)[source]

Mounts a host FS object on a given path.

  • path (str) – A path within the MountFS.
  • fs (FS or str) – A filesystem (instance or URL) to mount.
exception fs.mountfs.MountError[source]

Bases: exceptions.Exception

Thrown when mounts conflict.