Module zut.path

Normalize and check paths, find paths to the root hierarchy, get default application directories.

Functions

assert_safe_relative_path(path)

Ensure the given path is relative and not subject to path traversal.

find_to_root(name[, start_dir])

Search for the given file name, in increasingly higher folders, from the given start directory up to the root.

get_app_cache_dir(prog)

Base application directory for cache data: - $CACHE_ROOT/{prog} if $CACHE_ROOT is set - $XDG_CACHE_HOME/{prog} (or $LOCALAPPDATA/{prog}/cache on Windows) or their defaults (~/.cache/{prog} or ~AppDataLocal{prog}cache) in a user-scoped context - /var/cache/{prog} (or %PROGRAMDATA%/{prog}/cache on Windows) in a system-scoped context

get_app_config_dir(prog)

Base application directory for configuration files: - $CONFIG_ROOT/{prog} if $CONFIG_ROOT is set - $XDG_CONFIG_HOME/{prog} (or $APPDATA/{prog} on Windows) or their defaults (~/.config/{prog} or ~AppDataRoaming{prog}) in a user-scoped context - /etc/{prog} (or %PROGRAMDATA%/{prog} on Windows) in a system-scoped context

get_app_data_dir(prog)

Base application directory for persistent data: - $DATA_ROOT/{prog} if $DATA_ROOT is set - $XDG_DATA_HOME/{prog} (or $APPDATA/{prog} on Windows) or their defaults (~/.local/share/{prog} or ~AppDataRoaming{prog}) in a user-scoped context - /var/lib/{prog} (or %PROGRAMDATA%/{prog} on Windows) in a system-scoped context

normalize_path(-> ~pathlib.Path  -> ~typing.IO)

Relativize a path from the current working directory if it is inside its tree.

relativize_path(-> ~pathlib.Path  -> ~typing.IO)

Express a path relatively to the given directory (current working directory by default) if it is inside its tree.