diff --git a/.gitignore b/.gitignore index 4aa1d16..d0dff54 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ instance doc venv lib - +reste diff --git a/basic/catalog.py b/basic/catalog.py index 3a02493..0ee1f33 100644 --- a/basic/catalog.py +++ b/basic/catalog.py @@ -94,9 +94,9 @@ class Catalog: if pathname is None: raise Exception(EXP_KEY_MISSING, (domain)) if pathname[-4:] == ".csv": - data = utils.tdata_tool.getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_KEYS) + data = utils.tdata_tool.getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_KEYS) else: - data = utils.file_tool.readFileDict(pathname, job.m) + data = utils.file_tool.readFileDict(job, pathname, job.m) self.catalog[domain] = data[B.DATA_NODE_TABLES][domain][B.DATA_NODE_KEYS] return data diff --git a/basic/compexec.py b/basic/compexec.py index f218d2f..420de1f 100644 --- a/basic/compexec.py +++ b/basic/compexec.py @@ -51,10 +51,10 @@ import utils.tdata_tool import basic.constants as B import basic.text_const as T import utils.data_const as D - +import utils.path_const as P class Testexecuter(): - def prepare_system(self, granularity): + def prepare_system(self, job, granularity): """ In order to preparate the test system test data should be cleaned and loaded with actual data. This can happen on different granularities: for each testcase or for each test sequences or for a test set or @@ -62,7 +62,7 @@ class Testexecuter(): The loaded test data should be selected for a later comparison. :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.reset_TData(granularity) @@ -70,14 +70,14 @@ class Testexecuter(): self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) pass - def reset_TData(self, granularity): + def reset_TData(self, job, granularity): """ the testdata in the component of the testsystem will be resetted correponding with the configuration of the componend :param granularity: :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() started at " + datetime.now().strftime("%Y%m%d_%H%M%S")+" for " + str(self.name).upper()) @@ -96,7 +96,7 @@ class Testexecuter(): self.m.setMsg("resetInstance for " + self.name + " is OK") self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) - def load_TData(self, granularity, tdata): + def load_TData(self, job, granularity, tdata): """ the testdata will be loaded into the componend especially into databses or with import-functions of the component @@ -104,7 +104,7 @@ class Testexecuter(): :param testdata: :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) for node in [B.TOPIC_NODE_DB, B.TOPIC_NODE_CLI, B.TOPIC_NODE_FILE, B.TOPIC_NODE_API]: @@ -112,7 +112,7 @@ class Testexecuter(): if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS] and B.DATA_NODE_TABLES in tdata: for t in tdata[B.DATA_NODE_TABLES]: print (t) - if utils.db_abstract.isCompTable(self, tdata, t): + if utils.db_abstract.isCompTable(self, job, tdata, t): self.m.logInfo("insert content "+ self.name) dbi = basic.toolHandling.getDbTool(job, self) dbi.insertTables(tdata, job) @@ -120,23 +120,23 @@ class Testexecuter(): self.m.setMsg("data loaded for " + self.name + " is OK") self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) - def collect_TcArtifacts(self): + def collect_TcArtifacts(self, job): """ collects the artifacts from the test-system. the result is written as original in subfolder {tsorigin} :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) - self.read_TData("nachher", B.PAR_TESTCASE) + self.read_TData(job, utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE) - def read_TData(self, subdir, granularity): + def read_TData(self, job, subdir, granularity): """ :param granularity: :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]: @@ -149,7 +149,7 @@ class Testexecuter(): data[B.DATA_NODE_TABLES] = {} data[B.DATA_NODE_TABLES][t] = data[subdir][t] utils.tdata_tool.writeCsvData( - utils.path_tool.rejoinPath(utils.path_tool.composePattern("{tcresult}", self), subdir, t+".csv"), + utils.path_tool.rejoinPath(utils.path_tool.composePattern(job, "{tcresult}", self), subdir, t+".csv"), data, self, job) if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("check lob if is deleted with flaskdb "+ self.name) @@ -157,10 +157,10 @@ class Testexecuter(): self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) - def composeFileClauses(self, pattern): - job = basic.program.Job.getInstance() + def composeFileClauses(self, job, pattern): + #job = basic.program.Job.getInstance() out = {} - attr = utils.db_abstract.getDbAttributes(self, "null") + attr = utils.db_abstract.getDbAttributes(self, job, "null") while "{" in pattern: pre = pattern[0:pattern.index("{")] pat = pattern[pattern.index("{"):pattern.index("}")] @@ -194,15 +194,15 @@ class Testexecuter(): return out return out - def composeSqlClauses(self, sql): - job = basic.program.Job.getInstance() + def composeSqlClauses(self, job, sql): + #job = basic.program.Job.getInstance() out = {} print("-------- composeSqlClauses "+sql) table = sql[sql.upper().index(" FROM ")+6:].strip() print("table "+table) sql_new = sql[0:sql.upper().index(" FROM ")+5] print("sql_new "+sql_new) - attr = utils.db_abstract.getDbAttributes(self, table) + attr = utils.db_abstract.getDbAttributes(self, job, table) if attr[B.ATTR_DB_TABNAME] != "": table = attr[B.ATTR_DB_TABNAME] if attr[B.ATTR_DB_SCHEMA] != "": @@ -232,17 +232,17 @@ class Testexecuter(): print("---> out "+str(out)) return out - def test_System(self, granularity): + def test_System(self, job, granularity): """ :param granularity: :return: """ - def create_Request(self, granularity): + def create_Request(self, job, granularity): pass - def send_Request(self, granularity): + def send_Request(self, job, granularity): pass - def get_Response(self, granularity): + def get_Response(self, job, granularity): pass def execute_test(self, job, step, tdata): @@ -271,19 +271,19 @@ class Testexecuter(): print("nichts da") - def finish_Test(self, granularity): + def finish_Test(self, job, granularity): """ initialization-routine for finish-step :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("something in "+ self.name) self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) - def collect_system(self, granularity): + def collect_system(self, job, granularity): """ After the test the test data of each component should be selected again - to get the post-condition. In each component is configured how these data can be collected. @@ -292,14 +292,14 @@ class Testexecuter(): """ pass - def collect_TcArtifact(self, granularity): + def collect_TcArtifact(self, job, granularity): """ collects the artifacts from the test-system. the result is written as original in subfolder {tcorigin} post: a further contact zo the test-system is not necessary :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("get files in for "+ self.name + " in " + self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_LOG]["path"]) @@ -312,13 +312,13 @@ class Testexecuter(): self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) - def split_TcResult(self, granularity): + def split_TcResult(self, job, granularity): """ transforms the result from subfolder {tcorigin}. the result is written as utf-8-readable parts in subfolder {tcparts} :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() "+str(self.name)) if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: @@ -330,18 +330,18 @@ class Testexecuter(): if B.ATTR_ARTS_FILE in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("tidy files in for "+self.name+" in "+self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_FILE]["format"]) - def fix_TcResult(self, granularity): + def fix_TcResult(self, job, granularity): """ fixes the result which is collected and transformed from the test-system. the result is written in comparable form in folder {tcresult} with the identifiable name - like in target :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) - def compare_results(self, report): + def compare_results(self, job, report): """ to compare the actual result with the target result has three steps: 1 matching each element so you get a comparable pair @@ -349,11 +349,11 @@ class Testexecuter(): 3 rating the difference if this can be accepted :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) cm = basic.componentHandling.ComponentManager.getInstance() data = {} - matching = utils.match_tool.Matching() + matching = utils.match_tool.Matching(job, self) if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]: for t in self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]: if t in B.LIST_DB_ATTR: @@ -367,17 +367,18 @@ class Testexecuter(): comp = cm.getComponent(a[0]) else: comp = self - path = os.path.join(utils.path_tool.composePattern( + path = os.path.join(utils.path_tool.composePattern(job, "{"+M.MATCH[M.MATCH_SIDE_POSTACTUAL][M.M_FILEPATTERN]+"}", comp), a[1]+".csv") pass elif side == M.MATCH_SIDE_TESTCASE: if hasattr(job.par, "testcase_example"): - path = os.path.join(utils.path_tool.composePattern( + path = os.path.join(utils.path_tool.composePattern(job, "{"+M.MATCH[M.MATCH_SIDE_POSTEXPECT][M.M_FILEPATTERN]+"}", self), t+".csv") path.replace(getattr(job.par, B.PAR_TESTCASE), getattr(job.par, "testcase_example")) else: - path = os.path.join(utils.path_tool.composePattern("{" + M.MATCH[side][M.M_FILEPATTERN] + "}", self), t + ".csv") - filedata = utils.tdata_tool.readCsv(self.m, path, self) + path = os.path.join(utils.path_tool.composePattern(job, + "{" + M.MATCH[side][M.M_FILEPATTERN] + "}", self), t + ".csv") + filedata = utils.tdata_tool.readCsv(self.m, job, path, self) data[side] = M.MATCH[side] data[side]["path"] = path data[side]["data"] = filedata @@ -387,9 +388,9 @@ class Testexecuter(): report.setPaths(job.par.testcase, self.name, t, type, matching.matchfiles["A"], matching.matchfiles["B"]) text = utils.match_tool.matchTree(matching) report.setMatchResult(job.par.testcase, self.name, t, type, matching.cssClass, matching.diffText) - path = os.path.join(utils.path_tool.composePattern("{tcresult}", self), + path = os.path.join(utils.path_tool.composePattern(job, "{tcresult}", self), t+"_"+M.MATCH[type]["filename"]+".html") - utils.file_tool.writeFileText(self.m, path, text) + utils.file_tool.writeFileText(self.m, job, path, text) # write text pass pass diff --git a/basic/component.py b/basic/component.py index 4bd9296..9df6a0a 100644 --- a/basic/component.py +++ b/basic/component.py @@ -11,6 +11,7 @@ from datetime import datetime import basic.compexec import basic.message import basic.program +import basic.constants as B import inspect @@ -31,7 +32,7 @@ class Component(basic.compexec.Testexecuter): During a test-run the component must be checked, prepared, appfiles has to be collected, etc. For this doing there are some standard-methods implemented. """ - def init(self): + def init(self, job): """ The range of the test-system is defined by the dependancy graph which starts at the application.and indate each component. By this way it is possible to use the same component in different test-systems and so the @@ -41,52 +42,52 @@ class Component(basic.compexec.Testexecuter): it is controlled by their configuration """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) - def run(self): - job = basic.program.Job.getInstance() + def run(self, job): + #job = basic.program.Job.getInstance() if job.program == "check_environment": self.check_Instance() elif job.program == "init_testset": - self.prepare_system("testset") + self.prepare_system(job, B.PAR_TESTSUITE) elif job.program == "init_testcase": - self.prepare_system(B.PAR_TESTCASE) + self.prepare_system(job, B.PAR_TESTCASE) elif job.program == "test_system": - self.test_System("test") + self.test_System(job, "test") elif job.program == "test_system": - self.test_System("test") + self.test_System(job, "test") elif job.program == "finish_testcase": - self.finish_Test("test") + self.finish_Test(job, B.PAR_TESTCASE) elif job.program == "finish_testset": - self.finish_Test("test") + self.finish_Test(job, B.PAR_TESTSUITE) - def collect_TcResult(self): + def collect_TcResult(self, job): """ collects the result from the folder {tcresult}. the content is stored intern for comparison :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.logInfo("get files in for " + self.name + " in tcresult ") self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) - def collect_Expect(self): + def collect_Expect(self, job): """ pre: only for components which be collected at the end of the test-set collects the result from the folder {rsresult}. post: a further contact zo the test-system is not necessary :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) - def compare_TcResults(self): + def compare_TcResults(self, job): """ compares the result with the target (1) the elements of both sides are assigned @@ -96,7 +97,7 @@ class Component(basic.compexec.Testexecuter): (5) the summary result is returned :return: """ - job = basic.program.Job.getInstance() + # job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) @@ -111,6 +112,7 @@ class Component(basic.compexec.Testexecuter): :param tg: :return: """ + pass def report_TcResults(self): """ reports the result-code @@ -128,25 +130,25 @@ class Component(basic.compexec.Testexecuter): :return: """ pass - def split_TsResult(self): + def split_TsResult(self, job): """ transforms the result which is collected from the test-system. the result is written as utf-8-readable parts in the specific subfolder {tcparts} the relevant testcases will be called :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) # for tc in testcases: # self.fix_TcResult(self) - def compare_TsResults(self): + def compare_TsResults(self, job): """ controles the comparison the result with the target :return: """ - job = basic.program.Job.getInstance() + # job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) # for tc in testcases: @@ -154,14 +156,14 @@ class Component(basic.compexec.Testexecuter): # self.collect_Target # self.compare_TcResults - def report_TsResults(self): + def report_TsResults(self, job): """ (1.2) extraction of diff-files (only not accepted differences) as html-file in test-set - result-report - (2.3) visualization of final result-code of each component and each testcase in test-set - result-report - (2.4) visualization of statistical result-codes of each component and each test-set in test-context - result-report - :return: """ - job = basic.program.Job.getInstance() + # job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) reportheader = '' @@ -199,8 +201,8 @@ class Component(basic.compexec.Testexecuter): """ pass - def declare_Target(self): - job = basic.program.Job.getInstance() + def declare_Target(self, job): + #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("something in "+ self.name) diff --git a/basic/componentHandling.py b/basic/componentHandling.py index a371ce8..f2ee633 100644 --- a/basic/componentHandling.py +++ b/basic/componentHandling.py @@ -48,8 +48,8 @@ def getInstanceAttributes(conf): return out -def getComponents(mainfct): - job = basic.program.Job.getInstance() +def getComponents(job, mainfct): + #job = basic.program.Job.getInstance() verify = -2 + job.getDebugLevel("job_tool") job.debug(verify, "getComponents " + mainfct) out = [] @@ -67,11 +67,12 @@ class ComponentManager: initializes the Manager with all necessary components """ - def __init__(self): - job = basic.program.Job.getInstance() + def __init__(self, job, option=""): + #job = basic.program.Job.getInstance() job.m.logDebug("applicationscomponente -- " + str(type(job.par))) self.components = {} self.comps = {} + self.job = job ComponentManager.__instance = self print ("init ComponentHandling "+str(self)) @@ -79,7 +80,7 @@ class ComponentManager: def initComponents(self): # sets components the first time # afterwards set components from parameter-file - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() anw = job.par.application job.m.logDebug("applicationscomponente -- " + str(type(job.par))) if not job.conf.confs[B.SUBJECT_APPS].get(anw): @@ -93,14 +94,8 @@ class ComponentManager: self.createComponent(k, 0, "") - def setComponents(self): - # set components from parameter-file - job = basic.program.Job.getInstance() - job.m.logDebug("applicationscomponente -- " + str(type(job.par))) - - def getComponent(self, compobjname): - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() verify = -2 + job.getDebugLevel("job_tool") job.debug(verify, "getComponents " + compobjname) if compobjname in self.comps: @@ -109,7 +104,7 @@ class ComponentManager: def getComponents(self, mainfct): - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() verify = -2 + job.getDebugLevel("job_tool") job.debug(verify, "getComponents " + mainfct) out = [] @@ -142,12 +137,12 @@ class ComponentManager: :param suffix: suffix for specific context of the component :return: """ - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() verify = job.getDebugLevel("job_tool") componentName = componentName.lower() job.debug(verify, "createComponent " + componentName) - confs = utils.config_tool.getConfig("comp", componentName) - conns = utils.conn_tool.getConnections(componentName) + confs = utils.config_tool.getConfig(job, "comp", componentName) + conns = utils.conn_tool.getConnections(job, componentName) instAttr = getInstanceAttributes(confs) job.debug(verify, "createComponent -91- " + componentName + " : " + str(confs)) if nr > 0 and int(instAttr[B.ATTR_INST_CNT]) > 1: @@ -181,7 +176,7 @@ class ComponentManager: :param nr: number if component is multiple :return: instance of the component with all necessary attributes """ - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() cmodul = importlib.import_module(getComponentPath(compName)) class_ = getattr(cmodul, getComponentClass(compName)) c = class_() @@ -197,7 +192,7 @@ class ComponentManager: c.m = basic.message.Message(job, basic.message.LIMIT_DEBUG, "logTime", name) c.conf = utils.config_tool.mergeConn(c.m, confs["conf"], conns[i]) c.conf[B.SUBJECT_CONN] = conns[i] - c.init() + c.init(job) if parContent is not None: print("createComponent 5 a " + compName + " : " + str(parContent)) if B.SUBJECT_COMPS in parContent and compName in parContent[B.SUBJECT_COMPS]: @@ -209,7 +204,7 @@ class ComponentManager: for table in c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]: if table in B.LIST_DB_ATTR: continue - conf = utils.config_tool.getConfig(D.DDL_FILENAME, compName, table) + conf = utils.config_tool.getConfig(job, D.DDL_FILENAME, compName, table) if B.DATA_NODE_TABLES in conf and table in conf[B.DATA_NODE_TABLES]: c.conf[B.DATA_NODE_DDL][table] = conf[B.DATA_NODE_TABLES][table] elif table in conf: @@ -222,7 +217,7 @@ class ComponentManager: def createSubComponents(self, comp, nr, suffix): - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() verify = -2 + job.getDebugLevel("job_tool") job.debug(verify, "getComponents " + str(comp.conf[B.ATTR_INST_SUBCOMP])) for c in comp.conf[B.ATTR_INST_SUBCOMP].keys(): @@ -232,7 +227,7 @@ class ComponentManager: def getComponentDict(self): - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() verify = -2 + job.getDebugLevel("job_tool") job.debug(verify, "getComponents ") out = {} @@ -260,10 +255,10 @@ def getComponentPath(comp): return "components." + getComponentFolder(comp) + "." + getComponentModul(comp) -def getComponentDict(): - job = basic.program.Job.getInstance() - verify = -2 + job.getDebugLevel("job_tool") - job.debug(verify, "getComponents ") +def getComponentDict(job = None): + #job = basic.program.Job.getInstance() + #verify = -2 + job.getDebugLevel("job_tool") + #job.debug(verify, "getComponents ") out = {} for c in comps: out[comps[c].name] = {} diff --git a/basic/constants.py b/basic/constants.py index b13cb8a..29cb6c7 100644 --- a/basic/constants.py +++ b/basic/constants.py @@ -22,7 +22,7 @@ The constants desribes the keywords of the main datastructures, these are # ------------------------------------------------------------- # values and keywords -BASIS_FILE = "basis.yml" +BASIS_FILE = "basis" SVAL_YES = "y" SVAL_NO = "n" @@ -42,6 +42,8 @@ PAR_TCDIR = 'tcdir' """ definition of the directory of the testcase for logs and results """ PAR_XPDIR = 'xpdir' """ definition of the directory of expectation for comparing the testcase """ +PAR_WSDIR = "wsdir" +""" definition of the directory of the workspace """ PAR_TDTYP = 'tdtyp' PAR_TDSRC = 'tdsrc' PAR_TDNAME = 'tdname' diff --git a/basic/message.py b/basic/message.py index f4bef55..6189d84 100644 --- a/basic/message.py +++ b/basic/message.py @@ -149,7 +149,7 @@ class Message: self.debugfile.close() def setRc(self, rc, text): - job = basic.program.Job.getInstance() + job = self.job #basic.program.Job.getInstance() verify = -0+LIMIT_DEBUG self.debug(verify, "setRc " + str(rc) + " " + str(self.rc)+ "\n") if (int(rc) > self.rc): diff --git a/basic/program.py b/basic/program.py index 37f2cf5..e7fa783 100644 --- a/basic/program.py +++ b/basic/program.py @@ -20,9 +20,17 @@ import utils.date_tool import utils.path_tool import utils.file_tool import utils.config_tool +import test.constants as T jobdef = { + "webflask": { + "pardef": "", + "pfilesource": "", + "pfiletarget": "", + "basedir": "workbase", + "dirname": "workdir", + "logdir": "{job.par.debugs}/webflask/log_{time}.txt" }, "unit": { "pardef": "", "pfilesource": "", @@ -108,6 +116,72 @@ def setGlobal(): EXCP_CANT_POP = "cant pop this job from the instances" +DEFAULT_ARCHIV_DIR = T.DATA_PATH + "/lauf" +DEFAULT_GRAN = "ws" +DEFAULT_PRG = "webflask" +DEFAULT_GRAN = "ws" +DEFAULT_APP = "WEBFLASK" +DEFAULT_ENV = "Workspace" +DEFAULT_MODE = "test" +DEFAULT_TIME = "2022-08-29_17-29-59" + +def createJob(pprg="", pgran="", papp="", penv="", ptstamp="", pmode=""): + """ + this creates a Job-Object with the main arguments. + :param pprg: program-name + :param pgran: tc|ts| + :param papp: application + :param penv: environment + :param ptstamp: timestamp - part of specific testfolder + :param pmode: if it is a productive or development execution + :return: + """ + if len(pprg) < 1: + prgname = DEFAULT_PRG + else: + prgname = pprg + if len(pgran) < 1: + gran = DEFAULT_GRAN + else: + gran = pgran + if len(pgran) < 1: + gran = DEFAULT_GRAN + else: + gran = pgran + if len(papp) < 1: + app = DEFAULT_APP + else: + app = papp + if len(penv) < 1: + env = DEFAULT_ENV + else: + env = penv + if len(ptstamp) < 1: + tstamp = DEFAULT_TIME + else: + tstamp = ptstamp + if len(pmode) < 1: + mode = DEFAULT_MODE + else: + mode = pmode + if gran == "tc": + path = DEFAULT_ARCHIV_DIR + "/TC0001/" + tstamp + elif gran == "ts": + path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp + else: + path = T.DATA_PATH + "/workspace/" + + job = basic.program.Job(prgname) + # job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH + args = {"application": app, "environment": env, "modus": mode, gran + "time": tstamp, + gran + "dir": path, + "step": 1} + print(str(args)) + # "usecase": "TST001", "tstime": "2022-03-17_17-28"} + job.par.setParameterArgs(job, args) + return job + + class Job: __instance = None __instances = [] @@ -118,13 +192,13 @@ class Job: Job.__instance = self if Job.__instances is None: Job.__instances = [] - Job.pushInstance(self) - par = Parameter(program) + #Job.pushInstance(self) + par = Parameter(self, program) self.par = par print("prog-42 " + str(self.par.basedir)) - conf = Configuration(program) + conf = Configuration(self, program) self.conf = conf - appl = utils.config_tool.getConfig("basic", B.SUBJECT_APPS) + appl = utils.config_tool.getConfig(self, "basic", B.SUBJECT_APPS) print(appl) if appl is not None: self.conf.confs[B.SUBJECT_APPS] = appl[B.SUBJECT_APPS] @@ -139,59 +213,6 @@ class Job: self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) print("prog-50 " + str(self.par.basedir)) - @staticmethod - def popInstance(pjob=None): - """ pop and stop a subjob """ - if pjob is not None and Job.__instance is not None and Job.__instance != pjob: - raise Exception(B.EXP_CANT_POP) - # for guarantee that both the stack and the original variable is empty if one is empty - if len(Job.__instances) < 1: - Job.__instance = None - return None - if Job.__instance is None: - while len(Job.__instances) > 0: - Job.__instances.pop() - return None - if len(Job.__instances) == 1: - job = Job.__instance - job.stopJob(1) - Job.__instances.pop() - Job.__instance = None - return None - job = Job.__instances.pop() - if pjob is not None and job is not None and job != pjob: - Job.__instances.append(job) - Job.__instance = job - raise Exception(B.EXP_CANT_POP) - if len(Job.__instances) > 0: - topjob = Job.__instances.pop() - Job.__instances.append(topjob) - Job.__instance = topjob - else: - Job.__instance = None - return job - - - @staticmethod - def pushInstance(pjob): - """ push a new created subjob """ - if len(Job.__instances) > 0: - job = Job.__instances.pop() - if pjob is not None and job is not None and job != pjob: - Job.__instances.append(job) - Job.__instances.append(pjob) - Job.__instance = pjob - return pjob - - @staticmethod - def resetInstance(program): - job = Job.getInstance() - if job is not None: - job.stopJob(1) - Job.__instance = None - Job(program) - return Job.__instance - def setProgram(self, program): self.program = program @@ -206,15 +227,8 @@ class Job: setattr(self.par, "parstring", parstring) if not hasattr(self.par, jobdef[program]["dirname"]): setattr(self.par, jobdef[program]["dirname"], - utils.path_tool.composePattern("{"+basedir+"}", None)) - self.par.setParameterLoaded() - - @staticmethod - def getInstance(): - if (Job.__instance is not None): - return Job.__instance - else: - return None + utils.path_tool.composePattern(self, "{"+basedir+"}", None)) + self.par.setParameterLoaded(self) def startJob(self): @@ -223,10 +237,10 @@ class Job: logTime = self.start.strftime("%Y%m%d_%H%M%S") self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) print("prog-68 " + str(self.m.rc)) - self.par.setParameterLoaded() + self.par.setParameterLoaded(self) self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") self.m.debug(basic.message.LIMIT_INFO, "# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") - self.par.checkParameter() + self.par.checkParameter(self) def stopJob(self, reboot=0): @@ -250,7 +264,7 @@ class Job: cconf = basic.componentHandling.getComponentDict() output["par"] = self.par.__dict__ if len(cconf) < 1: - utils.file_tool.writeFileDict(self.m, parpath, output) + utils.file_tool.writeFileDict(self.m, self, parpath, output) return output[B.SUBJECT_COMPS] = {} for c in cconf: @@ -261,7 +275,7 @@ class Job: output[B.SUBJECT_COMPS][c][x] = cconf[c][x] if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]: cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx" - utils.file_tool.writeFileDict(self.m, parpath, output) + utils.file_tool.writeFileDict(self.m, self, parpath, output) def loadParameter(self): @@ -271,7 +285,7 @@ class Job: parpath = utils.path_tool.composePath(jobdef[self.program]["pfilesource"], None) if not os.path.join(parpath): return None - doc = utils.file_tool.readFileDict(parpath, self.m) + doc = utils.file_tool.readFileDict(self, parpath, self.m) for k in doc.keys(): output[k] = copy.deepcopy(doc[k]) return output @@ -349,13 +363,13 @@ class Job: # ------------------------------------------------------------------------------------------------------------------ class Parameter: print ("class Parameter") - def __init__ (self, program): + def __init__ (self, job, program): print ("# init Parameter for " + program) self.program = program self.basedir = "debugs" self.setBasedir(program) print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}") - if (program != "unit"): self.setParameter() + if (program not in ["unit", "webflask"] ): self.setParameter(job) def setBasedir(self, program): @@ -363,15 +377,18 @@ class Parameter: self.basedir = jobdef[program]["basedir"] if hasattr(self, jobdef[program]["dirname"]): utils.path_tool.extractPath(self.basedir, getattr(self, jobdef[program]["dirname"])) + elif self.basedir == "workbase": + home = utils.path_tool.getHome() + dirpath = os.path.join(home, "data", "workspace") + setattr(self, jobdef[program]["dirname"], dirpath) elif program != "unit": - dirpath = utils.path_tool.composePattern("{"+jobdef[program]["basedir"]+"}", None) + dirpath = utils.path_tool.composePattern(None, "{"+jobdef[program]["basedir"]+"}", None) setattr(self, jobdef[program]["dirname"], dirpath) else: self.basedir = "debugs" - def checkParameter(self): - job = Job.getInstance() + def checkParameter(self, job): print (f"Parameter initialisiert {self.program}") pardef = jobdef[job.program]["pardef"] for p in pardef.split(","): @@ -379,7 +396,7 @@ class Parameter: if len(p) > 1 and not hasattr(self, p): job.m.setFatal("Parameter " + p + " is not set!") - def setParameter(self): + def setParameter(self, job): """ 1. Programm -- implementiert in Main-Klasse 2. anwndung -- steuert zu pruefende System [ in basis_Config ] @@ -406,6 +423,7 @@ class Parameter: parser.add_argument('-r', '--release', action='store') parser.add_argument('-ts', '--'+B.PAR_TSDIR, action='store') parser.add_argument('-tc', '--'+B.PAR_TCDIR, action='store') + parser.add_argument('-ws', '--'+B.PAR_WSDIR, action='store') parser.add_argument('-rs', '--rsdir', action='store') parser.add_argument('-dt', '--tdtyp', action='store') # PAR_TDTYP parser.add_argument('-ds', '--tdsrc', action='store') # PAR_TDSRC @@ -419,7 +437,7 @@ class Parameter: # parser.add_argument('-t', '--typ', default='einzel', action='store') # parser.add_argument('-d', '--dir', action='store') args = parser.parse_args() - self.setParameterArgs(args) + self.setParameterArgs(job, args) def getDirParameter(self): @@ -430,8 +448,7 @@ class Parameter: return None - def setParameterArgs(self, args): - job = Job.getInstance() + def setParameterArgs(self, job, args): print("setParArgs " + str(type(args))) self.parstring = "python " + self.program if "dict" in str(type(args)): @@ -452,8 +469,8 @@ class Parameter: app2 = self.application - def setParameterLoaded(self): - job = Job.getInstance() + def setParameterLoaded(self, job): + #job = Job.getInstance() print("setParLoaded " ) readedPar = job.loadParameter() if readedPar is not None: @@ -476,35 +493,23 @@ class Parameter: # ------------------------------------------------------------------------------------------------------------------ class Configuration: - def __init__ (self, program): + def __init__ (self, job, program): self.program = program print (f"job initialisiert {self.program}") - if program == "unit": - if (os.path.exists(utils.path_tool.rejoinPath("..", "..", "config", B.BASIS_FILE))): - self.setConfiguration(utils.path_tool.rejoinPath("..", "..", "config", B.BASIS_FILE)) - return - if (os.path.exists(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))): - self.setConfiguration(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE)) - return - elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))): - self.setConfiguration(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE)) - return - elif (os.path.exists(utils.path_tool.rejoinPath("config", B.BASIS_FILE))): - self.setConfiguration(utils.path_tool.rejoinPath("config", B.BASIS_FILE)) - return - raise Exception(B.EXP_NO_BASIS_FILE) + path = utils.path_tool.getBasisConfigPath() + self.setConfiguration(job, path) + return - def setConfiguration(self, path): + def setConfiguration(self, job, path): self.confs = {} - doc = utils.file_tool.readFileLines(path, None) - with open(path, "r") as file: - doc = yaml.full_load(file) - if "basic" in doc: - for i, v in doc["basic"].items(): - self.confs[i] = v - else: - for i, v in doc.items(): - self.confs[i] = v + doc = utils.file_tool.readFileDict(job, path, None) + self.confs["configpath"] = path + if "basic" in doc: + for i, v in doc["basic"].items(): + self.confs[i] = v + else: + for i, v in doc.items(): + self.confs[i] = v def setConfig(self, path, val): a = path.split(".") diff --git a/basic/sysmonitor.py b/basic/sysmonitor.py index a8548ad..b8616c4 100644 --- a/basic/sysmonitor.py +++ b/basic/sysmonitor.py @@ -18,7 +18,7 @@ class SystemMonitor(): """ checks system-instances and writes it into the parameter-file """ - job = basic.program.Job.getInstance() + job = None #basic.program.Job.getInstance() verify = -1 + job.getDebugLevel(self.name) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime( "%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) diff --git a/basic/toolHandling.py b/basic/toolHandling.py index f930b26..c875973 100644 --- a/basic/toolHandling.py +++ b/basic/toolHandling.py @@ -72,7 +72,7 @@ def getDbTool(job, comp, dbtype=""): cmodul = importlib.import_module("utils."+toolname) class_ = getattr(cmodul, "DbFcts") c = class_() - c.setComp(comp) + c.setComp(job, comp) return c def getCliTool(job, comp): @@ -86,7 +86,7 @@ def getCliTool(job, comp): cmodul = importlib.import_module("utils."+toolname) class_ = getattr(cmodul, "CliFcts") c = class_() - c.setComp(comp) + c.setComp(job, comp) return c def getApiTool(job, comp): @@ -100,7 +100,7 @@ def getApiTool(job, comp): cmodul = importlib.import_module("utils."+toolname) class_ = getattr(cmodul, "ApiFcts") c = class_() - c.setComp(comp) + c.setComp(job, comp) return c def getFileTool(job, comp, filenode=""): diff --git a/check_environment.py b/check_environment.py index cd99b00..1a8ff40 100644 --- a/check_environment.py +++ b/check_environment.py @@ -22,7 +22,7 @@ if __name__ == '__main__': cm = basic.componentHandling.ComponentManager() print("cm "+str(cm)) cm.initComponents() - comps = cm.getComponents(PROGRAM_NAME) + comps = cm.getComponents(x, PROGRAM_NAME) x.m.setMsg("# Components initialized with these relevant components " + str(comps)) for c in comps: comp = cm.getComponent(c) diff --git a/collect_testcase.py b/collect_testcase.py index bb2d238..fb51796 100644 --- a/collect_testcase.py +++ b/collect_testcase.py @@ -18,9 +18,9 @@ PROGRAM_NAME = "collect_testcase" def startPyJob(job): cm = basic.componentHandling.ComponentManager.getInstance("init") cm.initComponents() - comps = cm.getComponents(PROGRAM_NAME) + comps = cm.getComponents(job, PROGRAM_NAME) print(" relevant components for this job: " + str(comps)) - tdata = utils.tdata_tool.getTestdata() + tdata = utils.tdata_tool.getTestdata(job) job.m.setMsg("# components initialized with "+str(comps)) for c in comps: comp = cm.getComponent(c) diff --git a/compare_testcase.py b/compare_testcase.py index 270e520..db907c3 100644 --- a/compare_testcase.py +++ b/compare_testcase.py @@ -20,24 +20,24 @@ import basic.message as message PROGRAM_NAME = "compare_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager("init") + cm = basic.componentHandling.ComponentManager(job, "init") print("cm "+str(cm)) cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) job.m.setMsg("# Components initialized with these relevant components " + str(comps)) - report = utils.report_tool.Report() - testdata = utils.tdata_tool.getTestdata() + report = utils.report_tool.Report(job) + testdata = utils.tdata_tool.getTestdata(job) for c in comps: comp = cm.getComponent(c) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") - comp.compare_results(report) + comp.compare_results(job, report) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") job.m.merge(comp.m) print(str(comp)) comp.conf["function"][PROGRAM_NAME] = comp.m.topmessage text = report.reportTestcase(job.par.testcase) path = os.path.join(job.par.tcdir, "Result.html") - utils.file_tool.writeFileText(job.m, path, text) + utils.file_tool.writeFileText(job.m, job, path, text) # Press the green button in the gutter to run the script. if __name__ == '__main__': diff --git a/execute_testcase.py b/execute_testcase.py index f025eb6..23cf495 100644 --- a/execute_testcase.py +++ b/execute_testcase.py @@ -22,12 +22,12 @@ import basic.message as message PROGRAM_NAME = "execute_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager(job) print("cm "+str(cm)) cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) job.m.setMsg("# Components initialized with these relevant components " + str(comps)) - tdata = utils.tdata_tool.getTestdata() + tdata = utils.tdata_tool.getTestdata(job) if not "_steps" in tdata: raise Exception("no steps to execute in testdata") for (step) in tdata["_steps"]: diff --git a/finish_testsuite.py b/finish_testsuite.py index 5a4d216..a2efdf4 100644 --- a/finish_testsuite.py +++ b/finish_testsuite.py @@ -22,15 +22,15 @@ def startPyJob(job): testinstances = getattr(job.par, "testinstances") for tc in testinstances: path = os.path.join(testinstances[tc], "Result.html") - text = utils.file_tool.readFileText(path, job.m) + text = utils.file_tool.readFileText(job, path, job.m) report.extractTestcase(tc, text) text = report.reportTestsuite() path = os.path.join(job.par.tsdir, "Result.html") - utils.file_tool.writeFileText(job.m, path, text) + utils.file_tool.writeFileText(job.m, job, path, text) archivFolder = job.conf.confs["paths"]["archiv"] tsFolder = os.path.join(archivFolder, "Testlauf") - tarfile = utils.zip_tool.openNewTarFile(tsFolder, job.par.usecase+"_"+job.par.tstime+".tar.gz") - utils.zip_tool.appendFolderIntoTarFile(tsFolder, job.par.usecase+"_"+job.par.tstime, tarfile) + tarfile = utils.zip_tool.openNewTarFile(job, tsFolder, job.par.usecase+"_"+job.par.tstime+".tar.gz") + utils.zip_tool.appendFolderIntoTarFile(job, tsFolder, job.par.usecase+"_"+job.par.tstime, tarfile) for tc in testinstances: tcSubFolder = testinstances[tc][len(archivFolder)+1:] utils.zip_tool.appendFolderIntoTarFile(archivFolder, tcSubFolder, tarfile) diff --git a/generate_testcases.py b/generate_testcases.py index 198f0a9..324fe0a 100644 --- a/generate_testcases.py +++ b/generate_testcases.py @@ -1,6 +1,6 @@ # https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/232-testfallgenerierung import random -#from flask import +#from webflask import # class Koeln(): # Konfig diff --git a/init_testcase.py b/init_testcase.py index f4b953a..4cfc600 100644 --- a/init_testcase.py +++ b/init_testcase.py @@ -19,21 +19,21 @@ import basic.message as message PROGRAM_NAME = "init_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager.getInstance("init") + cm = basic.componentHandling.ComponentManager.getInstance(job, "init") cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) job.m.setMsg("# Components initialized with these relevant components " + str(comps)) - testdata = utils.tdata_tool.getTestdata() + testdata = utils.tdata_tool.getTestdata(job) print("------------------------------------------------------------") for c in comps: comp = cm.getComponent(c) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") if job.hasFunction("reset_TData"): - comp.reset_TData(B.PAR_TESTCASE) + comp.reset_TData(job, B.PAR_TESTCASE) if job.hasFunction("load_TData"): - comp.load_TData(B.PAR_TESTCASE, testdata) + comp.load_TData(job, B.PAR_TESTCASE, testdata) if job.hasFunction("read_TData"): - comp.read_TData(utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE) + comp.read_TData(job, utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") job.m.merge(comp.m) print(str(comp)) diff --git a/init_testsuite.py b/init_testsuite.py index d31fd16..c3ec012 100644 --- a/init_testsuite.py +++ b/init_testsuite.py @@ -20,10 +20,10 @@ if __name__ == '__main__': x.stopJob() exit(x.m.rc * (-1) + 3) # now in theory the program is runnable - cm = ComponentManager() + cm = ComponentManager(x) cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) print(" relevant components for this job: " + str(comps)) - tdata = utils.tdata_tool.getTestdata() + tdata = utils.tdata_tool.getTestdata(x) x.stopJob() # See PyCharm help at https://www.jetbrains.com/help/pycharm/ diff --git a/start_dialog.py b/start_dialog.py index 413ca8b..9939628 100644 --- a/start_dialog.py +++ b/start_dialog.py @@ -74,7 +74,7 @@ def restartActualProcess(job): """ path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], JSON_FILE) if os.path.exists(path): - actProc = utils.file_tool.readFileDict(path) + actProc = utils.file_tool.readFileDict(job, path) jobNr = int(JOB_NR[actProc["job"]]["jobnr"]) question = "Prozess " choiceList = "" diff --git a/test/test_02css.py b/test/test_02css.py index bd340b8..4659c5e 100644 --- a/test/test_02css.py +++ b/test/test_02css.py @@ -22,61 +22,61 @@ class MyTestCase(unittest.TestCase): args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "modus": "unit"} - job.par.setParameterArgs(args) + job.par.setParameterArgs(job, args) # ------- inline --------------- job.conf.setConfig("tools.csstyp", "inline") job.conf.confs.get("tools")["csstyp"] == "inline" - text = utils.css_tool.getInlineStyle("diffFiles", "diffA") + text = utils.css_tool.getInlineStyle(job, "diffFiles", "diffA") self.assertEqual(len(text), 37) self.assertEqual(("style" in text), True) - text = utils.css_tool.getInlineStyle("diffFiles", "acceptA") + text = utils.css_tool.getInlineStyle(job, "diffFiles", "acceptA") self.assertEqual(len(text), 23) self.assertEqual(("style" in text), True) - text = utils.css_tool.getInlineStyle("resultFile", "result1") + text = utils.css_tool.getInlineStyle(job, "resultFile", "result1") self.assertEqual(len(text), 36) self.assertEqual(("style" in text), True) - text = utils.css_tool.getInternalStyle("diffFiles") + text = utils.css_tool.getInternalStyle(job, "diffFiles") self.assertEqual(len(text), 84) - text = utils.css_tool.getExternalStyle("diffFiles") + text = utils.css_tool.getExternalStyle(job, "diffFiles") self.assertEqual(len(text), 0) # ------- internal --------------- job.conf.setConfig("tools.csstyp", "internal") - text = utils.css_tool.getInlineStyle("diffFiles", "diffA") + text = utils.css_tool.getInlineStyle(job, "diffFiles", "diffA") self.assertEqual(len(text), 13) self.assertEqual(("class" in text), True) - text = utils.css_tool.getInlineStyle("resultFile", "result1") + text = utils.css_tool.getInlineStyle(job, "resultFile", "result1") self.assertEqual(len(text), 15) self.assertEqual(("class" in text), True) - text = utils.css_tool.getInternalStyle("diffFiles") + text = utils.css_tool.getInternalStyle(job, "diffFiles") if verbose: print(text) self.assertEqual(len(text), 262) self.assertEqual(("" return out -def getExternalStyle(filetype): - job = basic.program.Job.getInstance() +def getExternalStyle(job, filetype): + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 out = "" if job.conf.confs.get("tools").get("csstyp") == "external": diff --git a/utils/db_abstract.py b/utils/db_abstract.py index e088726..989b04d 100644 --- a/utils/db_abstract.py +++ b/utils/db_abstract.py @@ -265,7 +265,8 @@ class DbFcts(): self.comp = None pass - def setComp(self, comp): + def setComp(self, job, comp): + self.job = job self.comp = comp def getDbAttributes(self, table): @@ -355,7 +356,7 @@ class DbFcts(): the ddl are mostly stored as csv in the component-folder """ if (B.DATA_NODE_DDL in self.comp.conf): return - conf = utils.config_tool.getConfig(D.DDL_FILENAME, self.comp.name) + conf = utils.config_tool.getConfig(job, D.DDL_FILENAME, self.comp.name) self.comp.conf[B.DATA_NODE_DDL] = {} for k in conf[self.comp.name]: self.comp.conf[B.DATA_NODE_DDL][k] = conf[self.comp.name][k] diff --git a/utils/dbcsv_tool.py b/utils/dbcsv_tool.py index f52f23a..1757105 100644 --- a/utils/dbcsv_tool.py +++ b/utils/dbcsv_tool.py @@ -26,10 +26,10 @@ class DbFcts(utils.db_abstract.DbFcts): statement written in sql """ sqlTable = utils.db_abstract.getSqlTable(self.comp, table) header = "" - path = utils.path_tool.composePattern("{env.dompath}/"+sqlTable+".csv", self.comp) + path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp) print(path) tdata = {} - data = utils.tdata_tool.readCsv(self.comp.m, path, self.comp) + data = utils.tdata_tool.readCsv(self.comp.m, job, path, self.comp) tdata[B.DATA_NODE_HEADER] = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER] if B.DATA_NODE_TABLES in data \ and table in data[B.DATA_NODE_TABLES]\ @@ -46,12 +46,12 @@ class DbFcts(utils.db_abstract.DbFcts): verify = -1+job.getDebugLevel("db_tool") sqlTable = utils.db_abstract.getSqlTable(self.comp, table) header = "" - path = utils.path_tool.composePattern("{env.dompath}/"+sqlTable+".csv", self.comp) + path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp) for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]: print(h) header += ";"+h cmd = header[1:]+"\n" - utils.file_tool.writeFileText(self.comp.m, path, cmd) + utils.file_tool.writeFileText(self.comp.m, job, path, cmd) self.comp.m.logInfo(cmd) @@ -68,7 +68,7 @@ class DbFcts(utils.db_abstract.DbFcts): verify = -1+job.getDebugLevel("db_tool") sqlTable = utils.db_abstract.getSqlTable(self.comp, table) header = "" - path = utils.path_tool.composePattern("{env.dompath}/"+sqlTable+".csv", self.comp) + path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp) if len(rows) == 0: return "" else: @@ -96,14 +96,14 @@ class DbFcts(utils.db_abstract.DbFcts): rowvalues += ";"+str(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], "")) print("rv " + rowvalues) cmd += rowvalues+"\n" - utils.file_tool.writeFileText(self.comp.m, path, cmd) + utils.file_tool.writeFileText(self.comp.m, job, path, cmd) self.comp.m.logInfo(cmd) def getConnector(self): """ add-on-method to get the connector this method should only called by the class itself """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() return "" diff --git a/utils/dbmysql_tool.py b/utils/dbmysql_tool.py index 8023095..a95eec7 100644 --- a/utils/dbmysql_tool.py +++ b/utils/dbmysql_tool.py @@ -77,10 +77,10 @@ class DbFcts(utils.db_abstract.DbFcts): cmd = cmd[0:-1]+";" self.comp.m.logInfo(cmd) - def getConnector(self): + def getConnector(self, job): """ add-on-method to get the connector this method should only called by the class itself """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() mydb = mysql.connector.connect( host = "localhost", user = "datest", diff --git a/utils/dbrel_tool.py b/utils/dbrel_tool.py index 8023095..8091aa0 100644 --- a/utils/dbrel_tool.py +++ b/utils/dbrel_tool.py @@ -80,7 +80,7 @@ class DbFcts(utils.db_abstract.DbFcts): def getConnector(self): """ add-on-method to get the connector this method should only called by the class itself """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() mydb = mysql.connector.connect( host = "localhost", user = "datest", diff --git a/utils/dbsfile_tool.py b/utils/dbsfile_tool.py index 4d1866e..a7dde18 100644 --- a/utils/dbsfile_tool.py +++ b/utils/dbsfile_tool.py @@ -33,7 +33,7 @@ class DbFcts(utils.db_abstract.DbFcts): # attr = self.getDbAttributes(table) verify = -1+job.getDebugLevel("db_tool") pattern = "s3a://{hostname}/data/{tenant}/mt/sandboxes/{job.par.usecae}/{job.par.workspace}/{outfile}/VR_+reg+/" - files = self.comp.composeFileClauses(pattern) + files = self.comp.composeFileClauses(job, pattern) data = [] for k in files.keys(): sql = files[k] @@ -57,7 +57,7 @@ class DbFcts(utils.db_abstract.DbFcts): verify = -1+job.getDebugLevel("db_tool") cmd = "DELETE FROM "+table print("deleteRows "+cmd) - sqls = self.comp.composeSqlClauses(cmd) + sqls = self.comp.composeSqlClauses(job, cmd) print("deleteRows "+cmd) print(sqls) for k in sqls.keys(): @@ -74,7 +74,7 @@ class DbFcts(utils.db_abstract.DbFcts): """ method to insert rows into a database the rows will be interpreted by the ddl of the component """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = -1+job.getDebugLevel("db_tool") spark = self.getConnector() df = spark.createDataFrame(rows) @@ -84,7 +84,7 @@ class DbFcts(utils.db_abstract.DbFcts): def getConnector(self): """ add-on-method to get the connector this method should only called by the class itself """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() attr = self.getDbAttributes(B.SVAL_NULL) spark = None if B.ATTR_DB_CONN_JAR in attr: diff --git a/utils/dbshive_tool.py b/utils/dbshive_tool.py index a98e918..d3dd9be 100644 --- a/utils/dbshive_tool.py +++ b/utils/dbshive_tool.py @@ -34,7 +34,7 @@ class DbFcts(utils.db_abstract.DbFcts): verify = -1+job.getDebugLevel("db_tool") cmd = "SELECT "+",".join(self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]) cmd += " FROM "+table - sqls = self.comp.composeSqlClauses(cmd) + sqls = self.comp.composeSqlClauses(job, cmd) data = [] for k in sqls.keys(): sql = sqls[k] @@ -61,7 +61,7 @@ class DbFcts(utils.db_abstract.DbFcts): verify = -1+job.getDebugLevel("db_tool") cmd = "DELETE FROM "+table print("deleteRows "+cmd) - sqls = self.comp.composeSqlClauses(cmd) + sqls = self.comp.composeSqlClauses(job, cmd) print("deleteRows "+cmd) print(sqls) for k in sqls.keys(): @@ -78,7 +78,7 @@ class DbFcts(utils.db_abstract.DbFcts): """ method to insert rows into a database the rows will be interpreted by the ddl of the component """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = -1+job.getDebugLevel("db_tool") spark = self.getConnector() df = spark.createDataFrame(rows) @@ -88,7 +88,7 @@ class DbFcts(utils.db_abstract.DbFcts): def getConnector(self): """ add-on-method to get the connector this method should only called by the class itself """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() attr = self.getDbAttributes(B.SVAL_NULL) spark = None if B.ATTR_DB_CONN_JAR in attr: diff --git a/utils/dbspark_tool.py b/utils/dbspark_tool.py index fcb76d9..39fc77f 100644 --- a/utils/dbspark_tool.py +++ b/utils/dbspark_tool.py @@ -42,7 +42,7 @@ class DbFcts(utils.db_abstract.DbFcts): def deleteRows(self, table): """ method to delete rows from a database statement written in sql """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = -1+job.getDebugLevel("db_tool") cmd = "DELETE FROM "+table+";" self.comp.m.logInfo(cmd) @@ -51,7 +51,7 @@ class DbFcts(utils.db_abstract.DbFcts): """ method to insert rows into a database the rows will be interpreted by the ddl of the component """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = -1+job.getDebugLevel("db_tool") spark = self.getConnector() df = spark.createDataFrame(rows) @@ -61,7 +61,7 @@ class DbFcts(utils.db_abstract.DbFcts): def getConnector(self): """ add-on-method to get the connector this method should only called by the class itself """ - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() spark = pyspark.SparkSession\ .builder\ .appName("datest")\ diff --git a/utils/env_tool.py b/utils/env_tool.py index 1422248..5d1ab22 100644 --- a/utils/env_tool.py +++ b/utils/env_tool.py @@ -3,34 +3,34 @@ import utils.file_tool import basic.program -def importEnvProperty(): - job = basic.program.Job.getInstance() - path = utils.config_tool.getConfig("tool", "env") - props = utils.file_tool.readFileDict(path, job.m) +def importEnvProperty(job): + #job = basic.program.Job.getInstance() + path = utils.config_tool.getConfig(job, "tool", "env") + props = utils.file_tool.readFileDict(job, path, job.m) job.conf.confs["env"] = props["prop"] -def exportEnvProperty(): - job = basic.program.Job.getInstance() +def exportEnvProperty(job): + # job = basic.program.Job.getInstance() props = {} if not hasattr(job, "conf"): return if not hasattr(job.conf, "confs"): return if not "env" in job.confconfs: return props["prop"] = job.conf.confs["env"] - path = utils.config_tool.getConfig("tool", "env") - utils.file_tool.writeFileDict(job.m, path, props) + path = utils.config_tool.getConfig(job, "tool", "env") + utils.file_tool.writeFileDict(job.m, job, path, props) -def setEnvProp(props): - job = basic.program.Job.getInstance() - path = utils.config_tool.getConfig("tool", "env") - utils.file_tool.writeFileDict(job.m, path, props) +def setEnvProp(job, props): + # job = basic.program.Job.getInstance() + path = utils.config_tool.getConfig(job, "tool", "env") + utils.file_tool.writeFileDict(job.m, job, path, props) -def getEnvProperty(propname): - job = basic.program.Job.getInstance() +def getEnvProperty(job, propname): + # job = basic.program.Job.getInstance() if "env" not in job.conf.confs: - importEnvProperty() + importEnvProperty(job) prop = job.conf.confs[propname] if (prop["type"] == "succ"): val = prop["value"] diff --git a/utils/file_abstract.py b/utils/file_abstract.py index b63688f..31a918c 100644 --- a/utils/file_abstract.py +++ b/utils/file_abstract.py @@ -54,14 +54,14 @@ class FileFcts(): pattern = "" utils.file_tool.copyFiles(self.job, fileList, srcpath, envpath, pattern) - def readEnvFiles(self): + def readEnvFiles(self, job): envpath = "" pattern = "" - fileList = utils.file_tool.getFiles(self.comp.m, envpath, pattern, self.comp.conf["conn"]) + fileList = utils.file_tool.getFiles(self.comp.m, job, envpath, pattern, self.comp.conf["conn"]) # === execute_testcase === - def create_request(self, tdata, step): + def create_request(self, job, tdata, step): mapping = "" schema = "" archivpath = "" @@ -72,28 +72,28 @@ class FileFcts(): continue mapping = o["mapping"] schema = o["schema"] - archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/request", self.comp), filename) # ergebnisse/comp/request ) + archivpath = os.path.join(utils.path_tool.composePattern(job, "{tcresult}/request", self.comp), filename) # ergebnisse/comp/request ) #txt = self.createDict() - utils.file_tool.writeFileText(self.comp.m, archivpath, txt) + utils.file_tool.writeFileText(self.comp.m, job, archivpath, txt) def send_request(self, job, step): archivpath = "" filename = step.args["filename"] technique = step.args["technique"] - archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/request", self.comp), filename) + archivpath = os.path.join(utils.path_tool.composePattern(job, "{tcresult}/request", self.comp), filename) if technique == "cli": for o in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_FILE]: if o["name"] != filename: continue envpath = o["envpath"] - envpath = utils.path_tool.composePattern(envpath, self.comp) + envpath = utils.path_tool.composePattern(job, envpath, self.comp) fct = basic.toolHandling.getCliTool(job, self.comp) fct.copy(self.job, archivpath, envpath) elif technique == "api": - txt = utils.file_tool.readFileText(archivpath, self.comp.m) + txt = utils.file_tool.readFileText(job, archivpath, self.comp.m) fct = basic.toolHandling.getApiTool(job, self.comp) response = fct.send(self.job, self.comp, txt) - archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/response", self.comp), filename) + archivpath = os.path.join(utils.path_tool.composePattern(job, "{tcresult}/response", self.comp), filename) """ get_response: diff --git a/utils/file_tool.py b/utils/file_tool.py index 2ba563d..3d5237c 100644 --- a/utils/file_tool.py +++ b/utils/file_tool.py @@ -26,7 +26,7 @@ def getDump(obj): # if type(obj) == "__dict__" -def getFiles(msg, path, pattern, conn): +def getFiles(msg, job, path, pattern, conn): """ search filenames in the directory - if conn is set search remote :param msg: -- msg-Objekt @@ -37,7 +37,7 @@ def getFiles(msg, path, pattern, conn): """ if conn is not None: return getRemoteFiles(msg, path, pattern, conn) - job = basic.program.Job.getInstance() + # job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) out = [] msg.debug(verify, "getFiles " + path + " , " + pattern) @@ -89,7 +89,7 @@ def getRemoteFiles(msg, path, pattern, conn): pass -def getFilesRec(msg, path, pattern): +def getFilesRec(msg, job, path, pattern): """ Sucht Dateien im Verzeichnis rekursiv :param msg: -- msg-Objekt @@ -97,7 +97,7 @@ def getFilesRec(msg, path, pattern): :param pattern: -- Dateiname als Pattern :return: Array mit gefundenen Dateien, absoluter Pfad """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) out = [] msg.debug(verify, "getFilesRec " + path + " , " + pattern) @@ -110,23 +110,23 @@ def getFilesRec(msg, path, pattern): return out -def getTree(msg, pfad): - job = basic.program.Job.getInstance() +def getTree(msg, job, pfad): + # job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) msg.debug(verify, "getTree " + pfad ) tree = {} files = [] for f in os.listdir(pfad): if os.path.isDir(os.path.join(pfad, f)): - tree[f] = getTree(msg, os.path.join(pfad, f)) + tree[f] = getTree(msg, job, os.path.join(pfad, f)) elif os.path.isFile(os.path.join(pfad, f)): files.append(f) tree["_files_"] = files return tree -def mkPaths(path, msg): - job = basic.program.Job.getInstance() +def mkPaths(job, path, msg): + # job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) modus = job.conf.confs["paths"]["mode"] dirname = os.path.dirname(path) @@ -135,7 +135,7 @@ def mkPaths(path, msg): os.makedirs(dirname, exist_ok=True) -def getFileEncoding(msg, path): +def getFileEncoding(msg, job, path): print("--- getFileEncoding "+path) encodings = ['utf-8', 'iso-8859-1'] # add more for e in encodings: @@ -151,11 +151,11 @@ def getFileEncoding(msg, path): else: print('opening the file with encoding: %s ' % e) return e - return detectFileEncode(path, msg) + return detectFileEncode(job, path, msg) -def detectFileEncode(path, msg): # return "" - job = basic.program.Job.getInstance() +def detectFileEncode(job, path, msg): # return "" + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) print(path) cntIso = 0 @@ -182,26 +182,26 @@ def detectFileEncode(path, msg): # return "" return 'utf-8' -def readFileLines(path, msg): - lines = readFileText(path, msg) +def readFileLines(job, path, msg): + lines = readFileText(job, path, msg) if isinstance(lines, (str)): return lines.splitlines() return [] -def readFileText(path, msg): - job = basic.program.Job.getInstance() +def readFileText(job, path, msg): + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) if not os.path.exists(path): return "" - enc = detectFileEncode(path, msg) + enc = detectFileEncode(job, path, msg) with open(path, 'r', encoding=enc) as file: text = file.read() file.close() return text -def readFileDict(path, msg): +def readFileDict(job, path, msg): """ reads and gets general a dict from any kind of filetyp :param path: with extension of filetype @@ -209,12 +209,12 @@ def readFileDict(path, msg): :return: """ # 20220329 generalize - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) doc = {} if not os.path.exists(path): return doc - enc = detectFileEncode(path, msg) + enc = detectFileEncode(job, path, msg) if D.DFILE_TYPE_YML in path[-4:]: with open(path, 'r', encoding=enc) as file: doc = yaml.full_load(file) @@ -230,7 +230,7 @@ def readFileDict(path, msg): doc = castOrderedDict(res) file.close() elif D.DFILE_TYPE_CSV in path[-5:]: - doc = utils.tdata_tool.getCsvSpec(msg, path, D.CSV_SPECTYPE_CONF) + doc = utils.tdata_tool.getCsvSpec(msg, job, path, D.CSV_SPECTYPE_CONF) return doc def castOrderedDict(res, job=None, key=""): @@ -248,18 +248,18 @@ def castOrderedDict(res, job=None, key=""): return doc -def writeFileText(msg, path, text, enc="utf-8"): - job = basic.program.Job.getInstance() +def writeFileText(msg, job, path, text, enc="utf-8"): + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) - mkPaths(path, msg) + mkPaths(job, path, msg) with open(path, 'w', encoding=enc) as file: file.write(text) file.close() -def writeFileDict(msg, path, dict, enc="utf-8"): - job = basic.program.Job.getInstance() - mkPaths(path, msg) +def writeFileDict(msg, job, path, dict, enc="utf-8"): + #job = basic.program.Job.getInstance() + mkPaths(job, path, msg) if D.DFILE_TYPE_YML in path[-5:]: with open(path, 'w', encoding=enc) as file: yaml.dump(dict, file) diff --git a/utils/flask_tool.py b/utils/flask_tool.py index e69de29..c23cedc 100644 --- a/utils/flask_tool.py +++ b/utils/flask_tool.py @@ -0,0 +1,5 @@ +#!/usr/bin/python +# --------------------------------------------------------------------------------------------------------- +# Author : Ulrich Carmesin +# Source : gitea.ucarmesin.de +# --------------------------------------------------------------------------------------------------------- diff --git a/utils/i18n_tool.py b/utils/i18n_tool.py index 4ccce43..51ffebc 100644 --- a/utils/i18n_tool.py +++ b/utils/i18n_tool.py @@ -25,7 +25,7 @@ class I18n: def __init__(self): self.cache = {} - self.cache = utils.config_tool.getConfig(P.KEY_TOOL, "i18n") + self.cache = utils.config_tool.getConfig(None, P.KEY_TOOL, "i18n") I18n.__instance = self pass @@ -43,15 +43,13 @@ class I18n: out = out.format(args) return out - def getText(self, key, job=None): + def getText(self, key, job): """ this function gets the text depending on language which is set in job.conf :param key: MUST GIVEN WITH (f"{CONST=}", .. :return: return self.cache[language][key] """ - if job is None: - job = basic.program.Job.getInstance() if "language" in job.conf.confs: language = job.conf.confs["language"] else: @@ -67,9 +65,7 @@ class I18n: out = self.cache[DEFAULT_LANGUAGE][key] return out - def getAliasList(self, key, job=None): - if job is None: - jon = basic.program.Job.getInstance() + def getAliasList(self, key, job): out = [] out.append(self.extractText(key)) key = self.extractKey(key) diff --git a/utils/job_tool.py b/utils/job_tool.py index 0698b30..f97482a 100644 --- a/utils/job_tool.py +++ b/utils/job_tool.py @@ -21,11 +21,11 @@ """ from basic.program import Job def hasModul(komp): - job = Job.getInstance() + #job = Job.getInstance() return False def hasFunction(fct): - job = Job.getInstance() + #job = Job.getInstance() return False def hasTool(tool): - job = Job.getInstance() + #job = Job.getInstance() return False diff --git a/utils/match_tool.py b/utils/match_tool.py index b995b50..5371929 100644 --- a/utils/match_tool.py +++ b/utils/match_tool.py @@ -19,7 +19,8 @@ import utils.data_const as D class Matching(): - def __init__(self, comp): + def __init__(self, job, comp): + self.job = job self.comp = comp self.elements = {} self.matchfiles = {} @@ -101,13 +102,13 @@ class Matching(): return ddl def setDiffHeader(matching): - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 job.debug(verify, "getDiffHeader ") htmltxt = "" htmltxt += "" htmltxt += "" + M.MATCH[matching.matchtype]["title"] + "" - htmltxt += utils.css_tool.getInternalStyle("diffFiles") + htmltxt += utils.css_tool.getInternalStyle(job, "diffFiles") htmltxt += "" htmltxt += "" htmltxt += "

" + M.MATCH[matching.matchtype]["title"] + "

" @@ -118,7 +119,7 @@ class Matching(): matching.htmltext = htmltxt def setDiffFooter(self): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 job.debug(verify, "getDiffFooter ") htmltext = self.htmltext @@ -204,7 +205,7 @@ def matchBestfit(matching, path): def matchRestfit(matching): """ """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 job.debug(verify, "matchRestfit ") for x in sorted(matching.nomatch, reverse=True): @@ -231,7 +232,7 @@ def extractKeyI(key): def setMatchkeys(matching, path): - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 job.debug(verify, "getSimilarity " + path) if len(matching.matchkeys) > 0: @@ -269,7 +270,7 @@ def setMatchkeys(matching, path): def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT): """ it calculates the similarity between both rows by: concat each criteria with single-similarity 00..99 and i with 999..000 """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 job.debug(verify, "getSimilarity ") mBsim = "" @@ -282,14 +283,14 @@ def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT): continue if M.SIM_TECHNICAL in k: if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB: - mTsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), + mTsim += getStringSimilarity(job, str(rA[matching.matchkeys[k][D.DDL_FNAME]]), str(rB[matching.matchkeys[k][D.DDL_FNAME]])) else: mTsim += "00" topTsim += "99" if M.SIM_BUSINESS in k: if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB: - mBsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), + mBsim += getStringSimilarity(job, str(rA[matching.matchkeys[k][D.DDL_FNAME]]), str(rB[matching.matchkeys[k][D.DDL_FNAME]])) else: mBsim += "55" @@ -315,7 +316,7 @@ def matchTree(matching): :param matching: :return: """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 job.debug(verify, "..>> start matching " + matching.mode) matchElement(matching, matching.sideA, matching.sideB, "") @@ -326,7 +327,7 @@ def matchTree(matching): def matchElement(matching, A, B, path): """ travers through the datatree """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 job.debug(verify, "matchElem " + path + " A " + str(type(A)) + " B " + str(type(B))) if ((A is not None) and (isinstance(A, list))) \ @@ -339,8 +340,8 @@ def matchElement(matching, A, B, path): return matching -def getStringSimilarity(strA, strB): - job = basic.program.Job.getInstance() +def getStringSimilarity(job, strA, strB): + #job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 job.debug(verify, "getStringSimilarity " + strA + " ?= " + strB) if (strA == strB): return "99" @@ -351,10 +352,10 @@ def getStringSimilarity(strA, strB): def getEvaluation(matching, type, acceptance, sideA, sideB): - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 job.debug(verify, "getEvaluation " + str(sideA) + " ?= " + str(sideB)) - match = getStringSimilarity(str(sideA), str(sideB)) + match = getStringSimilarity(job, str(sideA), str(sideB)) classA = "novalue" classB = "novalue" result = "test" @@ -372,7 +373,7 @@ def getEvaluation(matching, type, acceptance, sideA, sideB): def matchDict(matching, sideA, sideB, path): """ travers through the datatree """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 job.debug(verify, "matchDict " + path) if (sideA is not None): @@ -406,7 +407,7 @@ def matchDict(matching, sideA, sideB, path): def matchArray(matching, sideA, sideB, path): """ matches the datarows of the datatree """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 job.debug(verify, "matchArray " + path + "\n.." + matching.htmltext) matching.sideA = sideA @@ -431,7 +432,7 @@ def matchArray(matching, sideA, sideB, path): def compareRows(matching, path): """ traverse through matched rows """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 ddl = matching.getTableDdl(path) report = utils.report_tool.Report.getInstance() @@ -465,7 +466,7 @@ def compareRows(matching, path): def markRow(matching, header, row, side): - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 text = "" cssClass = "" @@ -481,8 +482,8 @@ def markRow(matching, header, row, side): res = getEvaluation(matching, f[D.DDL_TYPE], f[D.DDL_ACCEPTANCE], "", row[f[D.DDL_FNAME]]) val = str(row[f[D.DDL_FNAME]]) cssClass = res[2] - text += "" + val + "" - text = "" \ + text += "" + val + "" + text = "" \ + M.MATCH[M.MATCH[matching.matchtype][side]]["short"] + "" + text + "" matching.difftext += text return text @@ -490,7 +491,7 @@ def markRow(matching, header, row, side): def compareRow(matching, header, rA, rB): """ traverse through matched rows """ - job = basic.program.Job.getInstance() + job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 allident = True textA = "" @@ -529,13 +530,13 @@ def compareRow(matching, header, rA, rB): matching.setCssClass("result1") elif (match == "hard"): allident = False - textA += "" + valA + "" - textB += "" + valB + "" + textA += "" + valA + "" + textB += "" + valB + "" matching.setCssClass("result3") else: allident = False - textA += "" + valA + " (" + match + ")" - textB += "" + valB + " (" + match + ")" + textA += "" + valA + " (" + match + ")" + textB += "" + valB + " (" + match + ")" matching.setCssClass("result1") if allident: return "" + textA + "" diff --git a/utils/path_tool.py b/utils/path_tool.py index 040cf59..75a5323 100644 --- a/utils/path_tool.py +++ b/utils/path_tool.py @@ -15,14 +15,41 @@ import utils.path_const as P TOOL_NAME = "path_tool" -def getKeyValue(key, comp=None): +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, "config", B.BASIS_FILE) + for format in utils.config_tool.CONFIG_FORMAT: + path += "."+format + if os.path.exists(path): + return path + + +def getKeyValue(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: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME)-4 pt = PathConf.getInstance() job.debug(verify, "getKeyValue " + key) @@ -53,7 +80,7 @@ def getKeyValue(key, comp=None): return "xx-"+key+"-xx" -def composePath(pathname, comp): +def composePath(job, pathname, comp): """ 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. @@ -61,18 +88,18 @@ def composePath(pathname, comp): :param comp: :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME) pt = PathConf.getInstance() job.debug(verify, "composePath " + pathname + " zu " + str(pt) + "mit ") job.debug(verify, str(pt.pattern)) if pt.pattern[pathname]: - return composePattern(pt.pattern[pathname], comp) + return composePattern(job, pt.pattern[pathname], comp) else: job.debug(verify, "in Pattern nicht vorhanden: " + pathname) -def composePattern(pattern, comp): +def composePattern(job, pattern, comp): """ the function composes the pattern to the standardarized path with the attributes which are stored in the job and the component @@ -81,23 +108,23 @@ def composePattern(pattern, comp): :param comp: :return: path """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME) - verbose = False + verbose = True job.debug(verify, "composePattern " + pattern) max=5 l = re.findall('\{.*?\}', pattern) job.debug(verify, l) for pat in l: if verbose: print(str(max) + ": " + pattern + ": " + pat) - pit = getKeyValue(pat[1:-1], comp) + pit = getKeyValue(job, pat[1:-1], comp) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) pattern = pattern.replace(pat, pit) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) while ("{" in pattern): max = max-1 job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) - pattern = composePattern(pattern, comp) + pattern = composePattern(job, pattern, comp) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) if (max < 3) : break @@ -149,7 +176,7 @@ def rejoinPath(a, b="", c="", d="", e="", f=""): return out -def extractPattern(pathtyp, comp=None): +def extractPattern(job, pathtyp, comp=None): """ this function extracts recoursively all parts of the pathstrucure as key and gets the values from the job-parameter and job-configuration @@ -157,7 +184,7 @@ def extractPattern(pathtyp, comp=None): :param comp: :return: dictionary of all part (key) with their valuess """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME) out = [] pt = PathConf.getInstance() @@ -169,13 +196,13 @@ def extractPattern(pathtyp, comp=None): pre = work[0:i] pat = work[i+1:j] job.debug(verify, work + " von " + str(i) + "-" + str(j) + " pre " + pre + "pat " + pat) - pit = getKeyValue(pat, comp) + pit = getKeyValue(job, pat, comp) tup = (pre, pat, pit) out.append(tup) work = work[j+1:] return out -def extractPath(pathtyp, path): +def extractPath(job, pathtyp, path): """ 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 @@ -185,7 +212,7 @@ def extractPath(pathtyp, path): :param path: the concrete path - it should be the directory in the parameter of the job :return: """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() patterlist = extractPattern(pathtyp) verbose = False work = path @@ -245,7 +272,7 @@ class PathConf: __instance = None def __init__(self): print('init pathConf') - confs = utils.config_tool.getConfig("tool", "path") + confs = utils.config_tool.getConfig(None, "tool", "path") self.pattern = confs["pattern"] print(self.pattern) PathConf.__instance = self diff --git a/utils/report_tool.py b/utils/report_tool.py index f2320da..f360829 100644 --- a/utils/report_tool.py +++ b/utils/report_tool.py @@ -48,7 +48,7 @@ class Report: else: return Report() - def __init__(self): + def __init__(self, job): """ :param report: matchtype :param comp: optional on matching @@ -68,7 +68,8 @@ class Report: paths : p with links to row-results matching : table complete match for artefact-result resp. only diff for other matches """ - job = basic.program.Job.getInstance() + #job = basic.program.Job.getInstance() + self.job = job self.report = {} self.report["testcases"] = [] self.testcase = "" @@ -99,7 +100,7 @@ class Report: self.report[testcase][component][artefact][matchtype]["diff"] = diffTable def getTitle(self, testcase="", component="", artefact="", matchtype=""): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() if len(matchtype) > 1: html = ""+M.MATCH[matchtype]["title"]+"

"+M.MATCH[matchtype]["title"]+"

" elif len(testcase) > 1: @@ -154,11 +155,11 @@ class Report: return cssClass def getHeader(self): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel(TOOL_NAME))-1 htmltxt = "" htmltxt += "" - htmltxt += utils.css_tool.getInternalStyle("diffFiles") + htmltxt += utils.css_tool.getInternalStyle(job, "diffFiles") return htmltxt def getOverviewHead(self, testcase=""): @@ -189,18 +190,18 @@ class Report: return html def getComponentHead(self, testcase="", component="", artefact="", matchtype=""): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() html = "

"+REP_COMP+" "+component+"

" return html def getArtefactBlock(self, testcase, component, artefact, matchtype=""): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() html = "

"+REP_ART+" "+artefact+"

" for match in self.report[testcase][component][artefact]: cssClass = self.getCssClass(testcase, component, artefact, match) path = self.getFilepath(testcase, component, artefact, match) path = path.replace(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], os.path.join("..", "..")) - html += " "+M.MATCH[match]["filename"]+" " + html += " "+M.MATCH[match]["filename"]+" " html += "

" if len(matchtype) < 1: matchtype = M.MATCH_POSTCOND @@ -217,7 +218,7 @@ class Report: def getFilepath(self, testcase, component, artefact, matchtype): cm = basic.componentHandling.ComponentManager.getInstance("init") comp = cm.getComponent(component) - path = os.path.join(utils.path_tool.composePattern("{tcresult}", comp), artefact+"_"+M.MATCH[matchtype]["filename"]+".html") + path = os.path.join(utils.path_tool.composePattern(self.job, "{tcresult}", comp), artefact+"_"+M.MATCH[matchtype]["filename"]+".html") return path def getComparisonBlock(self, testcase, component, artefact, matchtype): @@ -225,7 +226,7 @@ class Report: return html def reportTestcase(self, testcase): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel(TOOL_NAME)) - 1 html = self.getHeader() html += self.getTitle(testcase) @@ -242,7 +243,7 @@ class Report: return html def extractTestcase(self, testcase, html): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel(TOOL_NAME)) - 1 if not testcase in self.report: self.report = {} @@ -256,7 +257,7 @@ class Report: self.report[testcase]["block"] = block def reportTestsuite(self): - job = basic.program.Job.getInstance() + job = self.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel(TOOL_NAME)) - 1 testinstances = getattr(job.par, B.PAR_TESTCASES) html = self.getHeader() @@ -273,13 +274,13 @@ class Report: return html -def report_testsuite(tcpath): +def report_testsuite(job, tcpath): """ creates header :param tcpath: :return: html-code with result-codes of each component """ - job = basic.program.Job.getInstance() + # job = basic.program.Job.getInstance() verify = -0+job.getDebugLevel(TOOL_NAME) job.debug(verify, "writeDataTable " + str(tcpath)) diff --git a/utils/tdata_tool.py b/utils/tdata_tool.py index b244c4a..19ce4eb 100644 --- a/utils/tdata_tool.py +++ b/utils/tdata_tool.py @@ -28,8 +28,6 @@ def getTestdata(job=None): for the testcase resp testsuite of the job :return: """ - if job is None: - job = basic.program.Job.getInstance() if "testcase" in job.program: return collectTestdata(B.PAR_TESTCASE, getattr(job.par, B.PAR_TESTCASE), job) else: @@ -50,9 +48,9 @@ def collectTestdata(gran, testentity, job): basispath = utils.path_tool.rejoinPath(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], testentity) pathname = utils.config_tool.getConfigPath(P.KEY_TESTSUITE, getattr(job.par, B.PAR_TESTSUITE), "", job) if pathname[-3:] == D.DFILE_TYPE_CSV: - tdata = getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_DATA) + tdata = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA) else: - tdata = utils.file_tool.readFileDict(pathname, job.m) + tdata = utils.file_tool.readFileDict(job, pathname, job.m) # get explicit specdata of includes if D.CSV_BLOCK_IMPORT in tdata: for pathname in tdata[D.CSV_BLOCK_IMPORT]: @@ -60,16 +58,16 @@ def collectTestdata(gran, testentity, job): if job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] not in pathname: pathname = utils.path_tool.rejoinPath(basispath, pathname) if pathname[-3:] == D.DFILE_TYPE_CSV: - data = getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_DATA) + data = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA) else: - data = utils.file_tool.readFileDict(pathname, job.m) + data = utils.file_tool.readFileDict(job, pathname, job.m) for table in data[D.CSV_BLOCK_TABLES]: if table in tdata[D.CSV_BLOCK_TABLES]: print("Fehler") tdata[D.CSV_BLOCK_TABLES][table] = data[D.CSV_BLOCK_TABLES][table] # get implicit specdata of spec-library for prefix in list_blocks[D.DFILE_TABLE_PREFIX]: - files = utils.file_tool.getFiles(job.m, basispath, prefix, None) + files = utils.file_tool.getFiles(job.m, job, basispath, prefix, None) if len(files) < 0: continue for f in files: @@ -77,9 +75,9 @@ def collectTestdata(gran, testentity, job): continue pathname = utils.path_tool.rejoinPath(basispath, f) if pathname[-3:] == D.DFILE_TYPE_CSV: - data = getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_DATA) + data = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA) else: - data = utils.file_tool.readFileDict(pathname, job.m) + data = utils.file_tool.readFileDict(job, pathname, job.m) for table in data[D.CSV_BLOCK_TABLES]: if table in tdata[D.CSV_BLOCK_TABLES]: print("Fehler") @@ -92,24 +90,20 @@ def collectTestdata(gran, testentity, job): def setBlockLists(job): for block in D.LIST_BLOCK_CONST + D.LIST_ATTR_CONST + D.LIST_DFNAME_CONST: - list = utils.i18n_tool.I18n.getInstance().getAliasList(block+"='"+eval("D."+block)+"'") + list = utils.i18n_tool.I18n.getInstance().getAliasList(block+"='"+eval("D."+block)+"'", job) #list.append(eval("D."+block)) list_blocks[eval("D." + block)] = [] for x in list: list_blocks[eval("D." + block)].append(x.lower()) -def readCsv(msg, filename, comp, aliasNode="", job=None): - if job is None: - job = basic.program.Job.getInstance() - lines = utils.file_tool.readFileLines(filename, msg) +def readCsv(msg, job, filename, comp, aliasNode=""): + lines = utils.file_tool.readFileLines(job, filename, msg) print("readCsv "+filename) - return parseCsv(msg, filename, lines, comp, aliasNode, job) + return parseCsv(msg, job, filename, lines, comp, aliasNode) -def parseCsv(msg, filename, lines, comp, aliasNode="", job=None): - if job is None: - job = basic.program.Job.getInstance() +def parseCsv(msg, job, filename, lines, comp, aliasNode=""): if len(list_blocks) < 1: setBlockLists(job) tdata = {} @@ -133,7 +127,7 @@ def extractAliasNode(filename, comp, job): return "" -def getCsvSpec(msg, filename, ttype, job=None): +def getCsvSpec(msg, job, filename, ttype): """ reads the specification from a csv-file and maps it into the internal data-structure :param msg: @@ -142,14 +136,14 @@ def getCsvSpec(msg, filename, ttype, job=None): :param job: :return: """ - if job is None: - job = basic.program.Job.getInstance() - lines = utils.file_tool.readFileLines(filename, msg) + #if job is None: + # job = basic.program.Job.getInstance() + lines = utils.file_tool.readFileLines(job, filename, msg) tdata = {} # the result return parseCsvSpec(msg, lines, ttype, tdata, job) -def parseCsvSpec(msg, lines, ttype, tdata, job=None): +def parseCsvSpec(msg, lines, ttype, tdata, job): """ :param msg: @@ -158,8 +152,6 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): :param job: :return: """ - if job is None: - job = basic.program.Job.getInstance() if len(list_blocks) < 1: setBlockLists(job) status = "start" @@ -384,7 +376,7 @@ def writeCsvData(filename, tdata, comp, job): for k in tdata[B.DATA_NODE_TABLES]: text += buildCsvData(tdata[B.DATA_NODE_TABLES][k], k, job) text += "\n" - utils.file_tool.writeFileText(comp.m, filename, text) + utils.file_tool.writeFileText(comp.m, job, filename, text) def buildCsvData(tdata, table, job=None): diff --git a/utils/xml1_tool.py b/utils/xml1_tool.py deleted file mode 100644 index e77a83a..0000000 --- a/utils/xml1_tool.py +++ /dev/null @@ -1,757 +0,0 @@ -#import dpath.util -import json -import yaml -import re -import datetime -import utils.tdata_tool -import os, sys, json -import xmltodict -import pprint - -#class fcts: -def dict2xml(tree): - out = xmltodict.unparse(tree, pretty=True) - return out - -def xml2dict(xmlstring): - tree = {} - pp = pprint.PrettyPrinter(indent=4) - tree = xmlstring.parse(xmlstring) - return tree - -""" -Register-Meldung erstellen -""" -class register(): - def __init__(self): - self.absender = Absender() - self.vrfelder = Vrfelder() - pass - - def schreibeRegister(self, content, regAdr): - ausgabe = {} - content["vrfelder"] = self.vrfelder - content["absender"] = self.absender.keys[regAdr] - # - ausgabe = self.schreibeProtokoll(ausgabe, content) - print( "ausgabe vorher: " + str( ausgabe)) - ausgabe = self.schreibeAbsender(ausgabe, content, regAdr) - print("ausgabe vorher: "+str(ausgabe)) - ausgabe = self.schreibeEmpfaenger(ausgabe, content) - print("ausgabe vorher: "+str(ausgabe)) - ausgabe = self.schreibeMetadaten(ausgabe, content) - print("ausgabe vorher: "+str(ausgabe)) - ausgabe = self.schreibeSegmentkopf(ausgabe, content) - print("ausgabe vorher: "+str(ausgabe)) - ausgabe["nachricht"]["datensegment"] = [] - for row in content["tabelle"]["person"][B.DATA_NODE_DATA]: - print ("foreach row") - print (row) - satz = {} - satz = self.schreibeSegmentsatz(satz, content, row["_lfdNR"]) - # print("ausgabe vorher: "+str(ausgabe))* - ausgabe["nachricht"]["datensegment"].append(satz["datensegment"]) - return ausgabe - - """ Fuellt und ordnet Protokollknoten ein""" - def schreibeProtokoll(self, ausgabe, content): - ausgabe["protokoll"] = self.setProtokoll(content)["protokoll"] - return ausgabe - - def setProtokoll(self, content): - ausgabe = {} - d = datetime.datetime.now() - ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/datum', d.strftime("%Y%m%d")) - ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/uhrzeit', d.strftime("%H%M%S")) - ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/anwendung/anwendungsname', "Anwendungsname") - ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/anwendung/version', "Version") - ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/anwendung/hersteller', "StBA") - ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/ressourceID[@klasse="SDFMETA"]', "--RessourceID") - return ausgabe - - """ Fuellt und ordnet Absenderknoten ein""" - def schreibeAbsender(self, ausgabe, content, regAdr): - ausgabe["absender"] = self.setAbsender(content, regAdr) - return ausgabe - - def setAbsender(self, content, regAdr): - ausgabe = {} - for feld in Absender.FELDER: - ausgabe = fcts.setMerkmalContent(ausgabe, content, 0, feld) - return ausgabe - - """ Fuellt und ordnet Empfaengerknoten ein""" - def schreibeEmpfaenger(self, ausgabe, content): - ausgabe["empfaenger"] = self.setEmpfaenger(content)["empfaenger"] - return ausgabe - - def setEmpfaenger(self, content): - ausgabe = {} - ausgabe = fcts.setMerkmal(ausgabe, '/empfaenger/kennung[@klasse="STAID"]', '99') - return ausgabe - - """ Fuellt und ordnet Metadatenknoten ein""" - def schreibeMetadaten(self, ausgabe, content): - nachricht = self.setMetadaten(content) - for knoten in nachricht: - if knoten != "datensegment": - ausgabe[knoten] = nachricht[knoten] - return ausgabe - - def setMetadaten(self, content): - ausgabe = {} - d = datetime.datetime.now() - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/erhebung/kennung[@klasse="ERHID"]', 'ERHEBUNG_KENNUNG') - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/erhebung/ressource[@klasse="SDFMETA"]', 'ERHEBUNG_RESSOURCE_1') - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/erhebung/ressource[@klasse="SDF-ERZEUGUNG"]', 'ERHEBUNG_RESSOURCE_2') - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/berichtszeitraum/jahr', d.strftime("%Y")) - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/berichtsempfaenger/kennung[@klasse ="STAID"]', 'BERICHTSEMPFÄNGER_KENNUNG') - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/datenattribute/attribute::dezimalzeichen', 'DEZIMAL_ZEICHEN') - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/datenattribute/attribute::tausender-trennzeichen', 'TAUSENDER_TRENNZEICHEN') - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/hmm[@name="BerichtseinheitID"]/wert', 'BERICHTSEINHEIT_ID') - return ausgabe - - def schreibeSegmentkopf(self, ausgabe, content, ): - ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/datensegment/meldungsID', 'MELDUNGS_ID') - return ausgabe - - def schreibeSegmentsatz(self, ausgabe, content, index): - for feld in Person.FELDER: - ausgabe = fcts.setMerkmalContent(ausgabe, content, index, feld) - return ausgabe - - -class Absender(): - FELDER = ("ABSENDER_KENNUNG", "ABSENDER_IDENTITÄT", "ABSENDER_TELEFON", "ABSENDER_EMAIL", "ABSENDER_FAX", "ABSENDER_URL", "BERICHTSEINHEIT_ID", "REGNAME") - - def __init__(self): - content = utils.tdata_tool.readCsv("testdaten/allgemein/absender.csv", "keys") - self.keys = content["tabelle"]["absender"]["_keys"] - -class Vrfelder(): - def __init__(self): - with open(r'src/config/vrFelder.yml') as file: - content = yaml.full_load(file) - self.conf = content - - def getVrfeld(self, feld): - print("gerVrfeld "+feld) - if feld in self.conf["config"]: - print("gerVrfeld treffer"+feld) - return self.conf["config"][feld] - pass - -class Anschrift(): - FELDER = ("GEMSCHL", "HNR", "HNR_BUCHST", "HNR_TEILNR", "HNR_UNST", "ORTSTEIL", "ORTSTEIL_POST", "PLZ", "STOCKNR_WHG", "STR", "STRSCHL", "WOHNORT", "ZUSATZ") - -class Person(): - FELDER = ("IDNR", "DR", "FAMNAME", "FAMNAME_AE", "FAMNAME_BEST", "FAMNAME_ZUS", "FAMNAME_VOR", "FAMNAME_UNST", "GEB_DAT", "GEBNAME", "GEBNAME_BEST1", "GEBNAME_BEST2", "GEBNAME_UNST", "GEBSTAAT", "GEB_ORT", "GESCHLECHT", "STAATSANG", "VORNAME", "VORNAME_AE") - -""" -Werkzeuge, um Register-Merkmale zu erstellen, setzen, ... -""" -class fcts: - #+MULTI_NODE = ("mm", "hmm", "omm", "erhebung") - MULTI_NODE = ("erhebung") - #+ARRAY_NODE = ("satz", "ressource") - ARRAY_NODE = ("mm", "hmm", "omm", "satz", "ressource") - - def isLastGroup(pfad, knoten): - if (pfad[(pfad.find(knoten)+len(knoten)+4):].find("[@") > 1): - return False - return True - - def getNodename(knotenname): - if ("[@" in knotenname): - return knotenname[0:knotenname.find("[@")] - return knotenname - - def getKeyname(knotenname): - if ("[@" in knotenname): - return knotenname[knotenname.find("[@")+1:knotenname.find("=")] - return knotenname - - def setArrayElem(array, elem): - # sets or appends the element/key-val into the array - for k in array: - if (elem in array): - return array - array.append(elem) - - def getTidyTab(self, depth=0): - tab = "" - # print("depth "+str(depth)) - for i in range(0, depth): - tab += "\t" - return tab - - def hasTidyAttr(self, tree): - first = True - if isinstance(tree, dict): - for x in tree: - if first and isinstance(tree[x], dict): - return self.hasTidyAttr(tree[x]) - elif first and isinstance(tree[x], list): - return self.hasTidyAttr(tree[x]) - elif x[0:1] == "@": - return True - else: - return False - if isinstance(tree, list): - for x in tree: - if first and isinstance(x, dict): - return self.hasTidyAttr(x) - elif first and isinstance(x, list): - return self.hasTidyAttr(x) - elif x[0:1] == "@": - return True - else: - return False - elif tree[0:1] == "@": - return True - return False - - def getTidyAttr(self, tree, x, depth=0): - xml = "" - attr = "" - if isinstance(tree, dict): - for y in tree: - if isinstance(y, dict): - return "" - elif isinstance(y, list): - attr = self.getTidyAttr(y, x, depth) - elif y[0:1] == "@": - attr += " "+y[1:]+"="+tree[y] - elif len(attr) > 1: - xml = "<"+x+attr+">"+y+"" - return xml - else: - return "" - elif isinstance(tree, dict): - for y in tree: - pass - return "" - - def getTidyDict(self, tree, x, depth=0): - xml = "" - tab = self.getTidyTab(depth) - newTree = {} - attr = "" - for y in tree: - if y[0:1] == "@": - attr = " " + y[1:] + "=\"" + tree[y] + "\"" - else: - newTree[y] = tree[y] - if len(newTree) > 0: - xml += tab + "<" + x + attr + ">\n" + self.tidy(newTree, depth + 1) + tab + "\n" - else: - xml += tab + "<" + x + attr + "/>\n" - return xml - - def tidy(self, tree, depth=0): - verify = 0 - xml = "" - tab = self.getTidyTab(depth) - hasa = self.hasTidyAttr(tree) - if verify: print("getTidy "+str(type(tree))+" hasAttr "+str(hasa)) - if isinstance(tree, dict): - for x in tree: - if verify: print("dict " + str(x)) - if isinstance(tree[x], dict): - hasa = self.hasTidyAttr(tree[x]) - newTree = {} - attr = "" - for y in tree[x]: - if verify: print("y-for "+str(y)) - if y[0:1] == "@": - attr = " " + y[1:] + "=\"" + tree[x][y] + "\"" - else: - newTree[y] = tree[x][y] - if len(newTree) > 0: - xml += tab + "<" + x + attr + ">\n" + self.tidy(newTree, depth + 1) + tab + "\n" - else: - xml += tab + "<" + x + attr + "/>\n" - elif isinstance(tree[x], list): - hasa = self.hasTidyAttr(tree[x]) - if hasa: - xml += tab + "<" + x + self.tidy(tree[x], depth) + "\n" - else: - xml += tab + "<" + x + ">\n" + self.tidy(tree[x], depth + 1) + tab + "\n" - elif x[0:1] == "@": - attr = " " + x[1:] + "=\"" + tree[x] + "\"" - elif x == "#text": - xml = str(tree[x]) - return xml - else: - xml += tab + "<" + x + ">" + str(tree[x]) + "\n" - elif isinstance(tree, list): - for x in tree: - if verify: print("list " + str(x)) - if isinstance(x, dict): - newTree = {} - attr = "" - text = False - hasa = self.hasTidyAttr(x) - for y in x: - if verify: print("y-for "+str(y)) - if y[0:1] == "@": - attr = " " + y[1:] + "=\"" + x[y] + "\"" - elif y == "#text": - text = x[y] - else: - newTree[y] = x[y] - if text and len(newTree) > 0 and len(attr) > 0: - xml += "" + attr + ">" + self.tidy(newTree, depth + 1) - elif len(newTree) > 0 and len(attr) > 0: - xml += "" + attr + ">\n" + self.tidy(newTree, depth + 1) + tab - elif len(attr) > 0: - if not isinstance(x, dict): - xml += tab + "<296" + x + attr + "/>\n" - else: - xml += attr + ">"+text - else: - xml += self.tidy(newTree, depth) - else: - xml += tab + "<" + x + ">\n" + self.tidy(x, depth) + tab + "" - else: - xml += "<" + str(tree) + ">" - return xml - - - def addMerkmal(baum, pfad, index, wert): - """ - Eingabe: - baum inklusive Elternknoten - pfad kompletter Pfad von Wurzel bis Blatt - index auf den Pfad - wert einzutragender Wert - Verarbeitung - basis der zu bearbeitende Knotenname extrahiert von Attributen - elem zu bearbeitender Knoten - zu betrachtende Fälle: - a: basis intendiert ein Array: - b: basis intendiert ein Dictionary: - c: basis ist ein einfacher Knoten - Weiter zu betrachten hinsichtlich Komplexität des Knotens - .a einfacher Knoten - .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode) - Weiter zu betrachten hinsichtlich Pfadposition - ..a: Blatt - Wert eintragen und - ..b: im Pfad - weiterer rekursiver Aufruf - Ausgabe: - baum inklusive Elternknoten - """ - logdebug = 3 # Schalter zur Debug-Einstellung innerhalb der Funktion - if logdebug >= 1: print("--- addMerkmal "+str(index)+" "+pfad+" "+wert) - if logdebug >= 3: print("--- addMerkmal "+str(baum)) - - # # # # # # # # # # # # # # # # # # # # - # basis der zu bearbeitende Knotenname extrahiert von Attributen - # elem zu bearbeitender Knoten - elem = {} - a = pfad.strip('/').split('/') - anode = None # optional fuer Attribute - bnode = None # optional fuer direkte Wertzuordnung #text - basis = "" # Knotenname - ohne Attribute - - if ("[@" in a[index]): - if logdebug >= 1: print("0b") - basis = a[index][0:a[index].find("[@")] - attribs = a[index][a[index].find("[@")+1:a[index].find("]")] - aname = attribs[0:attribs.find("=")] - aval = attribs[attribs.find("=")+2:-1] - if logdebug >= 3 : print("0b "+basis+" : "+aname+" = "+aval) - aarr = [aname , aval] - anode = {} - anode[aname] = aval - if (index == len(a)-1): - barr = ["#text", wert] - bnode = {} - bnode["#text"] = wert - if logdebug >= 3 : print("0b "+basis+" "+str(anode)+" "+str(bnode)) - else: - basis = a[index] - if logdebug >= 3 : print("0b "+basis+" "+str(anode)+" "+str(bnode)) - if (basis in baum): - elem[basis] = baum[basis] - nindex = index+1 - if logdebug >= 1: print("1 "+a[index]+" "+wert+" "+str(baum)) - - # # # # # # # # # # # # # # # # # # # # - # zu betrachtende Fälle: - # a: basis intendiert ein Array: - # b: basis intendiert ein Dictionary: - # c: basis ist ein einfacher Knoten - # Weiter zu betrachten hinsichtlich Komplexität des Knotens - # .a einfacher Knoten - # .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode) - # Weiter zu betrachten hinsichtlich Pfadposition - # ..a: Blatt - Wert eintragen und - # ..b: im Pfad - weiterer rekursiver Aufruf - # - # # # Fall a : Array - if (basis in fcts.ARRAY_NODE): - # Weiter zu betrachten - # .a einfacher Knoten - # .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode) - # Weiter zu betrachten hinsichtlich Pfadposition - # ..a: Blatt - Wert eintragen und - # ...a zusaetzliches Blatt - # ...b ueberschriebenes Blatt OPEN - # ..b: im Pfad - weiterer rekursiver Aufruf - # ...a expandierter Pfad - # ...b fortgefuehrter Pfad - existKnoten = "N" - hatAttr = "N" - istWert = "N" - hatWert = "N" - expand = "N" - lastidx = 0 - if logdebug >= 1: print("a: ARRAY "+a[index-1]+"-"+basis+" "+str(baum)) - if (basis in baum): - # ggf. zu bearbeitendes ELEM erzeugen - if (isinstance(baum[basis], dict)): - print ("200 dict vorhanden") - if (len(baum[basis].keys()) <1): - elem[basis] = [] - elem[basis].append({}) - if (isinstance(baum[basis], list)): - print ("201 array vorhanden "+str(baum[basis])) - #if baum[basis] - existKnoten = "J" - elem[basis] = baum[basis] - else: - print ("203 neues array") - elem[basis] = [] - elem[basis].append({}) - existKnoten = "N" - xnode = {} - if (anode): - hatAttr = "J" - xnode = {} # Komplexitaetsfaelle in xnode setzen - if logdebug >= 3: print("a-b "+basis+" "+str(anode)) - ##elem[basis].append(anode) - #if (not aarr[0] in elem[basis]): #+ - # if logdebug >= 3: print("a-b "+basis+" anode ergaenzt "+str(anode)) - # #-elem[basis].append(anode) - xnode = anode - if (bnode): # a-b-a - istWert = "J" - if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx)) - if logdebug >= 3: print("-->a-b-a-b> kompl. Blatt "+basis+" "+str(bnode)) - #-elem[basis].append(bnode) - elem[basis][0][aarr[0]] = aarr[1] - elem[basis][0][barr[0]] = barr[1] - baum[basis] = elem[basis] - if logdebug >= 3: print("<--a-b-a-b< kompl. Blatt "+basis+" "+str(elem)) - return baum - # weitere Fallunterscheidung: unterster Komplexknoten erweitern, vorherige durchlaufen - subnode = fcts.getNodename(a[nindex]) - parentkey = fcts.getKeyname(a[index-1]) - realnode = subnode - aridx = -1 - if (basis in elem): - for x in elem[basis]: - print("x: "+str(x)+" "+str(len(x.keys()))) - if len(x.keys()) > 0: - print ("x ist") - aridx += 1 - # aridx -= 1 - lastidx = aridx - print ("## Faluntersuchung parentkey "+parentkey+" aridx "+str(aridx)+" subnode "+subnode) - if ((aridx < 0)): # a-b-b-a - elem[basis][0][realnode] = {} - elem[basis][0][realnode][aarr[0]] = aarr[1] - if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx)) - if logdebug >= 3: print("-->a-b-b-a> kompl. Pfad init " +basis+" "+parentkey+" " + realnode + " " + wert +" "+str(nindex)+" "+str(baum)) - insnode = fcts.addMerkmal(elem[basis][0][realnode], pfad, nindex, wert) - if logdebug >= 3: print("<--a-b-b-a< kompl. Pfad init " + basis+" "+str(insnode)+"-set-0-"+str(elem[basis][0])) - elem[basis][0] = insnode - baum[basis] = elem[basis] - return baum ## - if fcts.isLastGroup(pfad, basis): # a-b-b-a expandierter Pfad - subnode = fcts.getNodename(a[nindex]) - if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx)) - if logdebug >= 3: print("-->a-b-b-a> kompl. Pfaderw "+subnode+" "+str(nindex)+" "+str(anode)+" "+str(baum)) - insnode = fcts.addMerkmal(anode, pfad, nindex, wert) - if logdebug >= 3: print("<--a-b-b-a< kompl. Pfaderw. " + basis + " "+str(insnode)+"-ins-"+str(elem[basis][0])) - elem[basis].append(insnode) - baum[basis] = elem[basis] - return baum - else: - # hier soll in dem Knoten weiternavigiert werden - # satz[@klasse="1"]/mm[@name="2"]... - # basis = satz, subnode = mm - # baum = {satz: [{ @klasse : 1, mm : [{ @name : 0, .. - subnode = fcts.getNodename(a[nindex]) - realnode = subnode - if "[@" in subnode: - realnode = a[nindex+1] - if logdebug >= 3: - print (basis) - print (elem) - print (baum) - aridx = 0 - if (basis in baum): - aridx = len(baum[basis])-1 - #if (aridx >= 0) and (): - # elem[basis] = [] - # elem[basis].append(anode) - # .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode) - # Weiter zu betrachten hinsichtlich Pfadposition - # ..a: Blatt - Wert eintragen und #-DONE-# - # ...a zusaetzliches Blatt #-OPEN-# - # ...b ueberschriebenes Blatt #-DONE-# - # ..b: im Pfad - weiterer rekursiver Aufruf - # ...a initialer Pfadposition #-DONE-# - # ...b expandierter Pfad - # ...c fortgefuehrter Pfad - if (aridx > 0 and logdebug >= 3): - print (basis+" ++ "+str(aridx)+" "+subnode) - print(str(baum[basis])) - print(str(baum[basis][aridx])) - if ((aridx > 0) and (realnode in baum[basis][aridx].keys())): - elem[basis] = [] - #elem[basis].append(elem[basis][aridx][realnode]) - if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx)) - if logdebug >= 3: print("-->a-b-b-c> kompl. Pfad " +basis+" "+ realnode + " " + wert + " " + str(nindex) + " " + str(aridx)+" "+str(baum)) - insnode = fcts.addMerkmal(elem[basis][aridx], pfad, nindex, wert)[realnode] - if logdebug >= 3: print("<--a-b-b-c< kompl. Pfad " + basis+" "+str(insnode)+"-set-"+str(elem[basis][aridx][realnode])) - elem[basis][aridx][realnode] = insnode - else: - #elem[basis] = [] - #elem[basis].append(anode) - if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx)) - if logdebug >= 3: print("-->a-b-b-b> kompl. Pfad " +basis+" "+ realnode + " " + wert + " " + str(nindex) + " " + str(aridx)+" "+str(baum)) - insnode = fcts.addMerkmal(elem[basis][lastidx], pfad, nindex, wert) - if logdebug >= 3: print("<--a-b-b-b< kompl. Pfad " + basis+" "+str(insnode)+"-set-"+str(elem[basis][aridx])) - #elem[basis].append(insnode) - pass - baum[basis] = elem[basis] - return baum - # unerreichbar, da schon im else returned - #if logdebug >= 3: - # print("-->a-b-b> kompl. Pfad "+basis+" "+str(nindex)) - # print("-->a-b-b> kompl. Pfad "+realnode+" "+str(nindex)+" "+str(baum)) - # print("-->a-b-b> kompl. Pfad "+realnode+" "+str(nindex)+" "+str(elem)) - #if not subnode in elem[basis][0]: - # elem[basis][0][realnode] = {} - # elem[basis][0][realnode][aarr[0]] = aarr[1] - # elem[basis][0] = fcts.addMerkmal(elem[basis][0][realnode], pfad, nindex, wert) - #elif (len(elem[basis]) > 0): - # elem[basis].append(fcts.addMerkmal(xnode, pfad, nindex, wert)) - #+elem[basis].append(fcts.addMerkmal(xnode, pfad, nindex, wert)) - #if logdebug >= 3: - # print (basis) - # print(baum) - # print(elem) - # print("<--a-b-b< kompl. Pfad "+basis+""+str(baum)) - #baum[basis] = elem[basis] - #return baum ## - else: - if logdebug >= 3: print("-->a-a-b> einf. Pfad "+str(nindex)+" "+str(baum)) - return baum - ##### Fall 3ab ## Dict - elif (basis in fcts.MULTI_NODE): - if logdebug >= 1: print("b: DICT "+basis) - if (not basis in baum): - print ("elem angelegt") - elem[basis] = {} - if (anode ): - if logdebug >= 3: print("b-b "+basis+" "+str(anode)) - elem[basis][aarr[0]] = aarr[1] - if (bnode): - elem[basis][barr[0]] = barr[1] - baum[basis] = elem[basis] - #elem[basis].append(bnode) - if logdebug >= 3: print("<<--b-b-a< kompl. Blatt "+basis+" "+str(index)+" "+str(elem)) - return baum - if ("[@" in a[index+1]): - subbasis = a[index+1][0:a[index+1].find("[@")] - if logdebug >= 3: print("-->b-b-b> kompl. Pfad "+basis+" "+str(index)+" "+str(elem)) - elem[basis] = fcts.addMerkmal(elem[basis], pfad, nindex, wert) - baum[basis] = elem[basis] - if logdebug >= 3: print("<--b-b-b< kompl. Pfad "+basis+" "+str(index)+" "+str(baum)) - return baum - else: - subbasis = a[index+1] - if logdebug >= 3: print("-->b-a-b> einf. Pfad "+basis+" "+str(index)+" "+str(elem)) - elem[basis][subbasis] = fcts.addMerkmal({}, pfad, nindex, wert) - baum[basis] = elem[basis] - if logdebug >= 3: print("<--b-a-b< einf. Pfad "+basis+" "+str(index)+" "+str(elem)) - return baum - # baum[basis] = elem[basis] - return baum[basis] - ###### Fall einfach + vorhanden - else: - if (basis in baum): - elem[basis] = baum[basis] - else: - elem[basis] = {} - if logdebug >= 1: print("c: EINFACH "+a[index-1]+"-"+basis+" "+str(baum)) - if (1 == len(a)-index): - if logdebug >= 3 : print("3b "+basis+" "+str(anode)+" "+str(bnode)) - if (anode): - elem[basis] = {} - elem[basis][aarr[0]] = aarr[1] - if logdebug >= 3 : print("3b1") - if (bnode): - elem[basis][barr[0]] = barr[1] - baum[basis] = elem[basis] - if logdebug >= 3 : print("<<-- c-b-a kompl. Blatt "+basis+" "+str(baum)) - return baum - elem[basis] = {} - elem[basis] = wert - baum[basis] = elem[basis] - if logdebug >= 3 : print("<<-- c-a-a einf. Blatt "+basis+" "+str(anode)+" "+str(baum)) - return baum - if (anode): - if logdebug >= 3: print("-->c-b-b> kompl. Pfad "+basis+" "+nindex) - elem[basis] = fcts.addMerkmal(elem[basis], pfad, nindex, wert) - baum[basis] = elem[basis] - if logdebug >= 3: print("<--c-b-b< kompl. Pfad "+basis+" "+nindex+" "+str(baum)) - return baum[basis][basis] ## - if logdebug >= 3: print("-->c-a-b> einf. Pfad "+basis) - baum[basis] = fcts.addMerkmal(elem[basis], pfad, nindex, wert) - if logdebug >= 3: print("<--c-a-b< einf. Pfad "+basis+" "+str(index)+" "+str(baum)) - return baum - - # ----------------------------------------- - def setMerkmal(baum, pfad, wert): - logdebug = 3 # Schalter zur Debug-Einstellung innerhalb der Funktion - if logdebug >= 1: print("----------------------------------------- setMerkmal ---------------------") - if logdebug >= 1: print("setMerkmal "+pfad+" "+wert) - #MULTI_NODE = ("mm", "hmm", "omm", "ressource") - elem = baum - if logdebug >= 2 : print ("setMerkmal "+pfad+" "+wert) - a = pfad.strip('/').split('/') - if ("[@" in a[0]): - basis = a[0][0:a[0].find("[@")] - else: - basis = a[0] - if (1 == len(a)): - baum[basis] = wert - return baum - if (basis in baum): - elem = baum[basis] - else: - elem = {} - # for i in range(0, len(a)): - if logdebug >= 1: print("setMerkmal "+basis+" "+str(elem)) - baum = fcts.addMerkmal(baum, pfad, 0, wert) - if logdebug >= 1: print("setMerkmal "+basis+" "+str(baum)) - if True: - return baum - if (1 == len(a)): - elem[a[0]] = wert - for i in range(0, len(a)): - if logdebug >= 3 : print("for "+str(i)+" "+a[i]) - if ("[@" in a[i]): - basis = a[i][0:a[i].find("[@")] - else: - basis = a[i] - print ("basis "+basis ) - #if (a[i] in elem): - if ((not basis in fcts.MULTI_NODE) and (basis in elem)): - if logdebug >= 3 : print("a "+basis) - elem = elem[basis] - else: - if ("[@" in a[i]): - if logdebug >= 3 : print("b "+a[i]) - node = a[i][0:a[i].find("[@")] - attribs = a[i][a[i].find("[@")+1:a[i].find("]")] - aname = attribs[0:attribs.find("=")] - aval = attribs[attribs.find("=")+2:-1] - if logdebug >= 3 : print("b "+node+" : "+aname+" = "+aval) - - if (node in elem): - if logdebug >= 3 : print("b "+node+" in elem ") - #if logdebug >= 3 : print(json.dumps(elem[node])) - if ("dict" in str(type(elem[node]))): - if logdebug >= 3 : print(node +" elem[node] ist dict") - xnode = elem[node] - elem[node] = [] - elem[node].append(xnode) - else: - if logdebug >= 3 : print(node+" elem[node] ist nicht dict"+str(type(elem[node]))) - pnode = {} - pnode[aname] = aval - print (str(i)+" ?= "+str(len(a))) - if (i == len(a)-1): - pnode["#text"] = wert - elem[node].append(pnode) - else: - elem[node] = {} - elem = elem[node] - elem[aname] = aval - if (i == len(a)-1): - elem["#text"] = wert - elif (i == len(a)-1): - if logdebug >= 3 : print("c "+a[i]) - elem[a[i]] = wert - else: - if logdebug >= 3 : print("d "+a[i]) - elem[str(a[i])] = {} - elem = elem[str(a[i])] - return baum - - def setMerkmalContent(baum, content, index, feld): - logdebug = 1 # Schalter zur Debug-Einstellung innerhalb der Funktion - if logdebug >= 1 : print ("setMerkmalContent "+feld+" "+content["absender"]["REGNAME"]) - vrfeld = content["vrfelder"].getVrfeld(feld) - if logdebug >= 2 : print(type(vrfeld)) - if logdebug >= 2 : print(json.dumps(vrfeld)) - tabelle = "#" - - - #print (type(vrfeld)+" "+str(vrfeld)) - if (("tabelle" in vrfeld.keys()) and (vrfeld["tabelle"] == "absender")): - if logdebug >= 2 : print ("absender") - pass - elif (not "Register" in vrfeld): - if logdebug >= 2 : print ("kein Register") - return baum - elif (vrfeld["Register"].find(content["absender"]["REGNAME"])<0): - if logdebug >= 2 : print("verboten ") - return baum - if (not ("tabelle" in vrfeld.keys())): - if logdebug >= 2 : print ("keine tabelle") - return baum - elif (vrfeld["tabelle"][0:1] == "#"): - if logdebug >= 2 : print ("# tabelle") - return baum - xpath = vrfeld["Xpath"] - tabelle = vrfeld["tabelle"] - if logdebug >= 3 : print ("args "+tabelle+" "+xpath) - # pfadkennung ersetzen - if (xpath.find('${')>0): - ersatz = xpath[xpath.find('${')+2:xpath.find('}')] - npath = xpath[0:xpath.find('${')]+content["absender"][ersatz]+xpath[xpath.find('}')+1:] - else: - npath = xpath - if logdebug >= 2 : print ("npath "+npath) - npath = npath.replace('nachricht/', '') - if logdebug >= 2 : print ("npath "+npath) - if (tabelle == "absender"): - baum = fcts.setMerkmal(baum, npath, content["absender"][feld]) - return baum - # Wert ermitteln aus Content - if logdebug >= 3 : print (str(index) +" tabelle "+str(content)) - if (not content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1]): - if logdebug >= 2 : print ("Zeile fehlt") - return baum - if logdebug >= 3 : print (content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1]) - if (not feld in content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1].keys()): - if logdebug >= 2 : print ("Feld fehlt") - return baum - wert = content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1][feld] - baum = fcts.setMerkmal(baum, npath, wert) - #print("ausgabe "+str(baum)) - return baum - - def test(): - print("test in fcts") - -class merkmal: - def __init__(self): - self.merkmale = "loadyaml" \ No newline at end of file diff --git a/utils/zip_tool.py b/utils/zip_tool.py index ff2be8a..9da73b4 100644 --- a/utils/zip_tool.py +++ b/utils/zip_tool.py @@ -10,15 +10,14 @@ def untarFolder(target, targetFile): tar_file.close() pass -def openNewTarFile(target, targetFile): - job = basic.program.Job.getInstance() +def openNewTarFile(job, target, targetFile): tarfilename = os.path.join(target, targetFile) if os.path.exists(tarfilename): os.remove(tarfilename) job.m.logInfo("Archiv angelegt "+tarfilename) return tarfile.open(tarfilename, 'w:gz') -def appendFolderIntoTarFile(source, sourceFolder, tarFile): +def appendFolderIntoTarFile(job, source, sourceFolder, tarFile): workFolder = os.path.join(source, sourceFolder) for folderName, subfolders, filenames in os.walk(workFolder): for filename in filenames: