Read config from XDG_CONFIG_HOME (Fix #65)

Config file is read from the first of these two locations:
* $XDG_CONFIG_HOME/rtv/rtv.cfg
* ~/.rtv
This commit is contained in:
Samir Benmendil
2015-04-03 12:46:05 +01:00
parent 4017c8655f
commit a294010e27
2 changed files with 14 additions and 5 deletions

View File

@@ -26,9 +26,20 @@ def load_config():
saved settings for things like the username and password.
"""
config_path = os.path.join(os.path.expanduser('~'), '.rtv')
config = configparser.ConfigParser()
config.read(config_path)
HOME = os.path.expanduser('~')
XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config'))
config_paths = [
os.path.join(XDG_CONFIG_HOME, 'rtv', 'rtv.cfg'),
os.path.join(HOME, '.rtv')
]
# read only the first existing config file
for config_path in config_paths:
if os.path.exists(config_path):
config.read(config_path)
break
defaults = {}
if config.has_section('rtv'):