filesystem package

Submodules

filesystem.discoverable module

Discoverable filesystems Extend FileSystem with support for dynamic data. E.g. data from a REST resource.

Usage

fs = Discoverable({'repository': User},
                get_value_method=observe)

where

@dataclass
class User:
    # A REST resource of the endpoints `/users` and `/users/{id}`
    email: str
    role: str

    @staticmethod
    def get_value(path: Path):
        # Retrieve external data and instantiate this class.

    @staticmethod
    def get_all(path: Path):
        # Return resource identifiers.

    @staticmethod
    def refresh() -> bool:
        # Return True to indicate that a resource should be refreshed.
class filesystem.discoverable.Discoverable(*args, get_value_method: Callable[[FileSystem, str | int, dict | list, View], dict | list] | str = None, **kwds)[source]

Bases: FileSystem

discover(k: str | int, cwd: View = None)[source]
load(snapshot='.snapshot.pickle')[source]
observe(k: str | int, initial_value=None, cwd: View = None)[source]
observe_child_fields(path: List[str | int] | str | int)[source]
reset(*path: str)[source]
save_observed_value(k: str | int, initial_value=None, observed_value=None, cwd: View = None)[source]
show(*path: str)[source]

Show contents

snapshot(filename='.snapshot.pickle') bytes[source]
undiscover(k: str | int = None, cwd: View = None)[source]
filesystem.discoverable.discover_using_cls(cls: type, k: str | int, container_cls: type, full_path)[source]
filesystem.discoverable.infer_defaults(cls: type, data: dict)[source]
filesystem.discoverable.infer_initial_value_key(k: str | int, cwd: View)[source]
filesystem.discoverable.observe(repository: FileSystem, k: str | int, initial_value=None, cwd: View = None)[source]

filesystem.filesystem module

class filesystem.filesystem.FileSystem(root: dict = None, home: ~typing.List[str | int] | str | int = None, get_hook: ~typing.Callable[[str | int, ~mash.filesystem.view.View], str | int] = <function first>, post_cd_hook: ~typing.Callable = <function none>, **dict_kwds)[source]

Bases: object

A filesystem-like interface for static and dynamic data. This can be used to e.g. browse REST APIs.

append(k, v)[source]

Associate key k with value v and then change the working directory to k

cd(*path: str | int)[source]

Change working directory to path.

cd_option(option: Option)[source]
cd_step(k: str | int)[source]
cd_up()[source]
copy(post_cd_hook=None)[source]
cp(*references: str | int)[source]

Copy references.

Usage

cp(a, b) # Let b point to the value referenced by a.
cp(*a, b) # let b contain the pointers *a.
property cwd: View

A shallow copy of the current working directory.

foreach(path: List[str | int] | str | int) List[List[str | int] | str | int][source]

List all objects in the dir associated with each path, recursively.

Usage:

# GET repository/users/{id}/email
foreach repository users email >>= echo 'email:' $
property full_path: List[str | int] | str | int
get(path: List[str | int] | str | int, relative=True)[source]

Return the value of the file associated with path.

property home: List[str | int] | str | int
in_home() bool[source]

Check whether home is in cwd.

infer_key_name(path: List[str | int] | str | int, k: str | int, relative=True) str[source]
init_home(home: List[str | int] | str | int)[source]
init_states()[source]
ll(*path: str, delimiter='\n', include_list_indices=False) str[source]

Return a formatted result of ls().

load(snapshot: bytes)[source]
ls(*paths: List[str | int] | str | int) List[str | int][source]

List all objects in the dir associated with each path. If this dir is a path, then its properties are returned. Objects that start with HIDE_PREFIX are ignored.

mv(*references: str | int)[source]

Move references.

Usage

mv(a, b) # rename the reference a to b.
mv(*a, b) # move references *a to b
property path: List[str | int] | str | int
rm(*references: str | int)[source]

Remove references.

property semantic_path: Iterable[str | int]

Convert indices in path to semantic values.

set(k, value: dict | list, cwd: View = None)[source]

Assign a value to the file k.

show(*path: str)[source]
simulate_cd(path: List[str | int] | str | int, relative: bool) View[source]
snapshot() bytes[source]
tree(*path: str) str[source]
class filesystem.filesystem.Option(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Filesystem traversal options.

default = '~'
home = '~'
root = '/'
stay = '.'
switch = '-'
up = '..'
upup = '...'
upupup = '....'
default = '~'
home = '~'
root = '/'
stay = '.'
switch = '-'
up = '..'
upup = '...'
upupup = '....'
static verify(value)[source]
filesystem.filesystem.cd(filesystem: FileSystem, *keys: str)[source]

Change directory and finally reset the current directory. Stay in the current directory by default.

filesystem.scope module

class filesystem.scope.Scope(data: FileSystem, key='env', **kwds)[source]

Bases: object

A dict-like interface for a FileSystem instance. It mixes local and global scopes.

If a file is not present in the current directory, then this class attempts to acces it in each parent directory.

asdict() dict[source]
keys() Iterable[str][source]

Return the keys of all environment variables. Keys of global variables that are shadowed by local variables are ignored.

update(env: dict = {}, items: Tuple[str, Any] = [])[source]
filesystem.scope.show(env: ~filesystem.scope.Scope = None, when=<function constant.<locals>.K>)[source]

filesystem.view module

class filesystem.view.View(tree: dict | list, _trace: ~typing.List[~typing.Tuple[str | int, dict | list]] = <factory>)[source]

Bases: object

A tree of dict’s. Tree traversal is exposed through the methods up and down.

copy()[source]
cp(*references: str | int)[source]
down(key: str | int)[source]
get(k: str | int = None) Tuple[str | int, Any][source]

Return the value that is refrences by k. May raises ValueError.

infer_index(key: str | int)[source]
ls() Iterable[str | int][source]
mv(*references: str | int)[source]
property path: List[str | int] | str | int
rm(*references: str | int)[source]
set(k: str | int, value)[source]
property trace: List[Tuple[str | int, dict | list]]

A copy of the interal field _trace.

tree: dict | list
up() str | int[source]

Change view the parent directory. Raises IndexError if there is not parent directory.

exception filesystem.view.ViewError[source]

Bases: ValueError

filesystem.view.verify_directory(value, name: str)[source]

Module contents