Browse Source

bugfixes

master
Ulrich Carmesin 2 years ago
parent
commit
6ba0b16edc
  1. 82
      basic/program.py
  2. 1
      test/constants.py
  3. 8
      test/test_css.py
  4. 166
      test/test_path.py
  5. 7
      utils/config_tool.py
  6. 44
      utils/configs/path.yml
  7. 35
      utils/configs/txt
  8. 10
      utils/conn_tool.py
  9. 1
      utils/css_tool.py
  10. 15
      utils/file_tool.py
  11. 68
      utils/match_tool.py

82
basic/program.py

@ -20,6 +20,9 @@ import utils.date_tool
import utils.path_tool import utils.path_tool
import utils.file_tool import utils.file_tool
BASIS_FILE = "basis.yml"
EXCP_NO_BASIS_FILE = "basis file cant be found"
jobdef = { jobdef = {
"unit": { "unit": {
"pardef": "", "pardef": "",
@ -104,14 +107,17 @@ jobdef = {
def setGlobal(): def setGlobal():
pass pass
EXCP_CANT_POP = "cant pop this job from the instances"
class Job: class Job:
__instance = None __instance = None
instances = []
def __init__ (self, program): def __init__ (self, program):
print ("################# init Job ## " + program + " #################") print ("################# init Job ## " + program + " #################")
self.program = program self.program = program
Job.__instance = self Job.__instance = self
Job.pushInstance(self)
par = Parameter(program) par = Parameter(program)
self.par = par self.par = par
print("prog-42 " + str(self.par.basedir)) print("prog-42 " + str(self.par.basedir))
@ -129,16 +135,42 @@ class Job:
print("prog-50 " + str(self.par.basedir)) print("prog-50 " + str(self.par.basedir))
@staticmethod @staticmethod
def popInstance(): def popInstance(pjob=None):
job = Job.getInstance() if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
Job.__instance = None raise Exception(EXCP_CANT_POP)
if len(Job.instances) < 1:
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(EXCP_CANT_POP)
if len(Job.instances) > 0:
topjob = Job.instances.pop()
Job.instances.append(topjob)
Job.__instance = topjob
else:
Job.__instance = None
return job return job
@staticmethod @staticmethod
def pushInstance(job): def pushInstance(pjob):
Job.__instance = job if len(Job.instances) > 0:
return job 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): def resetInstance(program):
job = Job.getInstance() job = Job.getInstance()
if job is not None: if job is not None:
@ -147,9 +179,11 @@ class Job:
Job(program) Job(program)
return Job.__instance return Job.__instance
def setProgram(self, program): def setProgram(self, program):
self.program = program self.program = program
basedir = jobdef[program]["basedir"] basedir = jobdef[program]["basedir"]
self.basedir = basedir
if (self.par is not None): if (self.par is not None):
setattr(self.par, "program", program) setattr(self.par, "program", program)
setattr(self.par, "basedir", basedir) setattr(self.par, "basedir", basedir)
@ -162,12 +196,14 @@ class Job:
utils.path_tool.composePattern("{"+basedir+"}", None)) utils.path_tool.composePattern("{"+basedir+"}", None))
self.par.setParameterLoaded() self.par.setParameterLoaded()
@staticmethod
def getInstance(): def getInstance():
if (Job.__instance is not None): if (Job.__instance is not None):
return Job.__instance return Job.__instance
else: else:
return None return None
def startJob(self): def startJob(self):
self.start = datetime.now() self.start = datetime.now()
print("prog-68 " + str(self.par.basedir)) print("prog-68 " + str(self.par.basedir))
@ -179,6 +215,7 @@ class Job:
self.m.debug(basic.message.LIMIT_INFO, "# # # 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()
def stopJob(self, reboot=0): def stopJob(self, reboot=0):
self.ende = datetime.now() self.ende = datetime.now()
self.dumpParameter() self.dumpParameter()
@ -193,21 +230,24 @@ class Job:
if reboot == 0: if reboot == 0:
exit(rc) exit(rc)
def dumpParameter(self): def dumpParameter(self):
parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None) parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None)
if not os.path.exists(parpath):
return None
output = {} output = {}
cconf = basic.componentHandling.getComponentDict() cconf = basic.componentHandling.getComponentDict()
output["par"] = self.par.__dict__ output["par"] = self.par.__dict__
if len(cconf) < 1:
utils.file_tool.writeFileDict(self.m, parpath, output)
return
output["comps"] = {} output["comps"] = {}
for c in cconf: for c in cconf:
output["comps"][c] = {} output["comps"][c] = {}
for x in ["function", "conn"]: for x in ["function", "conn"]:
output["comps"][c][x] = cconf[c][x] output["comps"][c][x] = cconf[c][x]
if x == "conn" and "passwd" in cconf[c][x]: if x == "conn" and "passwd" in cconf[c][x]:
output["comps"][c][x]["passwd"] = "xxxxx" cconf["comps"][c][x]["passwd"] = "xxxxx"
utils.file_tool.writeFileText(self.m, parpath, output) utils.file_tool.writeFileDict(self.m, parpath, output)
def loadParameter(self): def loadParameter(self):
output = {} output = {}
@ -221,6 +261,7 @@ class Job:
output[k] = copy.deepcopy(doc[k]) output[k] = copy.deepcopy(doc[k])
return output return output
def getParameter(self, parameter): def getParameter(self, parameter):
if hasattr(self.par, parameter): if hasattr(self.par, parameter):
return getattr(self.par, parameter) return getattr(self.par, parameter)
@ -228,6 +269,8 @@ class Job:
neu = utils.date_tool.getActdate(utils.date_tool.F_DIR) neu = utils.date_tool.getActdate(utils.date_tool.F_DIR)
# setattr(self.par, parameter, neu) # setattr(self.par, parameter, neu)
return neu return neu
def hasElement(self, parameter, elem): def hasElement(self, parameter, elem):
if hasattr(self.par, parameter): if hasattr(self.par, parameter):
print (parameter + " in Parameter") print (parameter + " in Parameter")
@ -264,6 +307,7 @@ class Job:
else: else:
print(text) print(text)
# ------------------------------------------------------------------------------------------------------------------
class Parameter: class Parameter:
print ("class Parameter") print ("class Parameter")
def __init__ (self, program): def __init__ (self, program):
@ -274,6 +318,7 @@ class Parameter:
print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}") print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}")
if (program != "unit"): self.setParameter() if (program != "unit"): self.setParameter()
def setBasedir(self, program): def setBasedir(self, program):
if jobdef[program]: if jobdef[program]:
self.basedir = jobdef[program]["basedir"] self.basedir = jobdef[program]["basedir"]
@ -285,6 +330,7 @@ class Parameter:
else: else:
self.basedir = "debugs" self.basedir = "debugs"
def checkParameter(self): def checkParameter(self):
job = Job.getInstance() job = Job.getInstance()
print (f"Parameter initialisiert {self.program}") print (f"Parameter initialisiert {self.program}")
@ -344,6 +390,7 @@ class Parameter:
return ("tsbase", str(self.tsdir)) return ("tsbase", str(self.tsdir))
return None return None
def setParameterArgs(self, args): def setParameterArgs(self, args):
job = Job.getInstance() job = Job.getInstance()
print("setParArgs " + str(type(args))) print("setParArgs " + str(type(args)))
@ -381,18 +428,23 @@ class Parameter:
return self[a[0]][a[1]] return self[a[0]][a[1]]
return return
# ------------------------------------------------------------------------------------------------------------------
class Configuration: class Configuration:
def __init__ (self, program): def __init__ (self, program):
self.program = program self.program = program
print (f"job initialisiert {self.program}") print (f"job initialisiert {self.program}")
if program == "unit": if program == "unit":
if (os.path.exists('../conf/basis.yml')): if (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))):
self.setConfiguration('../conf/basis.yml') self.setConfiguration(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))
return return
elif (os.path.exists('conf/basis.yml')): elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))):
self.setConfiguration('../conf/basis.yml') self.setConfiguration(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))
return
elif (os.path.exists(utils.path_tool.rejoinPath("config", BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("config", BASIS_FILE))
return return
self.setConfiguration('conf/basis.yml') raise Exception(EXCP_NO_BASIS_FILE)
def setConfiguration(self, path): def setConfiguration(self, path):
self.confs = {} self.confs = {}

1
test/constants.py

@ -1 +1,2 @@
HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest" HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest"
OS_SYSTEM = "linux"

8
test/test_css.py

@ -41,7 +41,7 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(("class" in text), True) self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles") text = utils.css_tool.getInternalStyle("diffFiles")
print(text) print(text)
self.assertEqual(len(text), 237) self.assertEqual(len(text), 262)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("resultFile") text = utils.css_tool.getInternalStyle("resultFile")
print(text) print(text)
@ -49,7 +49,7 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles,resultFile") text = utils.css_tool.getInternalStyle("diffFiles,resultFile")
print(text) print(text)
self.assertEqual(len(text), 440) self.assertEqual(len(text), 465)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 0) self.assertEqual(len(text), 0)
@ -65,11 +65,11 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(len(text), 55) self.assertEqual(len(text), 55)
self.assertEqual(("<link " in text and "stylesheet" in text), True) self.assertEqual(("<link " in text and "stylesheet" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 189) self.assertEqual(len(text), 216)
print(text) print(text)
print(str(len(text))) print(str(len(text)))
text = utils.css_tool.getExternalStyle("diffFiles,resultFile") text = utils.css_tool.getExternalStyle("diffFiles,resultFile")
self.assertEqual(len(text), 422) self.assertEqual(len(text), 449)
print(text) print(text)
print(str(len(text))) print(str(len(text)))

166
test/test_path.py

@ -1,44 +1,156 @@
import unittest, os import unittest
import os
import inspect
import utils.path_tool import utils.path_tool
from basic.program import Job import basic.program
import basic.constants as B
import test.constants import test.constants
import test.testtools
import utils.path_const as P
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern",
"test_extractPath", "test_extractPattern"]
#TEST_FUNCTIONS = [ "test_extractPath"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def runTest(self): mymsg = "--------------------------------------------------------------"
self.test_path()
def test_key(self): def setTestPaths(self, job):
# here you can overwrite your workspace-configuration in order to get stable unittests
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_HOME] = "home/unittest"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] = "home/unittest/tdata"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV] = "home/unittest/env"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV] = "home/unittest/archiv"
pass pass
def test_path(self): def setPathConfig(self, pt):
job = Job("unit") # here you can overwrite your workspace-configuration in order to get stable unittests
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", paths = pt.getInstance()
"modus": "unit", "testcase": "TESTFALL", "release": "V0.1", "tctime": "2021-08-21_12-02-01" } paths.pattern[P.P_ENVBASE] = "{job.conf.environment}/{job.par.environment}"
job.par.setParameterArgs(args)
def test_key(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
res = utils.path_tool.getKeyValue("job.par."+B.PAR_ENV, None)
self.assertEqual(res, test.testtools.DEFAULT_ENV)
cnttest += 1
for par in [B.ATTR_PATH_TDATA, B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV, B.ATTR_PATH_PROGRAM]:
res = utils.path_tool.getKeyValue("job.conf."+par, None)
self.assertIn(HOME_PATH, res)
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_rejoinPath(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
if OS_SYSTEM == "linux":
res = utils.path_tool.rejoinPath("home", "ulrich")
self.assertEqual(res, "/home/ulrich")
cnttest += 1
res = utils.path_tool.rejoinPath("opt")
self.assertEqual(res, "/opt")
cnttest += 1
res = utils.path_tool.rejoinPath("http://domain.com", "application", "function")
self.assertEqual(res, "http://domain.com/application/function")
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_composePath(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# set the relevant datastrutures
job = test.testtools.getJob()
comp = test.testtools.getComp()
pt = utils.path_tool.PathConf() pt = utils.path_tool.PathConf()
r = utils.path_tool.getKeyValue("job.par.application") self.setTestPaths(job)
#print(r) self.setPathConfig(pt)
r = utils.path_tool.getKeyValue("job.conf.results") # tests
#print(r) path = utils.path_tool.composePath(P.P_ENVBASE, None)
self.assertEqual(r, os.path.join(HOME_PATH,"test","target")) self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path)
r = utils.path_tool.composePath("tcbase", None) self.assertIn(getattr(job.par, B.PAR_ENV), path)
#print(r) cnttest += 2
args = { "application" : "TEST" , "application" : "ENV01", "modus" : "unit", "loglevel" : "debug", path = utils.path_tool.composePath(P.P_TCLOG, None)
"tool" : "job_tool", "tsdir": os.path.join(HOME_PATH, "test","conf","lauf","V0.1","startjob","2021-08-21_18-ß2-01")} self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], path)
job = Job.resetInstance("unit") self.assertIn(getattr(job.par, B.PAR_TESTCASE), path)
job.par.setParameterArgs(args) cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_composePattern(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# set the relevant datastrutures
job = test.testtools.getJob()
comp = test.testtools.getComp()
pt = utils.path_tool.PathConf()
self.setTestPaths(job)
self.setPathConfig(pt)
# tests
path = utils.path_tool.composePattern("{"+P.P_ENVBASE+"}", None)
self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path)
self.assertIn(getattr(job.par, B.PAR_ENV), path)
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_extractPattern(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
pt = utils.path_tool.PathConf()
job = test.testtools.getJob("ts", test.testtools.DEFAULT_APP, test.testtools.DEFAULT_ENV, "2021-08-21_18-ß2-01")
r = utils.path_tool.extractPattern("tsbase" ) r = utils.path_tool.extractPattern("tsbase" )
#print(r)
self.assertEqual(r[0][1], "job.conf.archiv") self.assertEqual(r[0][1], "job.conf.archiv")
self.assertEqual(r[3][0], "_") self.assertEqual(r[1][1], P.KEY_TESTSUITE)
r = utils.path_tool.extractPath("tsbase" , os.path.join(HOME_PATH, "test","conf","lauf","V0.1","startjob_2021-08-21_10-02-01")) self.assertEqual(r[1][2], "testlauf")
#print("r " + str(r)) cnttest += 3
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_extractPath(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
pt = utils.path_tool.PathConf()
r = utils.path_tool.extractPath("tsbase" , os.path.join(HOME_PATH, "test","conf","lauf","testlauf","startjob_2021-08-21_10-02-01"))
print("r " + str(r))
#print(vars(job.par)) #print(vars(job.par))
self.assertEqual(job.par.release, "V0.1") #self.assertEqual(job.par.release, "V0.1")
self.assertEqual(job.par.usecase, "startjob") self.assertEqual(job.par.usecase, "startjob")
self.assertEqual(job.par.tltime, "2021-08-21_10-02-01") self.assertEqual(job.par.tstime, "2021-08-21_10-02-01")
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

7
utils/config_tool.py

@ -41,19 +41,20 @@ def getConfigPath(modul, name, subname=""):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("config_tool")-4 verify = job.getDebugLevel("config_tool")-4
job.debug(verify, "getConfig " + modul + ", " + name) job.debug(verify, "getConfig " + modul + ", " + name)
#TODO path rejoin, config as const
if modul == "tool": if modul == "tool":
for format in CONFIG_FORMAT: for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("home") , "configs","tool_"+name+"."+format) pathname = os.path.join(job.conf.confs.get("paths").get("home") , "config" ,"tool_"+name+"."+format)
job.debug(verify, "1 " + pathname) job.debug(verify, "1 " + pathname)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
for format in CONFIG_FORMAT: for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "utils", "configs", name+"."+format) pathname = os.path.join(job.conf.confs.get("paths").get("program"), "utils", "config", name+"."+format)
job.debug(verify, "2 " + pathname) job.debug(verify, "2 " + pathname)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
for format in CONFIG_FORMAT: for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("environment"), job.par.environment, "configs", "tool_"+ name+"."+format) pathname = os.path.join(job.conf.confs.get("paths").get("environment"), job.par.environment, "config", "tool_"+ name+"."+format)
job.debug(verify, "3 " + pathname) job.debug(verify, "3 " + pathname)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname

44
utils/configs/path.yml

@ -1,44 +0,0 @@
#
pattern:
# Keywords
log: log
parfile: PARAMETER_{job.par.application}_{job.par.environment}.yml
precond: vorher
postcond: nachher
diff: diff_fach
prediff: diff_init
rundiff: diff_ablauf
result: Ergebnisse/{comp.name}
origin: original
parts: teilergebnisse
sumfile: xxx
backup: backup
reffile: Herkunft.txt
tc: testfall
ts: testlauf
debugname: debug
logname: log
debugs: "{job.conf.home}/test/log"
# environment
envbase: "{job.conf.environment}/{job.par.environment}"
envlog: "{envbase}/{log}"
envparfile: "{envbase}/{parfile}"
# testcase
tcbase: "{job.conf.archiv}/{job.par.testcase}/{job.par.tctime}"
tclog: "{tcbase}/{log}"
tcresult: "{tcbase}/{result}"
tcparfile: "{tcbase}/{parfile}"
tcdiff: "{tcresult}/{diff}"
tcprediff: "{tcresult}/{prediff}"
tcrundiff: "{tcresult}/{rundiff}"
tcprecond: "{tcresult}/{precond}"
tcpostcond: "{tcresult}/{postcond}"
# testset
tsbase: "{job.conf.archiv}/{ts}/{job.par.usecase}_{job.par.tstime}"
tslog: "{tsbase}/{log}"
tsparfile: "{tsbase}/{parfile}"
tssum: "{tsbase}/Ergebnis"
# expectation-result rs
xpbase: "{job.conf.expect}/{job.par.branch}"
xpresult: "{xpbase}/{result}"
xpbackup: "{xpbase}/{result}"

35
utils/configs/txt

@ -1,35 +0,0 @@
#
pattern:
# Keywords
log: Protokolle
parfile: PARAMETER_{job.par.application}_{job.par.environ}.yml
precond: vorher
postcond: nachher
diff: diff_fach
prediff: diff_init
rundiff: diff_ablauf
result: Ergebnisse/{comp.name}
origin: original
parts: teilergebnisse
sumfile:
backup: backup
reffile: Herkunft.txt
tc: testfall
ts: testlauf
# testcase
tcbase: {job.conf.archiv}/{job.par.release}/{job.par.testcase}/{job.par.tctime}
tcresult: {tcbase}/{result}
tcparfile: {tcbase}/{parfile}
tcdiff: {tcresult}/{diff}
tcprediff: {tcresult}/{prediff}
tcrundiff: {tcresult}/{rundiff}
precond: {tcresult}/vorher
postcond: {tcresult}/nachher
# testset
tsbase: {job.conf.archiv}/{job.par.release}/{job.par.usecase}_{job.par.tltime}
tsparfile: {tsbase}/{parfile}
tssum: {tsbase}/Ergebnis
# target-result rs
rsbase: {job.conf.results}/{job.par.branch}
rsresult: {rsbase}/{result}
rsbackup: {rsbase}/{result}

10
utils/conn_tool.py

@ -6,6 +6,7 @@
import basic.program import basic.program
import utils.config_tool import utils.config_tool
import basic.constants as B import basic.constants as B
import utils.data_const as D
def getConnection(comp, nr): def getConnection(comp, nr):
@ -34,7 +35,14 @@ def getConnection(comp, nr):
def getConnections(comp): def getConnections(comp):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("conn_tool") verify = job.getDebugLevel("conn_tool")
print("getConnections " + comp) msg = None
if hasattr(comp, "m") and comp.m is not None:
msg = comp.m
elif hasattr(job, "m") and job.m is not None:
msg = job.m
else:
raise Exception("message-object is missing")
msg.debug(verify, "getConnections " + comp)
conn = {} conn = {}
conns = [] conns = []
if job.conf.confs.get("tools").get("connsrc") == D.DFILE_TYPE_YML: if job.conf.confs.get("tools").get("connsrc") == D.DFILE_TYPE_YML:

1
utils/css_tool.py

@ -4,6 +4,7 @@ CSS_CLASS = {
"table, td, th": "border: 1px solid grey;font-family:sans-serif" "table, td, th": "border: 1px solid grey;font-family:sans-serif"
}, },
"diffFiles": { "diffFiles": {
"novalue": "color:grey",
"diffA": "color:green;font-weight:bold;", "diffA": "color:green;font-weight:bold;",
"diffB": "color:crimson;font-weight:bold;", "diffB": "color:crimson;font-weight:bold;",
"acceptA": "color:darkblue;", "acceptA": "color:darkblue;",

15
utils/file_tool.py

@ -126,16 +126,23 @@ def detectFileEncode(path, msg): # return ""
print(path) print(path)
cntIso = 0 cntIso = 0
cntUtf = 0 cntUtf = 0
j = 0
CHAR_ISO = [ 196, 228, 214, 246, 220, 252, 191 ]
with open(path, 'rb') as file: with open(path, 'rb') as file:
while (byte := file.read(1)): byte = file.read(1)
while (byte):
i = int.from_bytes(byte, "little") i = int.from_bytes(byte, "little")
#byte = file.read(1) #byte = file.read(1)
if ((i == 196) or (i == 228) or (i == 214) or (i == 246) or (i == 220) or (i == 252) or (i == 191)): if (i in CHAR_ISO):
cntIso += 1 cntIso += 1
if (i == 160): if (i == 160):
pass pass
elif (i > 127): elif (i > 127):
cntUtf += 1 cntUtf += 1
j += 1
l = i
byte = file.read(1)
file.close()
if (cntIso > cntUtf): if (cntIso > cntUtf):
return 'iso-8859-1' return 'iso-8859-1'
return 'utf-8' return 'utf-8'
@ -195,8 +202,8 @@ def writeFileDict(msg, path, dict, enc="utf-8"):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
mkPaths(path, msg) mkPaths(path, msg)
if D.DFILE_TYPE_YML in path[-5:]: if D.DFILE_TYPE_YML in path[-5:]:
with open(path, 'r', encoding=enc) as file: with open(path, 'w', encoding=enc) as file:
doc = yaml.dump(dict, file) yaml.dump(dict, file)
file.close() file.close()
elif D.DFILE_TYPE_JSON in path[-5:]: elif D.DFILE_TYPE_JSON in path[-5:]:
with open(path, 'w', encoding=enc) as file: with open(path, 'w', encoding=enc) as file:

68
utils/match_tool.py

@ -126,6 +126,26 @@ class Matching():
self.htmltext = htmltext self.htmltext = htmltext
def ignorePreid(matching, key):
if matching.matchtype == M.MATCH_POSTCOND:
key_int = extractKeyI(key)
if matching.linksB[key] != B.SVAL_NULL:
return False
if matching.preIds is None or len(matching.preIds) < 1:
return False
for ids in matching.preIds:
hit = True
for k in ids:
row = matching.sideB[key_int]
if ids[k] == row[k]:
pass
else:
hit = False
if hit:
return True
return False
def matchFiles(matching): def matchFiles(matching):
""" """
@ -191,13 +211,14 @@ def matchRestfit(matching):
job.debug(verify, "matchRestfit " + x) job.debug(verify, "matchRestfit " + x)
pair = matching.nomatch[x] pair = matching.nomatch[x]
if (matching.isHitA(pair[0])): if (matching.isHitA(pair[0])):
print("A " + pair[0] + " bereits zugeordnet mit " + matching.linksA[pair[0]]) job.debug(verify, "A " + pair[0] + " bereits zugeordnet mit " + matching.linksA[pair[0]])
pass
if (matching.isHitB(pair[1])): if (matching.isHitB(pair[1])):
print("B " + pair[1] + " bereits zugeordnet mit " + matching.linksB[pair[1]]) job.debug(verify, "B " + pair[1] + " bereits zugeordnet mit " + matching.linksB[pair[1]])
continue continue
if (matching.isHitA(pair[0])): if (matching.isHitA(pair[0])):
continue continue
print("neues Matching " + pair[0] + " " + pair[1]) job.debug(verify, "neues Matching " + pair[0] + " " + pair[1])
matching.setHit(pair[0], pair[1]) matching.setHit(pair[0], pair[1])
@ -236,6 +257,8 @@ def setMatchkeys(matching, path):
raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY]) raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY])
if (not b[1].isnumeric()): if (not b[1].isnumeric()):
raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY]) raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY])
if (b[0] not in M.SIM_DEFAULT):
raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY])
k = "k"+b[0]+""+b[1].zfill(2) k = "k"+b[0]+""+b[1].zfill(2)
job.debug(verify, "ddl " + f) job.debug(verify, "ddl " + f)
keys[k] = {"ktyp": b[0], D.DDL_FNAME: ddl[f][D.DDL_FNAME], D.DDL_TYPE: ddl[f][D.DDL_TYPE], "rule": ddl[f][D.DDL_ACCEPTANCE]} keys[k] = {"ktyp": b[0], D.DDL_FNAME: ddl[f][D.DDL_FNAME], D.DDL_TYPE: ddl[f][D.DDL_TYPE], "rule": ddl[f][D.DDL_ACCEPTANCE]}
@ -254,20 +277,31 @@ def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT):
topBsim = "" topBsim = ""
topTsim = "" topTsim = ""
for k in sorted(matching.matchkeys): for k in sorted(matching.matchkeys):
if not D.DDL_FNAME in matching.matchkeys[k]:
job.m.logError("technical Attribut is missing "+k )
continue
if M.SIM_TECHNICAL in k: if M.SIM_TECHNICAL in k:
mTsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), str(rB[matching.matchkeys[k][D.DDL_FNAME]])) 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]]),
str(rB[matching.matchkeys[k][D.DDL_FNAME]]))
else:
mTsim += "00"
topTsim += "99" topTsim += "99"
if M.SIM_BUSINESS in k: if M.SIM_BUSINESS in k:
mTsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), str(rB[matching.matchkeys[k][D.DDL_FNAME]])) if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB:
topTsim += "99" mBsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]),
str(rB[matching.matchkeys[k][D.DDL_FNAME]]))
else:
mBsim += "55"
topBsim += "99"
if mBsim == topBsim and mTsim == topTsim: if mBsim == topBsim and mTsim == topTsim:
job.debug(verify, "Treffer ") job.debug(verify, "Treffer ")
return "MATCH" return "MATCH"
elif simorder[0:1] == M.SIM_TECHNICAL and mTsim == topTsim: elif simorder[0:1] == M.SIM_BUSINESS and mBsim == topBsim:
job.debug(verify, "Treffer ") job.debug(verify, "Treffer ")
return "MATCH" return "MATCH"
elif simorder[0:1] == M.SIM_BUSINESS and mBsim == topBsim: elif simorder[0:1] == M.SIM_TECHNICAL and mTsim == topTsim:
job.debug(verify, "Treffer ") job.debug(verify, "Treffer ")
return "MATCH" return "MATCH"
elif simorder[0:1] == M.SIM_TECHNICAL: elif simorder[0:1] == M.SIM_TECHNICAL:
@ -377,6 +411,7 @@ def matchArray(matching, sideA, sideB, path):
job.debug(verify, "matchArray " + path + "\n.." + matching.htmltext) job.debug(verify, "matchArray " + path + "\n.." + matching.htmltext)
matching.sideA = sideA matching.sideA = sideA
matching.sideB = sideB matching.sideB = sideB
setMatchkeys(matching, path)
matchBestfit(matching, path) matchBestfit(matching, path)
matchRestfit(matching) matchRestfit(matching)
a = path.split(":") a = path.split(":")
@ -419,9 +454,9 @@ def compareRows(matching, path):
htmltext += markRow(matching, header, matching.sideA[int(extractKeyI(k))], M.M_SIDE_A) htmltext += markRow(matching, header, matching.sideA[int(extractKeyI(k))], M.M_SIDE_A)
matching.setCssClass("result3") matching.setCssClass("result3")
for k in sorted(matching.linksB): for k in sorted(matching.linksB):
if ignorePreid(matching, k):
continue
if (not matching.isHitB(k)): if (not matching.isHitB(k)):
if ignorePrecond(matching):
continue
htmltext += markRow(matching, header, matching.sideB[int(extractKeyI(k))], M.M_SIDE_B) htmltext += markRow(matching, header, matching.sideB[int(extractKeyI(k))], M.M_SIDE_B)
matching.setCssClass("result2") matching.setCssClass("result2")
htmltext += "</table>" htmltext += "</table>"
@ -429,19 +464,6 @@ def compareRows(matching, path):
return htmltext return htmltext
def ignorePrecond(matching):
job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1
if not matching.matchtype == M.MATCH_POSTCOND:
return False
if not hasattr(job.par, "matchdelta"):
return False
if len(matching.preIds) < 1:
return False
return False
def markRow(matching, header, row, side): def markRow(matching, header, row, side):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4

Loading…
Cancel
Save