Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
5.0 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
2 years ago
import importlib
import os
# import basic.program
import basic.constants as B
3 years ago
# -------------------------------------------------
import tools.config_tool
3 years ago
def hasAttr(o, name):
if (isinstance(o, dict)):
if (name in o.keys()):
return True
elif (isinstance(o, list)):
print("hasAttr list " + str(type(o)))
3 years ago
elif hasattr(o, name):
return True
return False
def getAttr(o, name):
if (isinstance(o, dict)):
if (name in o.keys()):
return o[name]
elif (isinstance(o, list)):
print("getAttr c list " + str(type(o)))
elif hasattr(o, name):
return o.get(name)
3 years ago
"""
Toolmanager
"""
def getCompAttr(comp, topic, attr, table=""):
out = ""
print(topic + " " + attr + " " + str(comp))
if hasAttr(comp.conf[B.TOPIC_CONN], topic) and hasAttr(comp.conf[B.TOPIC_CONN][topic], attr):
return getAttr(comp.conf[B.TOPIC_CONN][topic], attr)
if len(table) > 1 and hasAttr(comp.conf[B.SUBJECT_ARTIFACT][topic], table) \
and hasAttr(comp.conf[B.SUBJECT_ARTIFACT][topic][table], attr):
return getAttr(comp.conf[B.SUBJECT_ARTIFACT][topic][table], attr)
if hasAttr(comp.conf[B.SUBJECT_ARTIFACT], topic) and hasAttr(comp.conf[B.SUBJECT_ARTIFACT][topic], attr):
print("attr " + attr + " vorhanden")
return getAttr(comp.conf[B.SUBJECT_ARTIFACT][topic], attr)
raise LookupError(topic + "." + attr + " is not set in comp " + comp.name)
def getTool(technicType, comp, job):
if technicType == B.TOPIC_NODE_DB:
return getDbTool(job, comp)
if technicType == B.TOPIC_NODE_CLI:
return getCliTool(job, comp)
if technicType == B.TOPIC_NODE_API:
return getApiTool(job, comp)
if technicType == B.TOPIC_NODE_FILE:
# TODO im Allgemeinen keine konrete Implementierung aufrufen,
# denn zu einer Komponente koennen unterschiedliche Dateien vorkommen
return getFileTool(job, comp, "")
3 years ago
# class ToolManager:
def getDbTool(job, comp, dbtype=""):
3 years ago
verify = int(job.getDebugLevel("db_tool"))
2 years ago
if len(dbtype) < 3:
dbtype = getCompAttr(comp, B.TOPIC_NODE_DB, B.ATTR_TYPE, "")
toolname = "db" + dbtype + "_tool"
filepath = os.path.join(job.conf[B.TOPIC_PATH][B.ATTR_PATH_PROGRAM], "tools", toolname + ".py")
# comp.m.debug(verify, "toolname "+filepath)
3 years ago
if not os.path.exists(filepath):
raise FileNotFoundError("dbi for tool " + toolname + " does not exist " + filepath)
cmodul = importlib.import_module("tools." + toolname)
3 years ago
class_ = getattr(cmodul, "DbFcts")
c = class_()
c.setComp(job, comp)
3 years ago
return c
def getCliTool(job, comp):
3 years ago
verify = int(job.getDebugLevel("db_tool"))
clitype = getCompAttr(comp, B.TOPIC_NODE_CLI, B.ATTR_TYPE, "")
toolname = "cli" + clitype + "_tool"
filepath = os.path.join(job.conf[B.TOPIC_PATH][B.ATTR_PATH_PROGRAM], "tools", toolname + ".py")
# comp.m.debug(verify, "toolname "+filepath)
3 years ago
if not os.path.exists(filepath):
raise FileNotFoundError("file for tool " + toolname + " does not exist " + filepath)
cmodul = importlib.import_module("tools." + toolname)
3 years ago
class_ = getattr(cmodul, "CliFcts")
c = class_()
c.setComp(job, comp)
3 years ago
return c
def getApiTool(job, comp):
verify = int(job.getDebugLevel("db_tool"))
apitype = getCompAttr(comp, B.TOPIC_NODE_API, B.ATTR_TYPE, "")
toolname = "api" + apitype + "_tool"
filepath = os.path.join(job.conf[B.TOPIC_PATH][B.ATTR_PATH_PROGRAM], "tools", toolname + ".py")
# comp.m.debug(verify, "toolname "+filepath)
if not os.path.exists(filepath):
raise FileNotFoundError("file for tool " + toolname + " does not exist " + filepath)
cmodul = importlib.import_module("tools." + toolname)
class_ = getattr(cmodul, "ApiFcts")
c = class_()
c.setComp(job, comp)
return c
2 years ago
def getFileTool(job, comp, filenode=""):
verify = int(job.getDebugLevel("file_tool"))
if len(filenode) > 3 and "." in filenode and filenode[-1:] != ".":
filetype = tools.config_tool.getAttribute(comp, filenode, B.ATTR_ARTS_TYPE, job)
elif len(filenode) > 2 and len(filenode) < 5:
filetype = filenode
else:
filetype = getCompAttr(comp, B.TOPIC_NODE_FILE, B.ATTR_TYPE, "")
toolname = "file" + filetype + "_fcts"
filepath = os.path.join(job.conf[B.TOPIC_PATH][B.ATTR_PATH_PROGRAM], "tools", toolname + ".py")
# comp.m.debug(verify, "toolname "+filepath)
2 years ago
if not os.path.exists(filepath):
raise FileNotFoundError("file for tool " + toolname + " does not exist " + filepath)
cmodul = importlib.import_module("tools." + toolname)
2 years ago
class_ = getattr(cmodul, "FileFcts")
c = class_()
c.setComp(job, comp)
return c