From 314d2dbf2643bf51d7ec5110531ea69a5d8374df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Piboub=C3=A8s?= Date: Mon, 31 Aug 2015 20:37:02 +0200 Subject: [PATCH] OAuth config file improvements --- rtv/__main__.py | 14 +++++--------- rtv/oauth.py | 15 +++++---------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/rtv/__main__.py b/rtv/__main__.py index 8d3c1f8..ebd8d51 100644 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -64,16 +64,12 @@ def load_oauth_config(): XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config')) - config_paths = [ - os.path.join(XDG_CONFIG_HOME, 'rtv', 'oauth.cfg'), - os.path.join(HOME, '.rtv-oauth') - ] + if os.path.exists(os.path.join(XDG_CONFIG_HOME, 'rtv')): + config_path = os.path.join(XDG_CONFIG_HOME, 'rtv', 'oauth.cfg') + else: + config_path = os.path.join(HOME, '.rtv-oauth') - # get the first existing config file - for config_path in config_paths: - if os.path.exists(config_path): - config.read(config_path) - break + config.read(config_path) if config.has_section('oauth'): defaults = dict(config.items('oauth')) diff --git a/rtv/oauth.py b/rtv/oauth.py index 8fcd118..8203de6 100644 --- a/rtv/oauth.py +++ b/rtv/oauth.py @@ -76,17 +76,12 @@ class OAuthTool(object): XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config')) - config_paths = [ - os.path.join(XDG_CONFIG_HOME, 'rtv', 'oauth.cfg'), - os.path.join(HOME, '.rtv-oauth') - ] + if os.path.exists(os.path.join(XDG_CONFIG_HOME, 'rtv')): + file_path = os.path.join(XDG_CONFIG_HOME, 'rtv', 'oauth.cfg') + else: + file_path = os.path.join(HOME, '.rtv-oauth') - # get the first existing config file - for config_path in config_paths: - if os.path.exists(config_path): - break - - return config_path + return file_path def open_config(self, update=False): if self.config_fp is None: