From d0021f95362aa21e4c5dabdb40b1c92c25d1fe8f Mon Sep 17 00:00:00 2001 From: mischa Date: Fri, 17 Jun 2022 16:01:23 +0200 Subject: [PATCH] moved logging config and fixed typos --- clean.py | 14 +++++++------- get.py | 14 +++++++------- push-debug.py | 18 ++++++++++++++++-- push.py | 18 +++++++++--------- validate-json.py | 2 +- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/clean.py b/clean.py index b44acd0..3b5284b 100755 --- a/clean.py +++ b/clean.py @@ -27,9 +27,9 @@ import configparser import argparse # Parse all arguments -parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI") -parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf") -parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0") +parser = argparse.ArgumentParser(description="Clean Alkira tenant config with AlkirAPI") +parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf)") +parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0)") parser.add_argument("-p", "--pretty", help="make the JSON pretty!", action="store_true") try: @@ -50,6 +50,10 @@ except KeyError: ############################################### +# Set logging.INFO to logging.DEBUG for debug information +logging.basicConfig(level=loglevel) +logging = logging.getLogger('AlkiraAPI') + # Tenant config if not os.path.isfile(ALKIRA_CONFIG): logging.error(f"The config file {ALKIRA_CONFIG} doesn't exist") @@ -62,10 +66,6 @@ ALKIRA_USERNAME = alkira.get('alkira', 'ALKIRA_USERNAME') ALKIRA_PASSWORD = alkira.get('alkira', 'ALKIRA_PASSWORD') ALKIRA_BASE_URI = f'https://{ALKIRA_TENANT}/api' -# Set logging.INFO to logging.DEBUG for debug information -logging.basicConfig(level=loglevel) -logging = logging.getLogger('AlkiraAPI') - ############################################### # Set default headers diff --git a/get.py b/get.py index 7f5bd97..0081619 100755 --- a/get.py +++ b/get.py @@ -27,9 +27,9 @@ import configparser import argparse # Parse all arguments -parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI") -parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf") -parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0") +parser = argparse.ArgumentParser(description="Get JSON config to AlkirAPI") +parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf)") +parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0)") try: args = parser.parse_args() @@ -48,6 +48,10 @@ except KeyError: ############################################### +# Set logging.INFO to logging.DEBUG for debug information +logging.basicConfig(level=loglevel) +logging = logging.getLogger('AlkiraAPI') + # Tenant config if not os.path.isfile(ALKIRA_CONFIG): logging.error(f"The config file {ALKIRA_CONFIG} doesn't exist") @@ -60,10 +64,6 @@ ALKIRA_USERNAME = alkira.get('alkira', 'ALKIRA_USERNAME') ALKIRA_PASSWORD = alkira.get('alkira', 'ALKIRA_PASSWORD') ALKIRA_BASE_URI = f'https://{ALKIRA_TENANT}/api' -# Set logging.INFO to logging.DEBUG for debug information -logging.basicConfig(level=loglevel) -logging = logging.getLogger('AlkiraAPI') - ############################################### # Set default headers diff --git a/push-debug.py b/push-debug.py index a1b5ea8..f36738e 100755 --- a/push-debug.py +++ b/push-debug.py @@ -27,10 +27,12 @@ import configparser import argparse # Parse all arguments -parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI") -parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf") +parser = argparse.ArgumentParser(description="Push JSON config to AlkirAPI (debug)") +parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnfi)") parser.add_argument("-f", "--file", type=str, help="location of the JSON connector file") parser.add_argument("-p", "--pretty", help="make the JSON pretty!", action="store_true") +parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0)") + if len(sys.argv)==1: parser.print_help(sys.stderr) sys.exit(1) @@ -44,8 +46,20 @@ except argparse.ArgumentError as e: print(str(e)) sys.exit() +try: + loglevel = { + 0: logging.INFO, + 1: logging.DEBUG + }[args.verbose] +except KeyError: + loglevel = logging.INFO + ############################################### +# Set loglevel (logging.INFO, logging.DEBUG) +logging.basicConfig(level=loglevel) +logging = logging.getLogger('AlkiraAPI') + # Tenant config if not os.path.isfile(ALKIRA_CONFIG): logging.error(f"The config file {ALKIRA_CONFIG} doesn't exist") diff --git a/push.py b/push.py index 194ab21..45f5629 100755 --- a/push.py +++ b/push.py @@ -27,11 +27,11 @@ import configparser import argparse # Parse all arguments -parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI") -parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf") -parser.add_argument("-f", "--folder", type=str, default='config', help="location of the JSON connector files (default: config") -parser.add_argument("-c", "--config", type=str, default='connectors.cnf', help="location of the connector config (default: config/connectors.cnf") -parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0") +parser = argparse.ArgumentParser(description="Push JSON config to AlkirAPI") +parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf)") +parser.add_argument("-f", "--folder", type=str, default='config', help="location of the JSON connector files (default: config)") +parser.add_argument("-c", "--config", type=str, default='connectors.cnf', help="location of the connector config (default: config/connectors.cnf)") +parser.add_argument("-v", "--verbose", type=int, default=0, help="Verbose level 0 or 1 (default: 0)") try: args = parser.parse_args() @@ -53,6 +53,10 @@ except KeyError: ############################################### +# Set loglevel (logging.INFO, logging.DEBUG) +logging.basicConfig(level=loglevel) +logging = logging.getLogger('AlkiraAPI') + # Tenant config if not os.path.isfile(ALKIRA_CONFIG): logging.error(f"The config file {ALKIRA_CONFIG} doesn't exist") @@ -71,10 +75,6 @@ if not os.path.isfile(CONNECTOR_CONFIG): config = configparser.ConfigParser() config.read(CONNECTOR_CONFIG) -# Set loglevel (logging.INFO, logging.DEBUG) -logging.basicConfig(level=loglevel) -logging = logging.getLogger('AlkiraAPI') - ############################################### # Set default headers diff --git a/validate-json.py b/validate-json.py index 56544d0..f23f31d 100755 --- a/validate-json.py +++ b/validate-json.py @@ -21,7 +21,7 @@ import json import argparse # Parse all arguments -parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI") +parser = argparse.ArgumentParser(description="Validate JSON config") parser.add_argument("-f", "--file", type=str, help="location of the JSON connector file") parser.add_argument("-p", "--pretty", help="make the JSON pretty!", action="store_true") if len(sys.argv)==1: