1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
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_fs]
|-- config.cfg
`-- defaults.cfg
[resources_fs]
|-- 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``::
[combined_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::
print(combined_fs.gettext('/config/defaults.cfg'))
read_jpg(combined_fs.open('/resources/images/logo.jpg', 'rb')
.. autoclass:: fs.mountfs.MountFS
:members:
.. autoexception:: fs.mountfs.MountError
:show-inheritance:
|