summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2021-04-13 10:25:34 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2021-04-13 10:25:34 (GMT)
commit1ddfe568f9b3ecc0cc8ed24fcf96bda5dc5528a6 (patch)
treec292b8b448adc135b6c21a4c9f717b1bd7aedaee
parente445ebc24edc459fdfb30c0257d799a79fa3ef50 (diff)
downloadeoptasks-1ddfe568f9b3ecc0cc8ed24fcf96bda5dc5528a6.zip
eoptasks-1ddfe568f9b3ecc0cc8ed24fcf96bda5dc5528a6.tar.gz
eoptasks-1ddfe568f9b3ecc0cc8ed24fcf96bda5dc5528a6.tar.bz2
factor reading of configuration file
-rwxr-xr-xeoptasks.py12
1 files 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 '<Server %s %r>' % (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')