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.
 
 
 

162 lines
5.5 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
""" In diesem Modul werden alle Funktionen zusammengefasst zur Generierung und Ermittlung von pathsn """
import traceback
import tools.config_tool
import re
import basic.constants as B
import tools.path_const as P
import tools.date_tool
import model.catalog
TOOL_NAME = "value_tool"
DOM_JOB = "job"
DOM_PAR = "par"
DOM_COMP = "comp"
DOM_CONF = "conf"
DOM_ENV = "env"
DOM_CTLG = "ctlg"
class ValueConf:
"""
this class contains the structure-informations of the testrelevant directories
"""
__instance = None
def __init__(self, job=None):
#print('init pathConf')
confs = tools.config_tool.getConfig(job, "tool", "value", ttype="tool")
self.pattern = confs["pattern"]
#print(self.pattern)
ValueConf.__instance = self
@staticmethod
def getInstance(job = None):
#print("PathConf getInstance " + str(PathConf.__instance))
if (ValueConf.__instance is None):
ValueConf(job)
#print("PathConf getInstance " + str(PathConf.__instance))
return ValueConf.__instance
def get_key_value(job, key, comp=None):
"""
this function gets the value for the key which relates to an attribute in the job or in the component
:param key:
:param comp:
:return:
"""
try:
verify = job.getDebugLevel(TOOL_NAME)
except:
verify = False
#pt = PathConf.getInstance(job)
if verify: job.debug(verify, "getKeyValue " + key)
if DOM_JOB == key[0:3]:
a = key.split(".")
if len(a) > 1:
k = a[1]
else:
k = key
if DOM_PAR == k:
val = job.getParameter(a[2])
return val
elif DOM_CONF == k:
val = job.conf[B.TOPIC_PATH][a[2]]
if verify: job.debug(verify, val)
return val
elif len(a) == 2:
if not hasattr(job, a[1]):
job.m.setError("key, job has not attribute "+a[1])
return ""
val = getattr(job, a[1])
if a[1] == "start":
val = tools.date_tool.formatParsedDate(str(val), tools.date_tool.F_LOG)
return val
elif DOM_COMP in key:
if comp is None:
raise Exception(P.EXP_COMP_MISSING.format(key))
if tools.config_tool.hasAttr(comp.conf, key[5:]):
return tools.config_tool.getAttr(comp.conf, key[5:])
if tools.config_tool.hasAttr(comp, key[5:]):
return tools.config_tool.getAttr(comp, key[5:])
return ""
elif DOM_ENV + "." in key:
if key[4:] in comp["conn"]:
return comp["conn"][key[4:]]
pass
elif DOM_CTLG in key:
a = key.split(".")
catalog = model.catalog.Catalog.getInstance()
if len(a) == 3:
return catalog.getValue(job, a[1], a[2])
if len(a) == 4:
return catalog.getValue(job, a[1], a[2], a[3])
pass
elif "time" in key and hasattr(job, "start"):
return getattr(job, "start")
else:
vc = ValueConf.getInstance(job)
if key in vc.pattern:
return vc.pattern[key]
pc = P.PathConf.getInstance(job)
if key in pc.pattern:
return pc.pattern[key]
job.m.setError("key is not defined " + key)
return "xx-"+key+"-xx"
def compose_pattern(job, pattern, comp):
try:
if "{" in pattern and "}" in pattern:
return compose_string(job, pattern, comp)
vc = ValueConf.getInstance(job)
if pattern in vc.pattern:
return compose_string(job, "{" + pattern + "}", comp)
pc = P.PathConf.getInstance(job)
if pattern in pc.pattern:
return compose_string(job, "{" + pattern + "}", comp)
except Exception as e:
job.m.logError("Pattern konnte nicht aufgeloest werden " + pattern+ " " + str(e))
print("except "+traceback.format_exc())
return None
return None
def compose_string(job, pattern: str, comp) -> str:
"""
the function composes the pattern to the standardarized path with the attributes
which are stored in the job and the component
- the key of pathname is declared in path_const and the structure is configurated in config/value.yml.
:param pattern: - keyword surroundet with {}
:param comp:
:return: path
"""
try:
verify = job.getDebugLevel(TOOL_NAME)
except:
verify = False
verbose = False
max=5
l = re.findall('\{.*?\}', pattern)
#job.debug(verify, l)
if verbose: print("l: " + str(l))
for pat in l:
if verbose: print(str(max) + ": " + pattern + ": " + pat)
pit = get_key_value(job, pat[1:-1], comp)
if verbose: print(str(pit) + ": " + pattern + ": " + pat)
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
if pit is None:
print("replacement for " + pat + " is None")
pattern = pattern.replace(pat, pit)
while ("{" in pattern):
max = max-1
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
pattern = compose_string(job, pattern, comp)
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
if (max < 3) :
break
return pattern