moved logging config and fixed typos

This commit is contained in:
mischa 2022-06-17 16:01:23 +02:00
parent 4e11f462f7
commit d0021f9536
5 changed files with 40 additions and 26 deletions

View File

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

14
get.py
View File

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

View File

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

18
push.py
View File

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

View File

@ -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: