Skip to content

Commit

Permalink
Update config loading docs
Browse files Browse the repository at this point in the history
  • Loading branch information
woefe committed Oct 22, 2022
1 parent be9a217 commit f5cf87a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ ytccf.sh --help
## Configuration
Ytcc searches for a configuration file at following locations:

1. `$XDG_CONFIG_HOME/ytcc/ytcc.conf`
2. `~/.config/ytcc/ytcc.conf`
3. `~/.ytcc.conf`
1. The file given with `-c` or `--config` options
2. `~/.ytcc.conf`
3. `$XDG_CONFIG_HOME/ytcc/ytcc.conf` or `~/.config/ytcc/ytcc.conf`
4. `/etc/ytcc/ytcc.conf`

If no config file is found in these three locations, a default config file is created at `~/.config/ytcc/ytcc.conf`.
If no config file is found in these locations, a default config file is created at `$XDG_CONFIG_HOME/ytcc/ytcc.conf` or `~/.config/ytcc/ytcc.conf`

### Example config

Expand Down
27 changes: 13 additions & 14 deletions ytcc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,28 @@ def _get_config(override_cfg_file: Optional[str] = None) -> configparser.ConfigP
Searches at following locations:
1. ``override_cfg_file``
2. ``$XDG_CONFIG_HOME/ytcc/ytcc.conf``
3. ``~/.config/ytcc/ytcc.conf``
4. ``~/.ytcc.conf``
3. ``~/.ytcc.conf``
4. ``$XDG_CONFIG_HOME/ytcc/ytcc.conf`` or ``~/.config/ytcc/ytcc.conf``
5. ``/etc/ytcc/ytcc.conf``
If no config file is found in these three locations, a default config file is created in
``~/.config/ytcc/ytcc.conf``
``$XDG_CONFIG_HOME/ytcc/ytcc.conf`` or ``~/.config/ytcc/ytcc.conf``.
:param override_cfg_file: Read the config from this file.
:return: The dict-like config object
"""
config_dir = os.getenv("XDG_CONFIG_HOME")
if not config_dir:
config_dir = "~/.config"

global_cfg_file = "/etc/ytcc/ytcc.conf"
default_cfg_file = os.path.expanduser(config_dir + "/ytcc/ytcc.conf")
fallback_cfg_file = os.path.expanduser("~/.ytcc.conf")

config = configparser.ConfigParser(interpolation=None)

cfg_file_locations = [global_cfg_file, default_cfg_file, fallback_cfg_file]
config_home = os.getenv("XDG_CONFIG_HOME", "~/.config")
default_cfg_file = Path(config_home, "ytcc/ytcc.conf").expanduser()

cfg_file_locations = [
Path("/etc/ytcc/ytcc.conf"),
default_cfg_file,
Path.home() / ".ytcc.conf",
]
if override_cfg_file:
cfg_file_locations.append(override_cfg_file)
cfg_file_locations.append(Path(override_cfg_file))

encoding = locale.getpreferredencoding(False) or "utf-8"

Expand Down

0 comments on commit f5cf87a

Please sign in to comment.