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
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.
- 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.
- 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:' $
- get(path: List[str | int] | str | int, relative=True)[source]¶
Return the value of the file associated with path.
- ll(*path: str, delimiter='\n', include_list_indices=False) str [source]¶
Return a formatted result of ls().
- 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.
- 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 = '....'¶
- 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.
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.
- exception filesystem.view.ViewError[source]¶
Bases:
ValueError