xotl.tools.fs.path – Path utilities¶
Extensions to os.path
Functions inside this module must not have side-effects on the
file-system. This module re-exports (without change) several functions from the
os.path standard module.
-
xotl.tools.fs.path.join(base, *extras)[source]¶ Join two or more pathname components, inserting ‘/’ as needed.
If any component is an absolute path, all previous path components will be discarded.
Normalize path (after join parts), eliminating double slashes, etc.
-
xotl.tools.fs.path.fix_encoding(name, encoding=None)[source]¶ Fix encoding of a file system resource name.
encodingis ignored ifnameis already astr.
-
xotl.tools.fs.path.normalize_path(base, *extras)[source]¶ Normalize path by:
- expanding ‘~’ and ‘~user’ constructions.
- eliminating double slashes
- converting to absolute.
-
xotl.tools.fs.path.shorten_module_filename(filename)[source]¶ A filename, normally a module o package name, is shortened looking his head in all python path.
-
xotl.tools.fs.path.shorten_user(filename)[source]¶ A filename is shortened looking for the (expantion) $HOME in his head and replacing it by ‘~’.
-
xotl.tools.fs.path.rtrim(path, n=1)[source]¶ Trims the last
ncomponents of the pathnamepath.This basically applies
ntimes the functionos.path.dirnametopath.pathis normalized before proceeding (but not tested to exists).Changed in version 1.5.5:
ndefaults to 1. In this case rtrim is identical toos.path.dirname().Example:
>>> rtrim('/tmp/a/b/c/d', 3) '/tmp/a' # It does not matter if `/` is at the end >>> rtrim('/tmp/a/b/c/d/', 3) '/tmp/a'