pythonwrench.os module¶
- pythonwrench.os.get_num_cpus_available() int[source]¶
Returns the number of CPUs available for the current process on Linux-based platforms.
On Windows and MAC OS, this will just return the number of logical CPUs on this machine. If the number of CPUs cannot be detected, returns 0.
-
pythonwrench.os.safe_rmdir(root: str | Path, *, rm_root: bool =
True, error_on_non_empty_dir: bool =True, followlinks: bool =False, dry_run: bool =False, verbose: int =0) tuple[list[str], list[str]][source]¶ Remove all empty sub-directories.
- Args:
root: Root directory path. rm_root: If True, remove the root directory too if it is empty at the end. defaults to True. error_on_non_empty_dir: If True, raises a RuntimeError if a subdirectory contains at least 1 file. Otherwise it will ignore non-empty directories. defaults to True. followlinks: Indicates whether or not symbolic links shound be followed. defaults to False. dry_run: If True, does not remove any directory and just output the list of directories which could be deleted. defaults to False. verbose: Verbose level. defaults to 0.
- Returns:
A tuple containing the list of directories paths deleted and the list of directories paths reviewed.
-
pythonwrench.os.tree_iter(root: str | Path, *, include: str | Pattern | Iterable[str | Pattern] =
'.*', exclude: str | Pattern | Iterable[str | Pattern] =(), space: str =' ', branch: str ='│ ', tee: str ='├── ', last: str ='└── ', max_depth: int =9223372036854775807, followlinks: bool =False, skipfiles: bool =False, sort: bool =False) Generator[str, Any, None][source]¶ A recursive generator, given a directory Path object will yield a visual tree structure line by line with each line prefixed by the same characters
Based on: https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python