File: multifs.rst

package info (click to toggle)
python-fs 2.4.16-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,948 kB
  • sloc: python: 13,048; makefile: 226; sh: 3
file content (55 lines) | stat: -rw-r--r-- 1,345 bytes parent folder | download | duplicates (5)
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
51
52
53
54
55
Multi Filesystem
================

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
do that::


    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
directories::

    |-- snippets
    |   |-- panel.html
    |   |-- widget.html
    |   `-- extra.html
    |-- index.html
    |-- profile.html
    |-- base.html
    `-- theme.html


.. autoclass:: fs.multifs.MultiFS
    :members: