option to select config file
This commit is contained in:
parent
05fb3c1677
commit
1d36d99462
@ -8,25 +8,12 @@ import argparse
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
DB_USER = ""
|
||||
DB_PASS = ""
|
||||
DB_HOST = ""
|
||||
DB_NAME = ""
|
||||
try:
|
||||
DB_USER = os.environ["DB_USER"]
|
||||
DB_PASS = os.environ["DB_PASS"]
|
||||
DB_HOST = os.environ["DB_HOST"]
|
||||
DB_NAME = os.environ["DB_NAME"]
|
||||
except KeyError:
|
||||
config = configparser.ConfigParser()
|
||||
config.read('./config/dbconfig.ini')
|
||||
DB_USER = config["database"]["user"]
|
||||
DB_PASS = config["database"]["pass"]
|
||||
DB_HOST = config["database"]["host"]
|
||||
DB_NAME = config["database"]["name"]
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description="hv2cli.py")
|
||||
parser.add_argument('--config', '-c',
|
||||
help="Config file, default is ./config/dbconfig.ini",
|
||||
required=False,
|
||||
default="./config/dbconfig.ini")
|
||||
parser.add_argument('--operation', '-o',
|
||||
help='Operation to perform.',
|
||||
required=True)
|
||||
@ -44,12 +31,30 @@ parser.add_argument('--nocolorize', '-n',
|
||||
action='store_true',
|
||||
default=False)
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
operation = args.operation
|
||||
params = json.loads(args.params)
|
||||
logLevel = args.verbosity
|
||||
noColorize = args.nocolorize
|
||||
|
||||
DB_USER = ""
|
||||
DB_PASS = ""
|
||||
DB_HOST = ""
|
||||
DB_NAME = ""
|
||||
try:
|
||||
DB_USER = os.environ["DB_USER"]
|
||||
DB_PASS = os.environ["DB_PASS"]
|
||||
DB_HOST = os.environ["DB_HOST"]
|
||||
DB_NAME = os.environ["DB_NAME"]
|
||||
except KeyError:
|
||||
config = configparser.ConfigParser()
|
||||
config.read(args.config)
|
||||
DB_USER = config["database"]["user"]
|
||||
DB_PASS = config["database"]["pass"]
|
||||
DB_HOST = config["database"]["host"]
|
||||
DB_NAME = config["database"]["name"]
|
||||
|
||||
|
||||
logger.remove()
|
||||
logger.add(sys.stderr, colorize=(not noColorize), level=logLevel)
|
||||
|
Loading…
x
Reference in New Issue
Block a user