From 1ddfe568f9b3ecc0cc8ed24fcf96bda5dc5528a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 13 Apr 2021 12:25:34 +0200 Subject: [PATCH] factor reading of configuration file --- eoptasks.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/eoptasks.py b/eoptasks.py index 19ec628..ee4562c 100755 --- a/eoptasks.py +++ b/eoptasks.py @@ -59,10 +59,15 @@ class Server: return '' % (self.name, self.keywords) -def get_servers(): - servers = [] +def get_config(): config = configparser.ConfigParser() config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini'))) + return config + + +def get_servers(): + servers = [] + config = get_config() serversfile = config.get('config', 'servers', fallback=None) if serversfile is None: print( @@ -244,8 +249,7 @@ def get_commands(): # puppet.update, unfortunately without proper error checking. 'puppet.update': '''sudo puppet agent -t || true''', } - config = configparser.ConfigParser() - config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini'))) + config = get_config() for section in config.sections(): if section.startswith('command:'): commands[section[len('command:') :]] = config.get(section, 'cmd')