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.

158 lines
5.3 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 tools.config_tool
import re
import basic.constants as B
import tools.path_const as P
import tools.date_tool
import model.catalog
2 years ago
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")
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(".")
2 years ago
if len(a) > 1:
k = a[1]
else:
k = key
if DOM_PAR == k:
val = job.getParameter(a[2])
return val
2 years ago
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:
job.m.logError("Pattern konnte nicht aufgeloest werden " + pattern)
return None
return None
def compose_string(job, pattern, comp):
"""
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
2 years ago
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)
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