utilities to work with common paths on linux
There are some common concepts for application data on linux. Config files, for example, are typically located in /etc/ and in ~/.config/ with the latter taking precedence.
It is a bit awkward in small projects to implement this behavior. So this library is meant to help with that.
config_path = lxpath.config('myproject', first=True) with open(config_path) as fh: ...
Update existing config:
config_dir = lxpath.config('myproject', can_write=True, first=True) with open(config_path, 'w') as fh: ...
Write new cache file:
cache_dir = lxpath.cache(can_write=True, first=True) cache_path = os.path.join(cache_dir, 'myproject') with open(cache_path, 'w') as fh: ...
Get the root of a git repository:
git_path = lxpath.local('.git', first=True) root_path = os.path.dirname(git_path)
List all icon dirs:
for path in lxpath.share('icons'): print(path)
All functions in this module share the same signature:
config(subpath=None, can_read=True, can_write=False, dot_d=False, first=False)
subpath : search for this subpath in all dirs
can_read : remove all paths that the user can not read
can_read : remove all paths that the user can not write
: if file
foo is included, also include all files in
first : return first match instead of iterator
config() : Search in common config dirs.
share() : Search in common shared data dirs.
cache() : Search in common cache dirs.
local() : Search from local directory upwards.
root() : Search in /.