A MultiFS is a filesystem composed of a sequence of other filesystems, where the directory structure of each overlays the previous filesystem in the sequence.
One use for such a filesystem would be to selectively override a set of files, to customize behavior. For example, to create a filesystem that could be used to theme a web application. We start with the following directories:
`-- templates |-- snippets | `-- panel.html |-- index.html |-- profile.html `-- base.html `-- theme |-- snippets | |-- widget.html | `-- extra.html |-- index.html `-- theme.html
And we want to create a single filesystem that will load a file from
templates/ only if it isn’t found in
theme/. Here’s how we could
from fs.osfs import OSFS from fs.multifs import MultiFS theme_fs = MultiFS() theme_fs.add_fs('templates', OSFS('templates')) theme_fs.add_fs('theme', OSFS('theme'))
Now we have a
theme_fs filesystem that presents a single view of both
|-- snippets | |-- panel.html | |-- widget.html | `-- extra.html |-- index.html |-- profile.html |-- base.html `-- theme.html
A filesystem that delegates to a sequence of other filesystems.
Operations on the MultiFS will try each ‘child’ filesystem in order, until it succeeds. In effect, creating a filesystem that combines the files and dirs of its children.
add_fs(name, fs, write=False, priority=0)¶
Add a filesystem to the MultiFS.
- name (str) – A unique name to refer to the filesystem being added.
- fs (FS or str) – The filesystem (instance or URL) to add.
- write (bool, optional) – If this value is True,
fswill be used as the writeable FS (defaults to False).
- priority (int, optional) – An integer that denotes the priority of the filesystem being added. Filesystems will be searched in descending priority order and then by the reverse order they were added. So by default, the most recently added filesystem will be looked at first.
Get a filesystem from its name.
Parameters: name (str) – The name of a filesystem previously added. Returns: the filesystem added as
Return type: FS Raises:
KeyError– If no filesystem with given
namecould be found.
Get iterator that returns (name, fs) in priority order.