factor reading of configuration file

This commit is contained in:
Frédéric Péters 2021-04-13 12:25:34 +02:00
parent e445ebc24e
commit 1ddfe568f9
1 changed files with 8 additions and 4 deletions

View File

@ -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')