Skip to content

Commit

Permalink
cli: make use of load_cfg wrapper
Browse files Browse the repository at this point in the history
using the wrapper we have cleaner code and
consitent behaviour among all commands
  • Loading branch information
ael-code committed Mar 19, 2016
1 parent 5f2c30d commit e4cafb1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
18 changes: 18 additions & 0 deletions cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import click
from conf.config_utils import load_configs


def die(msg, exit_code=1, fg='red'):
click.secho('ERROR: ' + msg, fg=fg, err=True)
exit(exit_code)


def load_cfg(path, envvar_prefix='LIBREANT_', debug=False):
'''wrapper of config_utils.load_configs'''
try:
return load_configs(envvar_prefix, path=path)
except Exception as e:
if debug:
raise
else:
die(str(e))
5 changes: 3 additions & 2 deletions cli/agherant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import logging

from conf import config_utils
from . import load_cfg
from conf.defaults import get_def_conf, get_help
from utils.loggers import initLoggers
from webant.agherant_standalone import main
Expand All @@ -18,7 +18,7 @@
def agherant(settings, debug, port, address, agherant_descriptions):
initLoggers(logNames=['config_utils'])
conf = get_def_conf()
conf.update(config_utils.load_configs('LIBREANT_', path=settings))
conf.update(load_cfg(settings, debug=debug))
cliConf = {}
if debug:
cliConf['DEBUG'] = True
Expand All @@ -37,6 +37,7 @@ def agherant(settings, debug, port, address, agherant_descriptions):
raise
else:
click.secho(str(e), fg='yellow', err=True)
exit(1)

if __name__ == '__main__':
agherant()
4 changes: 2 additions & 2 deletions cli/libreant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import json

from conf import config_utils
from . import load_cfg
from conf.defaults import get_def_conf, get_help
from utils.loggers import initLoggers
from webant.webant import main
Expand All @@ -25,7 +25,7 @@
def libreant(settings, debug, port, address, fsdb_path, es_indexname, es_hosts, users_db, preset_paths, agherant_descriptions, dump_settings):
initLoggers(logNames=['config_utils'])
conf = get_def_conf()
conf.update(config_utils.load_configs('LIBREANT_', path=settings))
conf.update(load_cfg(settings, debug=debug))
cliConf = {}
if debug:
cliConf['DEBUG'] = True
Expand Down
4 changes: 2 additions & 2 deletions cli/libreant_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os
import mimetypes

from . import load_cfg
from archivant import Archivant
from archivant.exceptions import NotFoundException
from conf import config_utils
from conf.defaults import get_def_conf, get_help
from utils.loggers import initLoggers
from custom_types import StringList
Expand All @@ -27,7 +27,7 @@ def libreant_db(debug, settings, fsdb_path, es_indexname, es_hosts):
initLoggers(logNames=['config_utils'])
global conf
conf = get_def_conf()
conf.update(config_utils.load_configs('LIBREANT_', path=settings))
conf.update(load_cfg(settings, debug=debug))
cliConf = {}
if debug:
cliConf['DEBUG'] = True
Expand Down
4 changes: 2 additions & 2 deletions cli/libreant_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import users.api
import users

from conf import config_utils
from . import load_cfg
from conf.defaults import get_def_conf, get_help
from utils.loggers import initLoggers

Expand Down Expand Up @@ -34,7 +34,7 @@ def libreant_users(debug, settings, users_db, pretty):
initLoggers(logNames=['config_utils'])
global conf
conf = get_def_conf()
conf.update(config_utils.load_configs('LIBREANT_', path=settings))
conf.update(load_cfg(settings, debug=debug))
cliConf = {}
if debug:
cliConf['DEBUG'] = True
Expand Down

0 comments on commit e4cafb1

Please sign in to comment.