scenario.path module¶
Path management.
- AnyPathType¶
Type for path-like data: either a simple string or a
os.PathLikeinstance.
- class Path¶
Bases:
objectHelper class for path management.
This class really looks like
pathlib.Path, but differs from it in that:it ensures persistent paths, even though initialized from a relative path and the current directory changes afterwards,
it provides a
prettypathdisplay from a main directory set for the current project (seesetmainpath()),it does not describe the current working implicitely when initialized from nothing, but a void path.
The
Pathclass supports theos.PathLikeinterface.- _main_path¶
Main path, used to compute the relative
prettypath. Unset by default.
- static setmainpath(path, log_level=20)¶
Sets the main path, used to compute the relative
prettypath.- Parameters:
path – New main path.
log_level – Log level (as defined by the standard
loggingpackage) to use for the related log line.
- static getmainpath()¶
- Returns:
Main path, i.e. base path for
prettypathcomputations.
- static cwd()¶
Computes a
Pathinstance representing the current working directory.- Returns:
Current working directory.
- static home()¶
Computes a
Pathinstance representing the current user’s home directory.- Returns:
Current user’s home directory.
- static tmp()¶
Computes a
Pathinstance representing the temporary directory.- Returns:
Temporary directory.
- __init__(path=None, relative_to=None)¶
Ensures the management of an absolute path.
- Parameters:
path –
File or directory path as a path-like.
Makes the
Pathinstance void when not set.relative_to –
Base directory or file to consider as the root, when the path given is a relative path.
Giving a file path as
relative_tois equivalent to giving its owner directory.
If the path given is relative, it is transformed in its absolute form from the current working directory.
- as_posix¶
Shortcut to
pathlib.PurePath.as_posix().
- as_uri¶
Shortcut to
pathlib.PurePath.as_uri().
- is_absolute¶
Shortcut to
pathlib.PurePath.is_absolute().
- is_reserved¶
Shortcut to
pathlib.PurePath.is_reserved().
- match¶
Shortcut to
pathlib.PurePath.match().
- stat¶
Shortcut to
pathlib.Path.stat().
- chmod¶
Shortcut to
pathlib.Path.chmod().
- exists¶
Shortcut to
pathlib.Path.exists().
- expanduser¶
Shortcut to
pathlib.Path.expanduser().
- group¶
Shortcut to
pathlib.Path.group().
- is_dir¶
Shortcut to
pathlib.Path.is_dir().
- is_file¶
Shortcut to
pathlib.Path.is_file().
- is_mount¶
Shortcut to
pathlib.Path.is_mount().
- is_symlink¶
Shortcut to
pathlib.Path.is_symlink().
- is_socket¶
Shortcut to
pathlib.Path.is_socket().
- is_fifo¶
Shortcut to
pathlib.Path.is_fifo().
- is_block_device¶
Shortcut to
pathlib.Path.is_block_device().
- is_char_device¶
Shortcut to
pathlib.Path.is_char_device().
- lchmod¶
Shortcut to
pathlib.Path.lchmod().
- lstat¶
Shortcut to
pathlib.Path.lstat().
- mkdir¶
Shortcut for
pathlib.Path.mkdir().
- open¶
Shortcut to
pathlib.Path.open().
- owner¶
Shortcut to
pathlib.Path.owner().
- read_bytes¶
Shortcut to
pathlib.Path.read_bytes().
- read_text¶
Shortcut to
pathlib.Path.read_text().
- readlink¶
Shortcut to
pathlib.Path.readlink().
- rmdir¶
Shortcut to
pathlib.Path.rmdir().
- symlink_to¶
Shortcut to
pathlib.Path.symlink_to().
- hardlink_to¶
Shortcut to
pathlib.Path.hardlink_to().
- link_to¶
Shortcut to
pathlib.Path.link_to().
- touch¶
Shortcut to
pathlib.Path.touch().
- unlink¶
Shortcut to
pathlib.Path.unlink().
- write_bytes¶
Shortcut to
pathlib.Path.write_bytes().
- write_text¶
Shortcut to
pathlib.Path.write_text().
- __fspath__()¶
os.PathLikeinterface implementation.
- __repr__()¶
Canonical string representation.
- __str__()¶
Human readable string representation (same as
prettypath).
- property parts¶
- property drive¶
- property root¶
- property anchor¶
- property name¶
Base name of the path.
- property suffix¶
Gives the extension of the file (or directory name), with its leading dot, if any, or an empty string if no extension.
- property suffixes¶
Gives the list of consecutive extensions, with their leading dot character.
- property stem¶
Gives the basename of the path, without the final extension if any.
- property abspath¶
Absolute form of the path in the POSIX style.
- property prettypath¶
Gives the pretty path.
The pretty path is actually a relative path from the main path if set (see
setmainpath()), or the current working directory otherwise, and presented in the POSIX style.
- __eq__(other)¶
Checks whether
otherequals to this path.- Parameters:
other – Path to checks against.
- Returns:
Truewhen the paths equal,Falseotherwise.
- samefile(other)¶
Returns
Truewhenotherdescribes the same path as this one.- Parameters:
other – Other path (or anything that is not a path at all).
- Returns:
Truewhenotheris the same path.
- __truediv__(other)¶
Joins this directory path with a sub-path.
- Parameters:
other – Sub-path to apply from this directory path.
- Returns:
New
Pathinstance.
- joinpath(*other)¶
Joins this directory path with a list of sub-paths.
- Parameters:
other – Sub-paths to apply from this directory path.
- Returns:
New
Pathinstance.
- with_name(name)¶
- with_stem(stem)¶
- with_suffix(suffix)¶
- is_void()¶
Tells whether this path is void.
- Returns:
Truewhen the path is void,Falseotherwise.
- is_relative_to(other)¶
Tells whether this path is a sub-path of the candidate parent directory.
- Parameters:
other – Candidate parent directory.
- Returns:
Truewhen this path is a sub-path ofother.
- relative_to(other)¶
Computes a relative path.
- Parameters:
other – Reference path to compute the relative path from.
- Returns:
Relative path from
otherin the POSIX style.
Note
The behaviour of this method differs from the one of
pathlib.PurePath.relative_to().pathlib.PurePath.relative_to()raises aValueErroras soon as this path is not a sub-path ofother. In order te be able compute relative paths beginning with “../”, we useos.path.relpath()instead.
- iterdir()¶
Lists this directory path.
- Returns:
Paths iterator.
- glob(pattern)¶
Returns the list of files that match the given pattern.
- Parameters:
pattern – Path pattern (see
glob.glob()). May be either a relative or an absolute path specification.- Returns:
List of paths that match the pattern.
See pathlib.Path.glob().
- rglob(pattern)¶
See pathlib.Path.rglob().
- rename(target)¶
Moves this file or directory as
target.- Parameters:
target – Target path.
- Returns:
New target
Pathinstance.
- replace(target)¶