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.

291 lines
9.7 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
3 years ago
""" In diesem Modul werden alle Funktionen zusammengefasst zur Generierung und Ermittlung von pathsn """
2 years ago
import os.path
3 years ago
import sys
3 years ago
import basic.program
3 years ago
import utils.config_tool
import re
import basic.constants as B
2 years ago
import utils.path_const as P
3 years ago
2 years ago
TOOL_NAME = "path_tool"
3 years ago
def getHome():
home = os.getcwd()
if home[-4:] == "test" and home[-6:] != "datest":
home = home[0:-5]
if home[-10:] == "components":
home = home[0:-11]
if home[-6:] == "datest":
prgdir = home[-6:]
home = home[0:-7]
elif home[-7:] == "program":
prgdir = home[-7:]
home = home[0:-8]
return home
def getBasisConfigPath():
home = os.getcwd()
a = home.split(os.path.sep)
for i in range(0, len(a)):
path = os.path.sep.join(a[0:-i])
path = os.path.join(path, P.VAL_CONFIG, B.BASIS_FILE)
for format in utils.config_tool.CONFIG_FORMAT:
filepath = path+"."+format
if os.path.isfile(filepath):
return filepath
if os.path.exists(filepath):
return filepath
raise Exception("no basis-configuration found")
def getKeyValue(job, key, comp=None):
2 years ago
"""
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:
"""
#job = basic.program.Job.getInstance()
2 years ago
verify = job.getDebugLevel(TOOL_NAME)-4
pt = PathConf.getInstance(job)
job.debug(verify, "getKeyValue " + key)
3 years ago
if 'job.par' in key:
2 years ago
val = job.getParameter(key[8:])
return val
3 years ago
elif 'job.conf' in key:
2 years ago
val = job.conf.confs[B.SUBJECT_PATH][key[9:]]
job.debug(verify, val)
return val
3 years ago
# return job.conf.confs["paths"][key[9:]]
elif 'comp.' in key:
if comp is None:
2 years ago
raise Exception(P.EXP_COMP_MISSING.format(key))
if utils.config_tool.hasAttr(comp.conf, key[5:]):
return utils.config_tool.getAttr(comp.conf, key[5:])
if utils.config_tool.hasAttr(comp, key[5:]):
return utils.config_tool.getAttr(comp, key[5:])
return ""
elif 'env.' in key:
if key[4:] in comp.conf["conn"]:
return comp.conf["conn"][key[4:]]
pass
3 years ago
elif (pt.pattern):
return pt.pattern[key]
job.debug(verify, "pt exists")
3 years ago
else:
return "xx-"+key+"-xx"
def composePath(job, pathname, comp):
2 years ago
"""
this function composes a concrete path by the structured pathname
- the key of pathname is declared in path_const and the structure is configurated in config/path.yml.
:param pathname - plain keyword
:param comp:
:return:
"""
#job = basic.program.Job.getInstance()
2 years ago
verify = job.getDebugLevel(TOOL_NAME)
pt = PathConf.getInstance(job)
job.debug(verify, "composePath " + pathname + " zu " + str(pt) + "mit ")
job.debug(verify, str(pt.pattern))
3 years ago
if pt.pattern[pathname]:
return composePattern(job, pt.pattern[pathname], comp)
3 years ago
else:
job.debug(verify, "in Pattern nicht vorhanden: " + pathname)
3 years ago
def composePattern(job, pattern, comp):
2 years ago
"""
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/path.yml.
:param pattern: - keyword surroundet with {}
:param comp:
:return: path
"""
#job = basic.program.Job.getInstance()
2 years ago
verify = job.getDebugLevel(TOOL_NAME)
verbose = False
job.debug(verify, "composePattern " + pattern)
3 years ago
max=5
l = re.findall('\{.*?\}', pattern)
job.debug(verify, l)
3 years ago
for pat in l:
if verbose: print(str(max) + ": " + pattern + ": " + pat)
pit = getKeyValue(job, pat[1:-1], comp)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
3 years ago
pattern = pattern.replace(pat, pit)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
3 years ago
while ("{" in pattern):
max = max-1
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
pattern = composePattern(job, pattern, comp)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
3 years ago
if (max < 3) :
break
return pattern
2 years ago
def rejoinPath(a, b="", c="", d="", e="", f=""):
"""
this function concatenates the arguments to a path in the correct format for the operating-system
:param a:
:param b: optional
:param c: optional
:param d: optional
:param e: optional
:param f: optional
:return: path
"""
work = a+"/"+b+"/"+c+"/"+d+"/"+e+"/"+f
if a.find("://") > 1:
protocol = True
else:
protocol = False
work = re.sub(r'\\', '/', work)
work = re.sub(r'\/', '/', work)
work = re.sub(r'//', '/', work)
while work[-1:] == "/":
work = work[0:-1]
l = work.split("/")
out = ""
for x in l:
if len(x) < 1:
continue
if protocol:
if len(out) < 1:
out = x
else:
out = out+"/"+x
else:
out = os.path.join(out, x)
if out[1:2] == ":" and out[2:3] != "\\":
out = out[0:2]+"\\"+out[2:]
elif protocol:
if "://" not in out or out.index("://") > 8 or out.index("://") < 1:
i = out.index(":/")
out = out[0:i+1] + "/" + out[i+1:]
pass
if not protocol and out.count("\\") < 1 and out[0:1] != "/" and out[0:2] != "..":
out = "/"+out
return out
def extractPattern(job, pathtyp, comp=None):
2 years ago
"""
this function extracts recoursively all parts of the pathstrucure as key and gets the values from the
job-parameter and job-configuration
:param pathtyp: the name of the path-structure
:param comp:
:return: dictionary of all part (key) with their valuess
"""
#job = basic.program.Job.getInstance()
2 years ago
verify = job.getDebugLevel(TOOL_NAME)
3 years ago
out = []
pt = PathConf.getInstance(job)
3 years ago
pattern = pt.pattern[pathtyp]
work = pattern
while "{" in work:
i = work.index("{")
j = work.index("}")
pre = work[0:i]
pat = work[i+1:j]
job.debug(verify, work + " von " + str(i) + "-" + str(j) + " pre " + pre + "pat " + pat)
pit = getKeyValue(job, pat, comp)
3 years ago
tup = (pre, pat, pit)
out.append(tup)
work = work[j+1:]
return out
def extractPath(job, pathtyp, path):
2 years ago
"""
this function extracts parts of a concrete structered path and stores the parts
as attributes into the actual job. So these attributes can read from the concrete
path instead of the related parameter-arguments.
It stores the values into the job-parameter
:param pathtyp: the structure of the concrete path
:param path: the concrete path - it should be the directory in the parameter of the job
:return:
"""
#job = basic.program.Job.getInstance()
patterlist = extractPattern(job, pathtyp)
2 years ago
verbose = False
2 years ago
work = path
3 years ago
i = 0
2 years ago
if verbose: print("-- extractPatternList -- " + pathtyp + ":" + str(patterlist))
3 years ago
for p in patterlist:
if len(p) < 1 : continue
3 years ago
delim = p[0]
key = p[1]
val = p[2]
nextdelim = ""
if i >= len(patterlist) - 1:
nextdelim = ""
else:
nextdelim = patterlist[i+1][0]
2 years ago
if verbose: print("xPath delim " + delim + " " + str(len(delim)) + ", " + nextdelim + " work " + work)
3 years ago
work = work[len(delim):]
2 years ago
if verbose: print("xPath key " + key + " i " + str(i) + " work " + work)
3 years ago
if val is not None:
2 years ago
if verbose: print("val not none " + val)
3 years ago
if val in work:
2 years ago
if verbose: print("val ok")
3 years ago
work = work.replace(val, "")
elif "time" in key and "job.par" in key:
prop = ""
if i < len(patterlist) - 1:
prop = work[0:work.index(nextdelim)]
else:
prop = work
key = key[8:]
2 years ago
if verbose: print("setprop " + key + " = " + prop)
3 years ago
if hasattr(job.par, key): delattr(job.par, key)
setattr(job.par, key, val)
else:
2 years ago
if verbose: print("val not not ok " + val + " zu " + key)
3 years ago
elif "job.par" in key:
prop = ""
if i < len(patterlist) - 1:
2 years ago
if verbose: print("job.par nextdelim " + nextdelim)
3 years ago
prop = work[0:work.index(nextdelim)]
else:
prop = work
key = key[8:]
2 years ago
if verbose: print("setprop " + key + " = " + prop)
3 years ago
if hasattr(job.par, key): delattr(job.par, key)
setattr(job.par, key, prop)
work = work.replace(prop, "")
else:
2 years ago
if verbose: print("val is none " + key)
3 years ago
i = i +1
class PathConf:
2 years ago
"""
this class contains the structure-informations of the testrelevant directories
"""
3 years ago
__instance = None
def __init__(self, job=None):
#print('init pathConf')
confs = utils.config_tool.getConfig(job, "tool", "path")
3 years ago
self.pattern = confs["pattern"]
#print(self.pattern)
3 years ago
PathConf.__instance = self
@staticmethod
def getInstance(job = None):
3 years ago
#print("PathConf getInstance " + str(PathConf.__instance))
if (PathConf.__instance is None):
PathConf(job)
3 years ago
#print("PathConf getInstance " + str(PathConf.__instance))
return PathConf.__instance