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.
 
 
 

164 lines
6.2 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import sys
import basic.constants as B
try:
import basic.program
except ImportError:
print("ImportError: " + str(ImportError.with_traceback()))
pass
import basic.componentHandling
import utils.path_tool
import utils.file_tool
import os.path
import basic.constants as B
import utils.data_const as D
COMP_FILES = [D.DDL_FILENAME]
CONFIG_FORMAT = [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV]
def getConfigPath(modul, name, subname=""):
"""
gets the most specified configuration of different sources
Parameter:
* typ -- (basic, comp, tool)
* name -- the specific class
sources:
* programm <<
* install <<
* environ << basis-conf
* release << basis-conf
* testset << parameter/environ
* testcase << parameter
the parameter-files could be one of these file-types:
* yaml, json, csv
"""
job = basic.program.Job.getInstance()
verify = job.getDebugLevel("config_tool")-4
job.debug(verify, "getConfig " + modul + ", " + name)
#TODO path rejoin, config as const
if modul == "tool":
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("home") , "config" ,"tool_"+name+"."+format)
job.debug(verify, "1 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "utils", "config", name+"."+format)
job.debug(verify, "2 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("environment"), job.par.environment, "config", "tool_"+ name+"."+format)
job.debug(verify, "3 " + pathname)
if os.path.exists(pathname):
return pathname
job.debug(verify, "3x " + pathname)
elif modul == "comp":
pathname = job.conf.confs.get("paths").get("home") + "/configs/comp_" + name + ".yml"
job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
pathname = job.conf.confs.get("paths").get("program") + "/components/" + basic.componentHandling.getComponentFolder(name) + "/CONFIG.yml"
job.debug(verify, "5 " + pathname)
if os.path.exists(pathname):
return pathname
job.debug(verify, "6 " + pathname)
elif modul in COMP_FILES:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components",
basic.componentHandling.getComponentFolder(name), modul+"."+format)
if os.path.exists(pathname):
return pathname
if len(subname) > 1:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components",
basic.componentHandling.getComponentFolder(name), subname+"."+format)
if os.path.exists(pathname):
return pathname
else:
pathname = utils.path_tool.composePath("tcparfile")
job.debug(verify, "7 " + pathname)
if os.path.exists(pathname):
return pathname
pathname = utils.path_tool.composePath("tsparfile")
job.debug(verify, "8 " + pathname)
if os.path.exists(pathname):
return pathname
pathname = job.conf.confs.get("paths").get("release") + "/configs/basis.yml"
job.debug(verify, "9 " + pathname)
if os.path.exists(pathname):
return pathname
pathname = job.conf.confs.get("paths").get("environment") + "/configs/basis.yml"
job.debug(verify, "10 " + pathname)
if os.path.exists(pathname):
return pathname
pathname = job.conf.confs.get("paths").get("home") + "/config/basis.yml"
job.debug(verify, "11 " + pathname)
if os.path.exists(pathname):
return pathname
job.debug(verify, "12 " + pathname)
def getConfValue(attribute, comp):
if attribute == B.ATTR_CONN_DBTYPE:
if not hasAttr(comp.conf[B.SUBJECT_CONN], "dbtype"):
if hasAttr(comp.conf[B.SUBJECT_CONN], "types") and hasAttr(comp.conf[B.SUBJECT_CONN]["types"], "dbtype"):
dbtype = comp.conf[B.SUBJECT_CONN]["types"]["dbtype"]
else:
raise LookupError("dbtype is not set in comp " + comp.name)
else:
dbtype = comp.conf["conn"]["dbtype"]
return ""
return ""
def getAttr(o, name):
#print("hasAttr " + str(type(o))+" "+name)
if (isinstance(o, dict)):
if (name in o.keys()):
#print("hasAttr dict ok " + str(type(o)))
return o[name]
#print("hasAttr dict "+str(type(o)))
elif (isinstance(o, list)):
pass
#print("hasAttr list "+str(type(o)))
elif hasattr(o, name):
#print("hasAttr class ok "+str(type(o)))
return getattr(o, name)
return False
def hasAttr(o, name):
#print("hasAttr " + str(type(o))+" "+name)
if (isinstance(o, dict)):
if (name in o.keys()):
#print("hasAttr dict ok " + str(type(o)))
return True
#print("hasAttr dict "+str(type(o)))
elif (isinstance(o, list)):
pass
#print("hasAttr list "+str(type(o)))
elif hasattr(o, name):
#print("hasAttr class ok "+str(type(o)))
return True
return False
def getConfig(modul, name, subname=""):
job = basic.program.Job.getInstance()
verify = job.getDebugLevel("config_tool")-4
msg = None
if hasattr(job, "m"): msg = job.m
pathname = getConfigPath(modul, name, subname)
confs = {}
job.debug(verify, "getConfig " + pathname)
if len(pathname) < 1:
return confs
doc = utils.file_tool.readFileDict(pathname, msg)
for i, v in doc.items():
confs[i] = v
return confs