Filesystem
pytruenas.fs
Filesystem paths for a :class:~pytruenas.TrueNASClient.
client.path(...) returns a pathlib_next path:
- local client (running on the NAS) -> a plain
:class:
pathlib_next.LocalPath(no extra dependencies); - remote client -> a :class:
~pytruenas.fs.truenas.TruenasPath, which prefers SFTP and falls back to the middlewarefilesystem.*websocket API (:class:~pytruenas.fs.tnasws.TnasWsPath).
The old bespoke multi-backend Path proxy is gone; these are real
pathlib_next path types, so every generic operation (read_bytes/walk/
glob/copy/...) comes from pathlib_next for free.
__all__ = ['LocalPath', 'TnasWsPath', 'TnasWsBackend', 'TruenasPath', 'path']
module-attribute
TnasWsBackend(client)
Backend state for :class:TnasWsPath: it just holds the client.
Mirrors the role of SftpBackend/AsyncsshSftpBackend (which hold an
SSH/SFTP connection); here the "connection" is the middleware
:class:~pytruenas.TrueNASClient, whose api.filesystem namespace does the
actual work.
Source code in src/pytruenas/fs/tnasws.py
45 46 | |
__slots__ = ('client',)
class-attribute
instance-attribute
client = client
instance-attribute
TnasWsPath
Bases: UriPath
A path on a TrueNAS host, served by the middleware filesystem.* API.
__SCHEMES = (_SCHEME,)
class-attribute
instance-attribute
__slots__ = ()
class-attribute
instance-attribute
chmod(mode, *, follow_symlinks=True)
Source code in src/pytruenas/fs/tnasws.py
121 122 123 124 125 126 | |
chown(uid=None, gid=None, *, follow_symlinks=True, recursive=False, traverse=True)
Source code in src/pytruenas/fs/tnasws.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
rmdir()
Source code in src/pytruenas/fs/tnasws.py
162 163 | |
stat(*, follow_symlinks=True)
Source code in src/pytruenas/fs/tnasws.py
72 73 74 75 76 77 | |
unlink(missing_ok=False)
Source code in src/pytruenas/fs/tnasws.py
153 154 155 156 157 158 159 160 | |
TruenasPath
Bases: TnasWsPath
Remote TrueNAS path: SFTP-preferred, websocket-filesystem.* fallback.
Subclasses :class:~pytruenas.fs.tnasws.TnasWsPath so the always-available
websocket backend is the base behaviour; the SFTP-preferred operations
(unlink/rmdir/rename/symlink_to/readlink/resolve) are overridden to try SFTP
first. Carries the same
TnasWsBackend (holding the client); the SFTP leg is built lazily from the
client's shell/ssh configuration.
__SCHEMES = ('truenas',)
class-attribute
instance-attribute
__slots__ = ()
class-attribute
instance-attribute
readlink()
Source code in src/pytruenas/fs/truenas.py
129 130 131 132 133 134 | |
rename(target)
Source code in src/pytruenas/fs/truenas.py
123 124 125 126 127 | |
resolve(strict=False)
Source code in src/pytruenas/fs/truenas.py
180 181 182 183 184 185 186 187 | |
rmdir()
Source code in src/pytruenas/fs/truenas.py
117 118 119 120 121 | |
symlink_to(target, target_is_directory=False, *, force=False, onremove=None)
Create a symlink, with pytruenas's force= convenience.
force removes a conflicting existing target first (a bool, a single
file-type, or a set of file-types that may be replaced); onremove is a
callback consulted before each removal. Not part of pathlib_next -- kept
from the original pytruenas API. The link itself is created via the SFTP
leg (filesystem.* has no symlink op).
Source code in src/pytruenas/fs/truenas.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
unlink(missing_ok=False)
Source code in src/pytruenas/fs/truenas.py
111 112 113 114 115 | |
path(client, *segments, backend=None)
Build the appropriate path type for client and segments.
backend forces a specific type: "local" -> :class:LocalPath,
"ws"/"api" -> :class:TnasWsPath, "truenas"/"auto" ->
:class:TruenasPath. Default (None/"auto"): LocalPath for a local
client, otherwise TruenasPath.
Source code in src/pytruenas/fs/__init__.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |