Configuration file finder.
APACHE-2.0 License
Configuration file finder.
The configuration file/directory is searched for in the following locations by default:
$XDG_CONFIG_HOME
; if not set, ~/.config is used)To locate the configuration directory, the tool searches for a dot-prefixed name (e.g., .mytool) in all locations except for the XDG config home. Within the XDG config home, a name without the dot prefix (e.g., mytool) is searched for.
If no directory is found, the path under the XDG config home is returned.
To locate the configuration file, the tool first searches for a dot-prefixed file (e.g., .myconf.txt) in all locations except for the XDG config home. Within the XDG config home, a file name without the dot prefix (e.g., myconf.txt) is searched for. Following this, an attempt is made to find the file within the located configuration directories.
If no file is found, the path under the configuration directory within the XDG config home is returned.
$ pip install conf-finder
from conf_finder import ConfFinder
cf = ConfFinder("mytool")
print(cf.directory())
This script searches for:
XDG_CONFIG_HOME
is not set, use ~/.config
.)If no directory is found, return $XDG_CONFIG_HOME/mytool
(or ~/.config/mytool
).
from conf_finder import ConfFinder
cf = ConfFinder("mytool")
print(cf.conf(exe="toml"))
This script searches for:
XDG_CONFIG_HOME
is not set, use ~/.config
.)from conf_finder import ConfFinder
cf = ConfFinder("mytool")
print(cf.conf("mytool", "toml", "myconf"))
This script searches for:
If you wish to search for only files directly placed under the search directories,
conf_type
to 'file'
:
from conf_finder import ConfFinder
cf = ConfFinder("mytool", conf_type="file")
print(cf.conf("mytool", "toml", "myconf"))
This script searches for:
If no file is found, $XDG_CONFIG_HOME/myconf.toml is returned.
To search for only directories, conf_type
to 'dir'
instead.