Package plumbum.path¶
-
class
plumbum.path.base.FSUser[source]¶ A special object that represents a file-system user. It derives from
int, so it behaves just like a number (uid/gid), but also have a.nameattribute that holds the string-name of the user, if given (otherwiseNone)-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
plumbum.path.base.Path[source]¶ An abstraction over file system paths. This class is abstract, and the two implementations are
LocalPathandRemotePath.-
__truediv__(other)¶ Joins two paths
-
__floordiv__(expr)[source]¶ Returns a (possibly empty) list of paths that matched the glob-pattern under this path
-
walk(filter=<function <lambda>>, dir_filter=<function <lambda>>)[source]¶ traverse all (recursive) sub-elements under this directory, that match the given filter. By default, the filter accepts everything; you can provide a custom filter function that takes a path as an argument and returns a boolean
Parameters: - filter – the filter (predicate function) for matching results. Only paths matching this predicate are returned. Defaults to everything.
- dir_filter – the filter (predicate function) for matching directories. Only directories matching this predicate are recursed into. Defaults to everything.
-
basename¶ The basename component of this path
-
dirname¶ The dirname component of this path
-
uid¶ The user that owns this path. The returned value is a
FSUserobject which behaves like anint(as expected fromuid), but it also has a.nameattribute that holds the string-name of the user
-
gid¶ The group that owns this path. The returned value is a
FSUserobject which behaves like anint(as expected fromgid), but it also has a.nameattribute that holds the string-name of the group
-
glob(pattern)[source]¶ Returns a (possibly empty) list of paths that matched the glob-pattern under this path
-
copy(dst, override=False)[source]¶ Copies this path (recursively, if a directory) to the destination path
-
read(encoding=None)[source]¶ returns the contents of this file. By default the data is binary (
bytes), but you can specify the encoding, e.g.,'latin1'or'utf8'
-
write(data, encoding=None)[source]¶ writes the given data to this file. By default the data is expected to be binary (
bytes), but you can specify the encoding, e.g.,'latin1'or'utf8'
-
chown(owner=None, group=None, recursive=None)[source]¶ Change ownership of this path.
Parameters: - owner – The owner to set (either
uidorusername), optional - owner – The group to set (either
gidorgroupname), optional - recursive – whether to change ownership of all contained files and subdirectories.
Only meaningful when
selfis a directory. IfNone, the value will default toTrueifselfis a directory,Falseotherwise.
- owner – The owner to set (either
-
chmod(mode)[source]¶ Change the mode of path to the numeric mode.
Parameters: mode – file mode as for os.chmod
-
access(mode=0)[source]¶ Test file existence or permission bits
Parameters: mode – a bitwise-or of access bits, or a string-representation thereof: 'f','x','r','w'foros.F_OK,os.X_OK,os.R_OK,os.W_OK
-
symlink(dst)[source]¶ Creates a symbolic link from
selftodstParameters: dst – the destination path
-
split()[source]¶ Splits the path on directory separators, yielding a list of directories, e.g,
"/var/log/messages"will yield['var', 'log', 'messages'].
-
relative_to(source)[source]¶ Computes the “relative path” require to get from
sourcetoself. They satisfy the invariantsource_path + (target_path - source_path) == target_path. For example:/var/log/messages - /var/log/messages = [] /var/log/messages - /var = [log, messages] /var/log/messages - / = [var, log, messages] /var/log/messages - /var/tmp = [.., log, messages] /var/log/messages - /opt = [.., var, log, messages] /var/log/messages - /opt/lib = [.., .., var, log, messages]
-
-
class
plumbum.path.base.RelativePath(parts)[source]¶ Relative paths are the “delta” required to get from one path to another. Note that relative path do not point at anything, and thus are not paths. Therefore they are system agnostic (but closed under addition) Paths are always absolute and point at “something”, whether existent or not.
Relative paths are created by subtracting paths (
Path.relative_to)-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
plumbum.path.local.LocalPath(*parts)[source]¶ The class implementing local-machine paths
-
basename¶ The basename component of this path
-
dirname¶ The dirname component of this path
-
uid¶ The user that owns this path. The returned value is a
FSUserobject which behaves like anint(as expected fromuid), but it also has a.nameattribute that holds the string-name of the user
-
gid¶ The group that owns this path. The returned value is a
FSUserobject which behaves like anint(as expected fromgid), but it also has a.nameattribute that holds the string-name of the group
-
glob(pattern)[source]¶ Returns a (possibly empty) list of paths that matched the glob-pattern under this path
-
copy(dst, override=False)[source]¶ Copies this path (recursively, if a directory) to the destination path
-
read(encoding=None)[source]¶ returns the contents of this file. By default the data is binary (
bytes), but you can specify the encoding, e.g.,'latin1'or'utf8'
-
write(data, encoding=None)[source]¶ writes the given data to this file. By default the data is expected to be binary (
bytes), but you can specify the encoding, e.g.,'latin1'or'utf8'
-
chown(owner=None, group=None, recursive=None)[source]¶ Change ownership of this path.
Parameters: - owner – The owner to set (either
uidorusername), optional - owner – The group to set (either
gidorgroupname), optional - recursive – whether to change ownership of all contained files and subdirectories.
Only meaningful when
selfis a directory. IfNone, the value will default toTrueifselfis a directory,Falseotherwise.
- owner – The owner to set (either
-
chmod(mode)[source]¶ Change the mode of path to the numeric mode.
Parameters: mode – file mode as for os.chmod
-
access(mode=0)[source]¶ Test file existence or permission bits
Parameters: mode – a bitwise-or of access bits, or a string-representation thereof: 'f','x','r','w'foros.F_OK,os.X_OK,os.R_OK,os.W_OK
-
-
class
plumbum.path.local.LocalWorkdir[source]¶ Working directory manipulator
-
class
plumbum.path.remote.StatRes(tup)[source]¶ POSIX-like stat result
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
plumbum.path.remote.RemotePath(remote, *parts)[source]¶ The class implementing remote-machine paths
-
basename¶ The basename component of this path
-
dirname¶ The dirname component of this path
-
uid¶ The user that owns this path. The returned value is a
FSUserobject which behaves like anint(as expected fromuid), but it also has a.nameattribute that holds the string-name of the user
-
gid¶ The group that owns this path. The returned value is a
FSUserobject which behaves like anint(as expected fromgid), but it also has a.nameattribute that holds the string-name of the group
-
glob(pattern)[source]¶ Returns a (possibly empty) list of paths that matched the glob-pattern under this path
-
unlink()¶ Deletes this path (recursively, if a directory)
-
copy(dst, override=False)[source]¶ Copies this path (recursively, if a directory) to the destination path
-
read(encoding=None)[source]¶ returns the contents of this file. By default the data is binary (
bytes), but you can specify the encoding, e.g.,'latin1'or'utf8'
-
write(data, encoding=None)[source]¶ writes the given data to this file. By default the data is expected to be binary (
bytes), but you can specify the encoding, e.g.,'latin1'or'utf8'
-
chown(owner=None, group=None, recursive=None)[source]¶ Change ownership of this path.
Parameters: - owner – The owner to set (either
uidorusername), optional - owner – The group to set (either
gidorgroupname), optional - recursive – whether to change ownership of all contained files and subdirectories.
Only meaningful when
selfis a directory. IfNone, the value will default toTrueifselfis a directory,Falseotherwise.
- owner – The owner to set (either
-
chmod(mode)[source]¶ Change the mode of path to the numeric mode.
Parameters: mode – file mode as for os.chmod
-
-
class
plumbum.path.remote.RemoteWorkdir(remote)[source]¶ Remote working directory manipulator
-
__weakref__¶ list of weak references to the object (if defined)
-
getpath()[source]¶ Returns the current working directory as a remote path <plumbum.path.remote.RemotePath> object
-
__call__(*args, **kwds)[source]¶ A context manager used to
chdirinto a directory and thenchdirback to the previous location; much likepushd/popd.Parameters: newdir – The destination director (a string or a RemotePath)
-
Utils¶
-
plumbum.path.utils.delete(*paths)[source]¶ Deletes the given paths. The arguments can be either strings,
local paths,remote paths, or iterables of such. No error is raised if any of the paths does not exist (it is silently ignored)
-
plumbum.path.utils.move(src, dst)[source]¶ Moves the source path onto the destination path;
srcanddstcan be either strings,LocalPathsorRemotePath; any combination of the three will work.New in version 1.3:
srccan also be a list of strings/paths, in which casedstmust not exist or be a directory.
-
plumbum.path.utils.copy(src, dst)[source]¶ Copy (recursively) the source path onto the destination path;
srcanddstcan be either strings,LocalPathsorRemotePath; any combination of the three will work.New in version 1.3:
srccan also be a list of strings/paths, in which casedstmust not exist or be a directory.