Default auto_login and README update

This commit is contained in:
Théo Piboubès
2015-08-17 04:28:15 +02:00
parent 46dda7a2bc
commit a15934e5e4
2 changed files with 33 additions and 17 deletions

View File

@@ -20,6 +20,23 @@ from .__version__ import __version__
__all__ = []
def get_config_fp():
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')
]
# get the first existing config file
for config_path in config_paths:
if os.path.exists(config_path):
break
return config_path
def open_config():
"""
Search for a configuration file at the location ~/.rtv and attempt to load
@@ -28,18 +45,8 @@ def open_config():
config = configparser.ConfigParser()
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
config_path = get_config_fp()
config.read(config_path)
return config
@@ -66,9 +73,14 @@ def load_oauth_config():
config = open_config()
defaults = {}
if config.has_section('oauth'):
defaults = dict(config.items('oauth'))
else:
# Populate OAuth section
config['oauth'] = {'auto_login': False}
with open(get_config_fp(), 'w') as cfg:
config.write(cfg)
defaults = dict(config.items('oauth'))
return defaults