Browse Source

refactor b.constants only moves

master
Ulrich Carmesin 3 years ago
parent
commit
ef6f34aaff
  1. 62
      basic/catalog.py
  2. 44
      basic/constants.py
  3. 24
      basic/program.py
  4. 50
      test/test_catalog.py
  5. 49
      test/test_config.py
  6. 57
      test/test_file.py
  7. 93
      utils/config_tool.py
  8. 24
      utils/file_tool.py
  9. 36
      utils/path_const.py

62
basic/catalog.py

@ -0,0 +1,62 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import os
import basic.program
import basic.constants as B
import utils.path_const as P
EXP_KEY_MISSING = "key is missing {}"
EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}"
class Catalog:
__instance = None
"""
in this class there should be managed each defined key-value-pairs
the pairs ara loaded from the path testdata/catalog:
* initially the csv-file catalog.csv
* on demand other csv-files in the path
"""
def __init__(self):
self.catalog = {}
Catalog.__instance = self
pass
@staticmethod
def getInstance():
if Catalog.__instance == None:
return Catalog()
return Catalog.__instance
def getValue(self, domain, key):
"""
this function gets the value of the domain an key
:param domain:
:param key:
:return:
"""
job = basic.program.Job.getInstance()
if not (isinstance(domain, str) and len(domain)):
raise Exception(EXP_KEY_MISSING, (domain, key))
if not (isinstance(key, str) and len(key)):
raise Exception(EXP_KEY_MISSING, (domain, key))
if domain not in self.catalog:
self.readDomain(domain)
if key not in self.catalog[domain][key]:
raise Exception(EXP_KEY_DOESNT_EXIST, (domain, key))
return self.catalog[domain][key]
def readDomain(self, domain):
"""
:param domain:
:return:
"""
job = basic.program.Job.getInstance()
if not (isinstance(domain, str) and len(domain)):
raise Exception(EXP_KEY_MISSING, (domain))

44
basic/constants.py

@ -19,11 +19,17 @@ The constants desribes the keywords of the main datastructures, these are
* the internal datastructure * the internal datastructure
""" """
EXCEPT_NOT_IMPLEMENT = "method is not implemented"
EXCEPT_NOT_INITIALIZED = "class is not initialized" # -------------------------------------------------------------
# values and keywords
BASIS_FILE = "basis.yml"
SVAL_YES = "y"
SVAL_NO = "n"
SVAL_NULL = "null"
# -------------------------------------------------------------
# parameter with arguments
PAR_APP = 'application' PAR_APP = 'application'
""" definition of the application which will be tested """ """ definition of the application which will be tested """
PAR_ENV = 'environment' PAR_ENV = 'environment'
@ -54,8 +60,16 @@ PAR_TCTIME = "tctime"
PAR_TSTIME = "tstime" PAR_TSTIME = "tstime"
PAR_TESTINSTANCES = "testinstances" PAR_TESTINSTANCES = "testinstances"
""" name of testcase extracted from PAR_TCDIR """ """ name of testcase extracted from PAR_TCDIR """
PAR_DB_WHERE = "dbwhere"
""" optional parameter with a where-clause """
PAR_DB_PARTITION = "dbparts"
""" optional parameter for partitions of a partitioned tables """
# -------------------------------------------------------------
# attributes
# -------------------------------------------------------------
# structure - nodes
# the internal datastructure is a tree with this design: # the internal datastructure is a tree with this design:
# root { : constant # root { : constant
# + option { : constant # + option { : constant
@ -81,14 +95,11 @@ DATA_NODE_COMP = "comp"
""" This constant defines """ """ This constant defines """
DATA_NODE_PAR = "par" DATA_NODE_PAR = "par"
SVAL_YES = "y"
SVAL_NO = "n"
SVAL_NULL = "null"
""" This constant defines """ """ This constant defines """
TOPIC_NODE_DB = "db" TOPIC_NODE_DB = "db"
# testexec, db_abstr
ATTR_DB_PARTITION = "partitioned" ATTR_DB_PARTITION = "partitioned"
""" optional attribute if table is partitioned """ optional attribute if table is partitioned
- this keyword delimited by "+" will be replaced by partition-names which are parametrized """ - this keyword delimited by "+" will be replaced by partition-names which are parametrized """
@ -104,10 +115,6 @@ ATTR_DB_SCHEMA = "schema"
""" optional attribute for technical name of the schema """ """ optional attribute for technical name of the schema """
ATTR_DB_TABNAME = "tabname" ATTR_DB_TABNAME = "tabname"
""" optional attribute in order to use a different technical name for the db-table """ """ optional attribute in order to use a different technical name for the db-table """
PAR_DB_WHERE = "dbwhere"
""" optional parameter with a where-clause """
PAR_DB_PARTITION = "dbparts"
""" optional parameter for partitions of a partitioned tables """
TOPIC_NODE_CLI = "cli" TOPIC_NODE_CLI = "cli"
TOPIC_NODE_API = "api" TOPIC_NODE_API = "api"
@ -140,13 +147,14 @@ ATTR_PATH_TDATA = "testdata"
""" This constant defines the folder in testing-filesystem with the testcase-specifications """ """ This constant defines the folder in testing-filesystem with the testcase-specifications """
ATTR_PATH_PATTN = "pattern" ATTR_PATH_PATTN = "pattern"
""" This constant defines the debug-folder in testing-filesystem """ """ This constant defines the debug-folder in testing-filesystem """
SUBJECT_APPS = "applications" # | x | | | | CompHandling
#SUBJECT_APPS = "applications" # | x | | | | CompHandling
SUBJECT_INST = "instance" # | | | | x | CompHanlding SUBJECT_INST = "instance" # | | | | x | CompHanlding
ATTR_INST_CNT = "count" # | | | | x | CompHanlding ATTR_INST_CNT = "count" # | | | | x | CompHanlding
ATTR_INST_SGL = "single" ATTR_INST_SGL = "single"
ATTR_INST_SUBCOMP = "components" ATTR_INST_SUBCOMP = "components"
SUBJECT_FCT = "function" # | | | | x | main-programs #SUBJECT_FCT = "function" # | | | | x | main-programs
SUBJECT_ARTS = "artifact" # | | | | x | Component SUBJECT_ARTS = "artifact" # | | | | x | Component
""" """
@ -156,11 +164,11 @@ in this subject-node are each kind of result of any component with the structure
* * partial-component - to-know: the existence of db-tables can be defined in the ddl-tree * * partial-component - to-know: the existence of db-tables can be defined in the ddl-tree
* * * specific attributes - it overrides the general attributes * * * specific attributes - it overrides the general attributes
""" """
ATTR_ARTS_DB = "db" #ATTR_ARTS_DB = "db"
ATTR_ARTS_LOG = "log" ATTR_ARTS_LOG = "log"
ATTR_ARTS_LOB = "lob" ATTR_ARTS_LOB = "lob"
ATTR_ARTS_FILE = "file" ATTR_ARTS_FILE = "file"
SUBJECT_DB = "databases" # | | | | # | db*_tools, match_tool #SUBJECT_DB = "databases" # | | | | # | db*_tools, match_tool
SUBJECT_CONN = "conn" # | | x | | | conn_tool, db*_tools, cli*_toold SUBJECT_CONN = "conn" # | | x | | | conn_tool, db*_tools, cli*_toold
ATTR_TYPE = "type" # | x | x | | x | conn_tool, toolHandling, db*_tools ATTR_TYPE = "type" # | x | x | | x | conn_tool, toolHandling, db*_tools
@ -169,3 +177,11 @@ RULE_ACCEPTANCE = "acceptance" # | | | | x | tools_match
ATTR_STEP_ARGS = "args" ATTR_STEP_ARGS = "args"
ATTR_DATA_REF = "_nr" ATTR_DATA_REF = "_nr"
# -------------------------------------------------------------
# exception texts
EXP_NO_BASIS_FILE = "basis file cant be found"
EXCEPT_NOT_IMPLEMENT = "method is not implemented"
EXCEPT_NOT_INITIALIZED = "class is not initialized"

24
basic/program.py

@ -20,8 +20,6 @@ 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": {
@ -137,7 +135,7 @@ class Job:
@staticmethod @staticmethod
def popInstance(pjob=None): def popInstance(pjob=None):
if pjob is not None and Job.__instance is not None and Job.__instance != pjob: if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
raise Exception(EXCP_CANT_POP) raise Exception(B.EXP_CANT_POP)
if len(Job.instances) < 1: if len(Job.instances) < 1:
return None return None
if len(Job.instances) == 1: if len(Job.instances) == 1:
@ -150,7 +148,7 @@ class Job:
if pjob is not None and job is not None and job != pjob: if pjob is not None and job is not None and job != pjob:
Job.instances.append(job) Job.instances.append(job)
Job.__instance = job Job.__instance = job
raise Exception(EXCP_CANT_POP) raise Exception(B.EXP_CANT_POP)
if len(Job.instances) > 0: if len(Job.instances) > 0:
topjob = Job.instances.pop() topjob = Job.instances.pop()
Job.instances.append(topjob) Job.instances.append(topjob)
@ -435,16 +433,16 @@ class Configuration:
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(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))): if (os.path.exists(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("..", "config", BASIS_FILE)) self.setConfiguration(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))
return return
elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))): elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("..", "config", BASIS_FILE)) self.setConfiguration(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))
return return
elif (os.path.exists(utils.path_tool.rejoinPath("config", BASIS_FILE))): elif (os.path.exists(utils.path_tool.rejoinPath("config", B.BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("config", BASIS_FILE)) self.setConfiguration(utils.path_tool.rejoinPath("config", B.BASIS_FILE))
return return
raise Exception(EXCP_NO_BASIS_FILE) raise Exception(B.EXP_NO_BASIS_FILE)
def setConfiguration(self, path): def setConfiguration(self, path):
self.confs = {} self.confs = {}
@ -467,6 +465,10 @@ class Configuration:
elif len(a) == 3: elif len(a) == 3:
self.confs[a[0]][a[1]][a[2]] = val self.confs[a[0]][a[1]][a[2]] = val
def getPath(self, key):
return self.confs.get(B.SUBJECT_PATH).get(key)
def getJobConf(self, key): def getJobConf(self, key):
a = key.split(":") a = key.split(":")
if len(a) == 1: if len(a) == 1:

50
test/test_catalog.py

@ -0,0 +1,50 @@
import unittest
import os
import inspect
import utils.path_tool
import basic.program
import basic.constants as B
import test.constants
import test.testtools
import utils.path_const as P
import basic.catalog
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):
mymsg = "--------------------------------------------------------------"
def test_class(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
catalog = basic.catalog.Catalog.getInstance()
self.assertIsNotNone(catalog)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
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()
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
unittest.main()

49
test/test_config.py

@ -1,30 +1,53 @@
import unittest import unittest
import os
import inspect
import utils.config_tool as t import utils.config_tool as t
from basic.program import Job from basic.program import Job
import test.constants import test.constants
import os import test.testtools
import utils.path_const as P
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
TEST_FUNCTIONS = ["test_getConfig"]
VERIFY = False VERIFY = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def runTest(self): mymsg = "--------------------------------------------------------------"
self.test_getConfig()
def test_getConfig(self): def test_getConfig(self):
job = Job("unit") global mymsg
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", actfunction = str(inspect.currentframe().f_code.co_name)
"modus": "unit"} cnttest = 0
job.par.setParameterArgs(args) if actfunction not in TEST_FUNCTIONS:
r = t.getConfigPath("tool", "path") return
self.assertEqual(r, os.path.join(HOME_PATH, "utils","configs","path.yml")) job = test.testtools.getJob()
r = t.getConfigPath("comp", "TestX2") x = "path"
self.assertEqual(r, None) r = t.getConfigPath(P.KEY_TOOL, x)
r = t.getConfigPath("comp", "testA2") self.assertIn(os.path.join(HOME_PATH, P.VAL_UTIL, P.VAL_CONFIG), r)
r = t.getConfig("tool", "path") cnttest += 1
x = "conn"
r = t.getConfigPath(P.KEY_TOOL, x)
self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_ENV)), r)
cnttest += 1
self.assertRaises(Exception, t.getConfigPath, (P.KEY_COMP, "TestX2"))
# self.assertEqual(r, None)
cnttest += 1
r = t.getConfigPath(P.KEY_COMP, "testA2")
self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), P.VAL_COMPS, "testa2", "CONFIG"), r)
r = t.getConfig(P.KEY_TOOL, "path")
if VERIFY: print("pattern " + r["pattern"]["log"]) if VERIFY: print("pattern " + r["pattern"]["log"])
if VERIFY: print("pattern " + r["pattern"]["precond"]) if VERIFY: print("pattern " + r["pattern"]["precond"])
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getAttributes(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
if __name__ == '__main__': if __name__ == '__main__':
VERIFY = True VERIFY = True

57
test/test_file.py

@ -1,40 +1,57 @@
import unittest, os import unittest
import os
import inspect
import utils.file_tool as t import utils.file_tool as t
import utils.path_tool import utils.path_tool
import basic.program import basic.program
import test.constants import test.constants
import test.testtools
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def runTest(self): mymsg = ""
self.test_encoding()
self.test_getFiles()
self.test_pathTool()
def test_getFiles(self): def test_getFiles(self):
job = basic.program.Job("unit") global mymsg
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", actfunction = str(inspect.currentframe().f_code.co_name)
"modus": "unit"} cnttest = 0
job.par.setParameterArgs(args) if actfunction not in TEST_FUNCTIONS:
r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", "file_.*.py", None) return
job = test.testtools.getJob()
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "file_.*.py", None)
self.assertEqual((len(r) == 1), True) self.assertEqual((len(r) == 1), True)
r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", "file__.*.py", None) cnttest += 3
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "file__.*.py", None)
self.assertEqual((len(r) == 0), True) self.assertEqual((len(r) == 0), True)
r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", ".*_tool.py", None) r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", ".*_tool.py", None)
self.assertEqual((len(r) > 2), True) self.assertEqual((len(r) > 2), True)
r = t.getFilesRec(job.m, job.conf.confs.get("paths").get("program"), ".*?file.*.py") cnttest += 3
# print (r) r = t.getFilesRec(job.m, job.conf.getPath("program"), ".*?file.*.py")
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_pathTool(self): def test_pathTool(self):
job = basic.program.Job("unit") global mymsg
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", actfunction = str(inspect.currentframe().f_code.co_name)
"modus": "unit"} cnttest = 0
job.par.setParameterArgs(args) if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
#self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"), #self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"),
# os.path.join(HOME_PATH, "components","testA","COFIG.yml")) # os.path.join(HOME_PATH, "components","testA","COFIG.yml"))
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_encoding(self): def test_encoding(self):
job = basic.program.Job("unit") global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
print("------- test_encoding") print("------- test_encoding")
encodings = ['utf-8', 'windows-1250', 'iso-8859-1'] encodings = ['utf-8', 'windows-1250', 'iso-8859-1']
res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_iso8859.txt")) res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_iso8859.txt"))
@ -43,6 +60,8 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(res, "iso-8859-1") self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_utf8.txt")) res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_utf8.txt"))
self.assertEqual(res, "utf-8") self.assertEqual(res, "utf-8")
cnttest += 3
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
if __name__ == '__main__': if __name__ == '__main__':

93
utils/config_tool.py

@ -18,6 +18,7 @@ import utils.file_tool
import os.path import os.path
import basic.constants as B import basic.constants as B
import utils.data_const as D import utils.data_const as D
import utils.path_const as P
COMP_FILES = [D.DDL_FILENAME] COMP_FILES = [D.DDL_FILENAME]
CONFIG_FORMAT = [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV] CONFIG_FORMAT = [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV]
@ -42,66 +43,87 @@ def getConfigPath(modul, name, subname=""):
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 #TODO path rejoin, config as const
if modul == "tool": if modul == P.KEY_TOOL:
for format in CONFIG_FORMAT: for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("home") , "config" ,"tool_"+name+"."+format) pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
P.VAL_CONFIG, P.KEY_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", "config", name+"."+format) pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM),
P.VAL_UTIL, P.VAL_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, "config", "tool_"+ name+"."+format) pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_ENV),
job.par.environment, P.VAL_CONFIG, P.KEY_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
job.debug(verify, "3x " + pathname) job.debug(verify, "3x " + pathname)
elif modul == "comp": raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
pathname = job.conf.confs.get("paths").get("home") + "/configs/comp_" + name + ".yml" elif modul == P.KEY_COMP:
job.debug(verify, "4 " + pathname) for format in CONFIG_FORMAT:
if os.path.exists(pathname): pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
return pathname P.VAL_CONFIG, P.KEY_COMP+"_" + name + "."+format)
pathname = job.conf.confs.get("paths").get("program") + "/components/" + basic.componentHandling.getComponentFolder(name) + "/CONFIG.yml" job.debug(verify, "4 " + pathname)
job.debug(verify, "5 " + pathname) if os.path.exists(pathname):
if os.path.exists(pathname): return pathname
return pathname for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM),
P.VAL_COMPS, basic.componentHandling.getComponentFolder(name), "CONFIG." + format)
job.debug(verify, "5 " + pathname)
if os.path.exists(pathname):
return pathname
job.debug(verify, "6 " + pathname) job.debug(verify, "6 " + pathname)
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
elif modul in COMP_FILES: elif modul in COMP_FILES:
# for example DATASTRUCURE or the table
for format in CONFIG_FORMAT: for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components", pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), P.VAL_COMPS,
basic.componentHandling.getComponentFolder(name), modul+"."+format) basic.componentHandling.getComponentFolder(name), modul+"."+format)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
for format in CONFIG_FORMAT:
if len(subname) > 1: if len(subname) > 1:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components", pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), P.VAL_COMPS,
basic.componentHandling.getComponentFolder(name), subname+"."+format) basic.componentHandling.getComponentFolder(name), subname+"."+format)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
else: else:
pathname = utils.path_tool.composePath("tcparfile") pathname = utils.path_tool.composePath(P.P_TCPARFILE)
job.debug(verify, "7 " + pathname) job.debug(verify, "7 " + pathname)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
pathname = utils.path_tool.composePath("tsparfile") pathname = utils.path_tool.composePath(P.P_TSPARFILE)
job.debug(verify, "8 " + pathname) job.debug(verify, "8 " + pathname)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
pathname = job.conf.confs.get("paths").get("release") + "/configs/basis.yml" for format in CONFIG_FORMAT:
job.debug(verify, "9 " + pathname) if len(subname) > 1:
if os.path.exists(pathname): pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_RELEASE),
return pathname P.VAL_CONFIG, "basis."+format)
pathname = job.conf.confs.get("paths").get("environment") + "/configs/basis.yml" job.debug(verify, "9 " + pathname)
job.debug(verify, "10 " + pathname) if os.path.exists(pathname):
if os.path.exists(pathname): return pathname
return pathname for format in CONFIG_FORMAT:
pathname = job.conf.confs.get("paths").get("home") + "/config/basis.yml" if len(subname) > 1:
job.debug(verify, "11 " + pathname) pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_ENV),
if os.path.exists(pathname): P.VAL_CONFIG, "basis."+format)
return pathname job.debug(verify, "9 " + pathname)
job.debug(verify, "12 " + pathname) if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
if len(subname) > 1:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
P.VAL_CONFIG, "basis."+format)
job.debug(verify, "9 " + pathname)
if os.path.exists(pathname):
return pathname
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
def getConfValue(attribute, comp): def getConfValue(attribute, comp):
@ -114,9 +136,9 @@ def getConfValue(attribute, comp):
else: else:
dbtype = comp.conf["conn"]["dbtype"] dbtype = comp.conf["conn"]["dbtype"]
return "" return ""
return "" return ""
def getAttr(o, name): def getAttr(o, name):
#print("hasAttr " + str(type(o))+" "+name) #print("hasAttr " + str(type(o))+" "+name)
if (isinstance(o, dict)): if (isinstance(o, dict)):
@ -143,11 +165,14 @@ def hasAttr(o, name):
elif (isinstance(o, list)): elif (isinstance(o, list)):
pass pass
#print("hasAttr list "+str(type(o))) #print("hasAttr list "+str(type(o)))
elif hasattr(o, name): elif hasattr(o, name):
#print("hasAttr class ok "+str(type(o))) #print("hasAttr class ok "+str(type(o)))
return True return True
return False return False
def getConfig(modul, name, subname=""): def getConfig(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

24
utils/file_tool.py

@ -24,14 +24,15 @@ def getDump(obj):
return str(result) return str(result)
# if type(obj) == "__dict__" # if type(obj) == "__dict__"
def getFiles(msg, path, pattern, conn): def getFiles(msg, path, pattern, conn):
""" """
search filenames in the directory - if conn is set search remote search filenames in the directory - if conn is set search remote
:param msg: -- msg-Objekt :param msg: -- msg-Objekt
:param path: -- Pfad - String :param path: -- path - String
:param pattern: -- Dateiname als Pattern :param pattern: -- filename or pattern
:param conn: :param conn:
:return: Array mit gefundenen Dateien, nur Dateiname :return: Array with filenames
""" """
if conn is not None: if conn is not None:
return getRemoteFiles(msg, path, pattern, conn) return getRemoteFiles(msg, path, pattern, conn)
@ -48,15 +49,17 @@ def getFiles(msg, path, pattern, conn):
out.append(f) out.append(f)
return out return out
def getRemoteFiles(msg, path, pattern, conn): def getRemoteFiles(msg, path, pattern, conn):
""" """
search filenames in the directory - if conn is set search remote search filenames in the directory - if conn is set search remote
:param msg: -- msg-Objekt :param msg: -- msg-Objekt
:param path: -- Pfad - String :param path: -- path - String
:param pattern: -- Dateiname als Pattern :param pattern: -- filename as Pattern
:param conn: :param conn:
:return: Array mit gefundenen Dateien, nur Dateiname :return: Array filenames
""" """
pass
def getFilesRec(msg, path, pattern): def getFilesRec(msg, path, pattern):
@ -79,6 +82,7 @@ def getFilesRec(msg, path, pattern):
out.append(os.path.join(r, f)) out.append(os.path.join(r, f))
return out return out
def getTree(msg, pfad): def getTree(msg, pfad):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
@ -93,6 +97,7 @@ def getTree(msg, pfad):
tree["_files_"] = files tree["_files_"] = files
return tree return tree
def mkPaths(path, msg): def mkPaths(path, msg):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
@ -102,6 +107,7 @@ def mkPaths(path, msg):
return return
os.makedirs(dirname, exist_ok=True) os.makedirs(dirname, exist_ok=True)
def getFileEncoding(msg, path): def getFileEncoding(msg, path):
print("--- getFileEncoding "+path) print("--- getFileEncoding "+path)
encodings = ['utf-8', 'iso-8859-1'] # add more encodings = ['utf-8', 'iso-8859-1'] # add more
@ -120,6 +126,7 @@ def getFileEncoding(msg, path):
return e return e
return detectFileEncode(path, msg) return detectFileEncode(path, msg)
def detectFileEncode(path, msg): # return "" def detectFileEncode(path, msg): # return ""
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
@ -147,12 +154,14 @@ def detectFileEncode(path, msg): # return ""
return 'iso-8859-1' return 'iso-8859-1'
return 'utf-8' return 'utf-8'
def readFileLines(path, msg): def readFileLines(path, msg):
lines = readFileText(path, msg) lines = readFileText(path, msg)
if isinstance(lines, (str)): if isinstance(lines, (str)):
return lines.splitlines() return lines.splitlines()
return [] return []
def readFileText(path, msg): def readFileText(path, msg):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
@ -164,6 +173,7 @@ def readFileText(path, msg):
file.close() file.close()
return text return text
def readFileDict(path, msg): def readFileDict(path, msg):
""" """
reads and gets general a dict from any kind of filetyp reads and gets general a dict from any kind of filetyp
@ -190,6 +200,7 @@ def readFileDict(path, msg):
doc = utils.tdata_tool.getCsvSpec(msg, path, D.CSV_SPECTYPE_CONF) doc = utils.tdata_tool.getCsvSpec(msg, path, D.CSV_SPECTYPE_CONF)
return doc return doc
def writeFileText(msg, path, text, enc="utf-8"): def writeFileText(msg, path, text, enc="utf-8"):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
@ -198,6 +209,7 @@ def writeFileText(msg, path, text, enc="utf-8"):
file.write(text) file.write(text)
file.close() file.close()
def writeFileDict(msg, path, dict, enc="utf-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)

36
utils/path_const.py

@ -13,7 +13,18 @@ KEY_TESTCASE = "tc"
KEY_TESTSUITE = "ts" KEY_TESTSUITE = "ts"
KEY_DEBUGNAME = "debugname" KEY_DEBUGNAME = "debugname"
KEY_LOGNAME = "logname" KEY_LOGNAME = "logname"
KEY_COMP = "comp"
""" keyword for individual component """
KEY_TOOL = "tool"
""" keyword for technical tools """
VAL_UTIL = "utils"
""" subdir for any technical tools """
VAL_CONFIG = "config"
""" subdir for any place of config-files """
VAL_COMPS = "components"
""" subdir for the plugin components """
VAL_BASIC = "basic"
""" subdir for the basic job-framework """
# ------------------------------------------------------------- # -------------------------------------------------------------
# parameter with arguments # parameter with arguments
PAR_APP = "job.par." + B.PAR_APP PAR_APP = "job.par." + B.PAR_APP
@ -41,6 +52,26 @@ PAR_TESTINSTANCES = "job.par." + B.PAR_TESTINSTANCES
# ------------------------------------------------------------- # -------------------------------------------------------------
# attributes # attributes
ATTR_PATH_MODE = "mode"
""" This constant defines the home-folder in filesystem of test """
ATTR_PATH_HOME = "home"
""" This constant defines the home-folder in testing-filesystem """
ATTR_PATH_DEBUG = "debugs"
""" This constant defines the debug-folder in testing-filesystem """
ATTR_PATH_ARCHIV = "archiv"
""" This constant defines the folder in testing-filesystem for results and log of execution """
ATTR_PATH_PROGRAM = "program"
""" This constant defines the program-folder in the workspace """
ATTR_PATH_ENV = "environment"
""" This constant defines the folder in testing-filesystem, used for configs related to environments """
ATTR_PATH_RELEASE = "release"
""" This constant defines the folder in testing-filesystem, used for configs related to release """
ATTR_PATH_TDATA = "testdata"
""" This constant defines the folder in testing-filesystem with the testcase-specifications """
ATTR_PATH_PATTN = "pattern"
""" This constant defines the debug-folder in testing-filesystem """
# ------------------------------------------------------------- # -------------------------------------------------------------
# structure - nodes # structure - nodes
@ -68,3 +99,6 @@ P_XPBACKUP = "xpbackup"
# ------------------------------------------------------------- # -------------------------------------------------------------
# exception texts # exception texts
EXP_COMP_MISSING = "Component is missing for {}" EXP_COMP_MISSING = "Component is missing for {}"
""" excetion for the case that a specific component doesnt exist, 1 parameter (context) """
EXP_CONFIG_MISSING = "Configuration is missing for {}"
""" excetion for the case that a specific configuration is missing, 1 parameter (context) """
Loading…
Cancel
Save