From ef6f34aaff01fe255e0ab52c500c10f968b50130 Mon Sep 17 00:00:00 2001 From: Ulrich Carmesin Date: Sun, 29 May 2022 16:43:17 +0200 Subject: [PATCH] refactor b.constants only moves --- basic/catalog.py | 62 +++++++++++++++++++++++++++++ basic/constants.py | 44 ++++++++++++++------- basic/program.py | 24 ++++++------ test/test_catalog.py | 50 ++++++++++++++++++++++++ test/test_config.py | 49 ++++++++++++++++------- test/test_file.py | 57 ++++++++++++++++++--------- utils/config_tool.py | 93 ++++++++++++++++++++++++++++---------------- utils/file_tool.py | 24 +++++++++--- utils/path_const.py | 36 ++++++++++++++++- 9 files changed, 341 insertions(+), 98 deletions(-) create mode 100644 basic/catalog.py create mode 100644 test/test_catalog.py diff --git a/basic/catalog.py b/basic/catalog.py new file mode 100644 index 0000000..e37e6a8 --- /dev/null +++ b/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)) diff --git a/basic/constants.py b/basic/constants.py index f3120f4..1f98cf4 100644 --- a/basic/constants.py +++ b/basic/constants.py @@ -19,11 +19,17 @@ The constants desribes the keywords of the main datastructures, these are * 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' """ definition of the application which will be tested """ PAR_ENV = 'environment' @@ -54,8 +60,16 @@ PAR_TCTIME = "tctime" PAR_TSTIME = "tstime" PAR_TESTINSTANCES = "testinstances" """ 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: # root { : constant # + option { : constant @@ -81,14 +95,11 @@ DATA_NODE_COMP = "comp" """ This constant defines """ DATA_NODE_PAR = "par" -SVAL_YES = "y" -SVAL_NO = "n" -SVAL_NULL = "null" """ This constant defines """ TOPIC_NODE_DB = "db" - +# testexec, db_abstr ATTR_DB_PARTITION = "partitioned" """ optional attribute if table is partitioned - 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 """ ATTR_DB_TABNAME = "tabname" """ 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_API = "api" @@ -140,13 +147,14 @@ 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 """ -SUBJECT_APPS = "applications" # | x | | | | CompHandling + +#SUBJECT_APPS = "applications" # | x | | | | CompHandling SUBJECT_INST = "instance" # | | | | x | CompHanlding ATTR_INST_CNT = "count" # | | | | x | CompHanlding ATTR_INST_SGL = "single" ATTR_INST_SUBCOMP = "components" -SUBJECT_FCT = "function" # | | | | x | main-programs +#SUBJECT_FCT = "function" # | | | | x | main-programs 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 * * * specific attributes - it overrides the general attributes """ -ATTR_ARTS_DB = "db" +#ATTR_ARTS_DB = "db" ATTR_ARTS_LOG = "log" ATTR_ARTS_LOB = "lob" 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 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_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" diff --git a/basic/program.py b/basic/program.py index 4869446..615896a 100644 --- a/basic/program.py +++ b/basic/program.py @@ -20,8 +20,6 @@ import utils.date_tool import utils.path_tool import utils.file_tool -BASIS_FILE = "basis.yml" -EXCP_NO_BASIS_FILE = "basis file cant be found" jobdef = { "unit": { @@ -137,7 +135,7 @@ class Job: @staticmethod def popInstance(pjob=None): 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: return None if len(Job.instances) == 1: @@ -150,7 +148,7 @@ class Job: 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) + raise Exception(B.EXP_CANT_POP) if len(Job.instances) > 0: topjob = Job.instances.pop() Job.instances.append(topjob) @@ -435,16 +433,16 @@ class Configuration: self.program = program print (f"job initialisiert {self.program}") if program == "unit": - if (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))): - self.setConfiguration(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", B.BASIS_FILE)) return - elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))): - self.setConfiguration(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", B.BASIS_FILE)) return - elif (os.path.exists(utils.path_tool.rejoinPath("config", BASIS_FILE))): - self.setConfiguration(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", B.BASIS_FILE)) return - raise Exception(EXCP_NO_BASIS_FILE) + raise Exception(B.EXP_NO_BASIS_FILE) def setConfiguration(self, path): self.confs = {} @@ -467,6 +465,10 @@ class Configuration: elif len(a) == 3: 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): a = key.split(":") if len(a) == 1: diff --git a/test/test_catalog.py b/test/test_catalog.py new file mode 100644 index 0000000..255a69e --- /dev/null +++ b/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() diff --git a/test/test_config.py b/test/test_config.py index 9001992..f3d6032 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -1,30 +1,53 @@ import unittest +import os +import inspect import utils.config_tool as t from basic.program import Job import test.constants -import os +import test.testtools +import utils.path_const as P HOME_PATH = test.constants.HOME_PATH +TEST_FUNCTIONS = ["test_getConfig"] VERIFY = False class MyTestCase(unittest.TestCase): - def runTest(self): - self.test_getConfig() + mymsg = "--------------------------------------------------------------" def test_getConfig(self): - job = Job("unit") - args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", - "modus": "unit"} - job.par.setParameterArgs(args) - r = t.getConfigPath("tool", "path") - self.assertEqual(r, os.path.join(HOME_PATH, "utils","configs","path.yml")) - r = t.getConfigPath("comp", "TestX2") - self.assertEqual(r, None) - r = t.getConfigPath("comp", "testA2") - r = t.getConfig("tool", "path") + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + x = "path" + r = t.getConfigPath(P.KEY_TOOL, x) + self.assertIn(os.path.join(HOME_PATH, P.VAL_UTIL, P.VAL_CONFIG), r) + 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"]["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__': VERIFY = True diff --git a/test/test_file.py b/test/test_file.py index 49bb5bb..afbc7c7 100644 --- a/test/test_file.py +++ b/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.path_tool import basic.program import test.constants +import test.testtools HOME_PATH = test.constants.HOME_PATH +TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding"] + class MyTestCase(unittest.TestCase): - def runTest(self): - self.test_encoding() - self.test_getFiles() - self.test_pathTool() + mymsg = "" def test_getFiles(self): - job = basic.program.Job("unit") - args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", - "modus": "unit"} - job.par.setParameterArgs(args) - r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", "file_.*.py", None) + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "file_.*.py", None) 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) - 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) - r = t.getFilesRec(job.m, job.conf.confs.get("paths").get("program"), ".*?file.*.py") - # print (r) + cnttest += 3 + r = t.getFilesRec(job.m, job.conf.getPath("program"), ".*?file.*.py") + MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) + def test_pathTool(self): - job = basic.program.Job("unit") - args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", - "modus": "unit"} - job.par.setParameterArgs(args) + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() #self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"), # os.path.join(HOME_PATH, "components","testA","COFIG.yml")) + MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) + + 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") 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")) @@ -43,6 +60,8 @@ class MyTestCase(unittest.TestCase): self.assertEqual(res, "iso-8859-1") res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_utf8.txt")) self.assertEqual(res, "utf-8") + cnttest += 3 + MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) if __name__ == '__main__': diff --git a/utils/config_tool.py b/utils/config_tool.py index f6713df..4f312b4 100644 --- a/utils/config_tool.py +++ b/utils/config_tool.py @@ -18,6 +18,7 @@ import utils.file_tool import os.path import basic.constants as B import utils.data_const as D +import utils.path_const as P COMP_FILES = [D.DDL_FILENAME] 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 job.debug(verify, "getConfig " + modul + ", " + name) #TODO path rejoin, config as const - if modul == "tool": + if modul == P.KEY_TOOL: 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) if os.path.exists(pathname): return pathname 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) if os.path.exists(pathname): return pathname 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) if os.path.exists(pathname): return pathname job.debug(verify, "3x " + pathname) - elif modul == "comp": - pathname = job.conf.confs.get("paths").get("home") + "/configs/comp_" + name + ".yml" - job.debug(verify, "4 " + pathname) - if os.path.exists(pathname): - return pathname - pathname = job.conf.confs.get("paths").get("program") + "/components/" + basic.componentHandling.getComponentFolder(name) + "/CONFIG.yml" - job.debug(verify, "5 " + pathname) - if os.path.exists(pathname): - return pathname + raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name) + elif modul == P.KEY_COMP: + for format in CONFIG_FORMAT: + pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME), + P.VAL_CONFIG, P.KEY_COMP+"_" + name + "."+format) + job.debug(verify, "4 " + pathname) + if os.path.exists(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) + raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name) elif modul in COMP_FILES: + # for example DATASTRUCURE or the table 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) if os.path.exists(pathname): return pathname + for format in CONFIG_FORMAT: if len(subname) > 1: - pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components", - basic.componentHandling.getComponentFolder(name), subname+"."+format) - if os.path.exists(pathname): - return pathname + pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), P.VAL_COMPS, + basic.componentHandling.getComponentFolder(name), subname+"."+format) + if os.path.exists(pathname): + return pathname + raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name) else: - pathname = utils.path_tool.composePath("tcparfile") + pathname = utils.path_tool.composePath(P.P_TCPARFILE) job.debug(verify, "7 " + pathname) if os.path.exists(pathname): return pathname - pathname = utils.path_tool.composePath("tsparfile") + pathname = utils.path_tool.composePath(P.P_TSPARFILE) job.debug(verify, "8 " + pathname) if os.path.exists(pathname): return pathname - pathname = job.conf.confs.get("paths").get("release") + "/configs/basis.yml" - job.debug(verify, "9 " + pathname) - if os.path.exists(pathname): - return pathname - pathname = job.conf.confs.get("paths").get("environment") + "/configs/basis.yml" - job.debug(verify, "10 " + pathname) - if os.path.exists(pathname): - return pathname - pathname = job.conf.confs.get("paths").get("home") + "/config/basis.yml" - job.debug(verify, "11 " + pathname) - if os.path.exists(pathname): - return pathname - job.debug(verify, "12 " + pathname) + for format in CONFIG_FORMAT: + if len(subname) > 1: + pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_RELEASE), + P.VAL_CONFIG, "basis."+format) + job.debug(verify, "9 " + 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_ENV), + P.VAL_CONFIG, "basis."+format) + job.debug(verify, "9 " + 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): @@ -114,9 +136,9 @@ def getConfValue(attribute, comp): else: dbtype = comp.conf["conn"]["dbtype"] return "" - return "" + def getAttr(o, name): #print("hasAttr " + str(type(o))+" "+name) if (isinstance(o, dict)): @@ -143,11 +165,14 @@ def hasAttr(o, name): elif (isinstance(o, list)): pass #print("hasAttr list "+str(type(o))) + + elif hasattr(o, name): #print("hasAttr class ok "+str(type(o))) return True return False + def getConfig(modul, name, subname=""): job = basic.program.Job.getInstance() verify = job.getDebugLevel("config_tool")-4 diff --git a/utils/file_tool.py b/utils/file_tool.py index 495b98f..2514de7 100644 --- a/utils/file_tool.py +++ b/utils/file_tool.py @@ -24,14 +24,15 @@ def getDump(obj): return str(result) # if type(obj) == "__dict__" + def getFiles(msg, path, pattern, conn): """ search filenames in the directory - if conn is set search remote :param msg: -- msg-Objekt - :param path: -- Pfad - String - :param pattern: -- Dateiname als Pattern + :param path: -- path - String + :param pattern: -- filename or pattern :param conn: - :return: Array mit gefundenen Dateien, nur Dateiname + :return: Array with filenames """ if conn is not None: return getRemoteFiles(msg, path, pattern, conn) @@ -48,15 +49,17 @@ def getFiles(msg, path, pattern, conn): out.append(f) return out + def getRemoteFiles(msg, path, pattern, conn): """ search filenames in the directory - if conn is set search remote :param msg: -- msg-Objekt - :param path: -- Pfad - String - :param pattern: -- Dateiname als Pattern + :param path: -- path - String + :param pattern: -- filename as Pattern :param conn: - :return: Array mit gefundenen Dateien, nur Dateiname + :return: Array filenames """ + pass def getFilesRec(msg, path, pattern): @@ -79,6 +82,7 @@ def getFilesRec(msg, path, pattern): out.append(os.path.join(r, f)) return out + def getTree(msg, pfad): job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) @@ -93,6 +97,7 @@ def getTree(msg, pfad): tree["_files_"] = files return tree + def mkPaths(path, msg): job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) @@ -102,6 +107,7 @@ def mkPaths(path, msg): return os.makedirs(dirname, exist_ok=True) + def getFileEncoding(msg, path): print("--- getFileEncoding "+path) encodings = ['utf-8', 'iso-8859-1'] # add more @@ -120,6 +126,7 @@ def getFileEncoding(msg, path): return e return detectFileEncode(path, msg) + def detectFileEncode(path, msg): # return "" job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) @@ -147,12 +154,14 @@ def detectFileEncode(path, msg): # return "" return 'iso-8859-1' return 'utf-8' + def readFileLines(path, msg): lines = readFileText(path, msg) if isinstance(lines, (str)): return lines.splitlines() return [] + def readFileText(path, msg): job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) @@ -164,6 +173,7 @@ def readFileText(path, msg): file.close() return text + def readFileDict(path, msg): """ 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) return doc + def writeFileText(msg, path, text, enc="utf-8"): job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("file_tool")) @@ -198,6 +209,7 @@ def writeFileText(msg, path, text, enc="utf-8"): file.write(text) file.close() + def writeFileDict(msg, path, dict, enc="utf-8"): job = basic.program.Job.getInstance() mkPaths(path, msg) diff --git a/utils/path_const.py b/utils/path_const.py index a4f07ac..04d73bc 100644 --- a/utils/path_const.py +++ b/utils/path_const.py @@ -13,7 +13,18 @@ KEY_TESTCASE = "tc" KEY_TESTSUITE = "ts" KEY_DEBUGNAME = "debugname" 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 PAR_APP = "job.par." + B.PAR_APP @@ -41,6 +52,26 @@ PAR_TESTINSTANCES = "job.par." + B.PAR_TESTINSTANCES # ------------------------------------------------------------- # 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 @@ -68,3 +99,6 @@ P_XPBACKUP = "xpbackup" # ------------------------------------------------------------- # exception texts 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) """ \ No newline at end of file