diff --git a/test/test_04config.py b/test/test_04config.py index 4bdf313..6eacc72 100644 --- a/test/test_04config.py +++ b/test/test_04config.py @@ -61,6 +61,9 @@ class MyTestCase(unittest.TestCase): r = tools.config_tool.getConfig(job, P.KEY_TOOL, "path", ttype=D.CSV_SPECTYPE_KEYS) if verbose: print("pattern " + r["pattern"]["log"]) if verbose: print("pattern " + r["pattern"]["precond"]) + r = tools.config_tool.getConfig(job, P.KEY_BASIC, "servers", ttype=D.CSV_SPECTYPE_KEYS) + if verbose: print("pattern " + r["pattern"]["log"]) + if verbose: print("pattern " + r["pattern"]["precond"]) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -127,6 +130,9 @@ class MyTestCase(unittest.TestCase): plain = tools.config_tool.get_plain_filename(job, os.path.join(job.conf[B.TOPIC_PATH][B.ATTR_PATH_PROGRAM], P.ATTR_PATH_TDATA, "testfall." + ext)) self.assertEqual(plain, "testfall") + + MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) + def test_zzz(self): print(MyTestCase.mymsg) diff --git a/test/test_92workspace.py b/test/test_92workspace.py new file mode 100644 index 0000000..d96a2e1 --- /dev/null +++ b/test/test_92workspace.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# --------------------------------------------------------------------------------------------------------- +# Author : Ulrich Carmesin +# Source : gitea.ucarmesin.de +# https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/225-konfiguration-der-testanwendung +# --------------------------------------------------------------------------------------------------------- +import sys +import basic.constants as B +import unittest +import os +import inspect + +import tools.make_tool +import tools.conn_tool +import test.constants as T +import test.testtools +import tools.path_const as P +import basic.constants as B +import tools.data_const as D + +TEST_FUNCTIONS = ["test_01createWorkspaces"] +#TEST_FUNCTIONS = ["test_01getConfigPath"] +verbose = False + +class MyTestCase(unittest.TestCase): + mymsg = "--------------------------------------------------------------" + + def test_01createWorkspaces(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + tools.make_tool.createWorkspaces(job) + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + + def test_zzz(self): + print(MyTestCase.mymsg) + + +if __name__ == '__main__': + verbose = True + unittest.main() diff --git a/tools/config_tool.py b/tools/config_tool.py index eedb54a..0523cd4 100644 --- a/tools/config_tool.py +++ b/tools/config_tool.py @@ -26,24 +26,28 @@ import tools.path_const as P TABLE_FILES = [D.DDL_FILENAME] CONFIG_FORMAT = [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV] + def getExistingPath(job, pathnames): if isinstance(pathnames, str): pathnames = [pathnames] for p in pathnames: if p[-1:] == ".": p = p[0:-1] - for format in CONFIG_FORMAT: - pathname = p+"."+format + for f in CONFIG_FORMAT: + pathname = p + "." + f if os.path.exists(pathname): return pathname return None -def select_config_path(job, modul, name, subname=""): + +def select_config_path(job: any, modul: str, name: str, subname="") -> str: """ gets the most specified configuration of different sources - Parameter: - * typ -- (basic, comp, tool) - * name -- the specific class + :param job: + :param modul: + :param name: + :param subname: + :return: sources: * programm << * install << @@ -55,27 +59,23 @@ def select_config_path(job, modul, name, subname=""): * yaml, json, csv """ if job is None: - verify = False # job = basic.program.Job.getInstance() + verify = False # job = basic.program.Job.getInstance() else: verify = job.getDebugLevel("config_tool") - if verify: job.debug(verify, "getConfig " + modul + ", " + name) if modul == P.KEY_TOOL: return getToolPath(job, name, subname) elif modul == P.KEY_COMP: - for format in CONFIG_FORMAT: + for f in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], - P.VAL_CONFIG, P.KEY_COMP +"_" + name + "." + format) - if verify: job.debug(verify, "4 " + pathname) + P.VAL_CONFIG, P.KEY_COMP + "_" + name + "." + f) if os.path.exists(pathname): - return pathname - for format in CONFIG_FORMAT: + return str(pathname) + for f in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_COMPONENTS], - basic.componentHandling.getComponentFolder(name), "CONFIG." + format) - if verify: job.debug(verify, "5 " + pathname) + basic.componentHandling.getComponentFolder(name), "CONFIG." + f) if os.path.exists(pathname): - return pathname - if verify: job.debug(verify, "6 " + pathname) - raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name) + return str(pathname) + raise Exception(P.EXP_CONFIG_MISSING, modul + ", " + name) elif modul in TABLE_FILES: return getTablePath(job, name, subname, modul) elif modul == P.KEY_BASIC: @@ -94,35 +94,31 @@ def select_config_path(job, modul, name, subname=""): return getModelPath(job, name) else: pathname = tools.path_tool.compose_path(job, P.P_TCPARFILE) - if verify: job.debug(verify, "7 " + pathname) if os.path.exists(pathname): return pathname pathname = tools.path_tool.compose_path(job, P.P_TSPARFILE) - if verify: job.debug(verify, "8 " + pathname) if os.path.exists(pathname): return pathname - for format in CONFIG_FORMAT: + for f in CONFIG_FORMAT: if len(subname) > 1: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_RELEASE], - P.VAL_CONFIG, "basis." + format) - if verify: job.debug(verify, "9 " + pathname) + P.VAL_CONFIG, "basis." + f) if os.path.exists(pathname): - return pathname - for format in CONFIG_FORMAT: + return str(pathname) + for f in CONFIG_FORMAT: if len(subname) > 1: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_ENV], - P.VAL_CONFIG, "basis." + format) - if verify: job.debug(verify, "9 " + pathname) + P.VAL_CONFIG, "basis." + f) if os.path.exists(pathname): - return pathname - for format in CONFIG_FORMAT: + return str(pathname) + for f in CONFIG_FORMAT: if len(subname) > 1: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], - P.VAL_CONFIG, "basis." + format) - if verify: job.debug(verify, "9 " + pathname) + P.VAL_CONFIG, "basis." + f) if os.path.exists(pathname): - return pathname - raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name) + return str(pathname) + raise Exception(P.EXP_CONFIG_MISSING, modul + ", " + name) + def getToolPath(job, name, subname): if subname != "": @@ -149,7 +145,8 @@ def getToolPath(job, name, subname): return path raise Exception(P.EXP_CONFIG_MISSING, envdir + ", " + name) -def getTablePath(job, name, subname, filename): + +def getTablePath(job: any, name: str, subname: str, filename: str) -> str: """ reads the ddl of the table depending on context (=name) a) component: the ddl is read from specific or general component-folder @@ -177,58 +174,80 @@ def getTablePath(job, name, subname, filename): pathnames.append(os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_PROGRAM], P.VAL_BASIC, filename)) pathnames.append(os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_PROGRAM], P.VAL_BASIC, subname)) """ - print("pathnames "+str(pathnames)) + print("pathnames " + str(pathnames)) configpath = getExistingPath(job, pathnames) - print("configpath "+str(configpath)) + print("configpath " + str(configpath)) if configpath is not None: return configpath if name == B.ATTR_INST_TESTSERVER: - #print(name) - for format in CONFIG_FORMAT: + # print(name) + for f in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_PROGRAM], - P.ATTR_PATH_MODEL, subname + "." + format) - #print(pathname) + P.ATTR_PATH_MODEL, subname + "." + f) if os.path.exists(pathname): - return pathname - - for format in CONFIG_FORMAT: + return str(pathname) + for f in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_COMPONENTS], - basic.componentHandling.getComponentFolder(name), filename + "." + format) - #print(pathname) + basic.componentHandling.getComponentFolder(name), filename + "." + f) if os.path.exists(pathname): - return pathname - for format in CONFIG_FORMAT: + return str(pathname) + for f in CONFIG_FORMAT: if len(subname) > 1: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_COMPONENTS], - basic.componentHandling.getComponentFolder(name), subname + "." + format) - if os.path.exists(pathname): - return pathname + basic.componentHandling.getComponentFolder(name), subname + "." + f) + if os.path.exists(pathname): + return str(pathname) raise Exception(P.EXP_CONFIG_MISSING, filename + ", " + name) -def getBasicPath(job, name): - path = getExistingPath(job, os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_COMPONENTS], + +def getBasicPath(job: any, name: str) -> str: + """ + the function searchs the config-file in the basic-context. + :param job: + :param name: + :return: + """ + path = getExistingPath(job, os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], P.VAL_CONFIG, name)) if path is not None: return path - path = getExistingPath(job, os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], + path = getExistingPath(job, os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_COMPONENTS], P.VAL_CONFIG, name)) if path is not None: return path + raise Exception(P.EXP_CONFIG_MISSING, name) -def getEnvironmentPath(job, name): + +def getEnvironmentPath(job: any, name: str) -> str: + """ + the function searchs the config-file in the environment-context. + :param job: + :param name: + :return: + """ path = getExistingPath(job, os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_ENV], name, P.VAL_CONFIG, B.SUBJECT_ENVIRONMENT)) if path is not None: return path + raise Exception(P.EXP_CONFIG_MISSING, name) -def getTestPath(job, name, subdir, filename): - for format in CONFIG_FORMAT: + +def getTestPath(job: any, name: str, subdir: str, filename: str) -> str: + for f in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_TDATA], job.par.project, - subdir, name, filename + "." + format) + subdir, name, filename + "." + f) if os.path.exists(pathname): - return pathname + return str(pathname) + raise Exception(P.EXP_CONFIG_MISSING, name) + -def getCatalogPath(job, name): +def getCatalogPath(job: any, name: str) -> str: + """ + the function searchs the config-file in the catalog-context. + :param job: + :param name: + :return: + """ if hasattr(job, "par") and hasattr(job.par, B.SUBJECT_PROJECT): path = getExistingPath(job, os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_TDATA], getattr(job.par, B.SUBJECT_PROJECT), P.KEY_CATALOG, name)) @@ -253,20 +272,34 @@ def getCatalogPath(job, name): return path raise Exception(P.EXP_CONFIG_MISSING, name) -def getUserPath(job, name): + +def getUserPath(job: any, name: str) -> str: + """ + the function searchs the config-file in the user-context. + :param job: + :param name: + :return: + """ for ext in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], P.VAL_CONFIG, P.VAL_USER, name + "." + ext) if os.path.exists(pathname): - return pathname - return None + return str(pathname) + raise Exception(P.EXP_CONFIG_MISSING, name) -def getModelPath(job, name): + +def getModelPath(job: any, name: str) -> str: + """ + the function searchs the config-file in the model-context. + :param job: + :param name: + :return: + """ for ext in CONFIG_FORMAT: pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_PROGRAM], P.ATTR_PATH_MODEL, name + "." + ext) if os.path.exists(pathname): - return pathname - return None + return str(pathname) + raise Exception(P.EXP_CONFIG_MISSING, name) def get_plain_filename(job, path): @@ -280,12 +313,13 @@ def get_plain_filename(job, path): filename = names.pop() for ext in CONFIG_FORMAT: if filename[-len(ext):] == ext: - filename = filename[:-len(ext)-1] + filename = filename[:-len(ext) - 1] return filename return filename -def getConfValue(attribute, comp): - if attribute == B.ATTR_CONN_DBTYPE: + +def getConfValue(attribute: str, comp: any) -> str: + if attribute == B.ATTR_TYPE: if not hasAttr(comp.conf[B.TOPIC_CONN], "dbtype"): if hasAttr(comp.conf[B.TOPIC_CONN], "types") and hasAttr(comp.conf[B.TOPIC_CONN]["types"], "dbtype"): dbtype = comp.conf[B.TOPIC_CONN]["types"]["dbtype"] @@ -298,10 +332,10 @@ def getConfValue(attribute, comp): def getAttr(o, name): - if (isinstance(o, dict)): - if (name in o.keys()): + if isinstance(o, dict): + if name in o.keys(): return o[name] - elif (isinstance(o, list)): + elif isinstance(o, list): pass elif hasattr(o, name): return getattr(o, name) @@ -309,13 +343,11 @@ def getAttr(o, name): def hasAttr(o, name): - if (isinstance(o, dict)): - if (name in o.keys()): + if isinstance(o, dict): + if name in o.keys(): return True - elif (isinstance(o, list)): + elif isinstance(o, list): pass - - elif hasattr(o, name): return True return False @@ -338,11 +370,9 @@ def getConfig(job, modul: str, name: str, subname: str = "", ttype: str = D.CSV_ msg = None if hasattr(job, "m"): msg = job.m pathname = select_config_path(job, modul, name, subname) - # print("+++ " + str(pathname)) confs = {} if pathname is None: - return None - job.debug(verify, "getConfig " + pathname) + return {} if len(pathname) < 1: return confs if ttype == "" and modul in ["tool", "comp"]: @@ -375,7 +405,7 @@ def getAttributeList(comp, path, job): artType = a[0] artName = a[1] if B.TOPIC_CONN not in comp.conf: - raise Exception ("Environment is not configured") + raise Exception("Environment is not configured") if artType in comp.conf[B.TOPIC_CONN]: if artName in comp.conf[B.TOPIC_CONN][artType]: for attr, val in comp.conf[B.TOPIC_CONN][artType][artName].items(): @@ -404,6 +434,7 @@ def getAttributeList(comp, path, job): attrList[attr] = val return attrList + def mergeConn(msg, conf, conn): """ merges the config-attributes from the connection-attributes @@ -422,33 +453,35 @@ def mergeConn(msg, conf, conn): if topic not in conf[B.SUBJECT_ARTIFACTS]: continue if topic == B.TOPIC_NODE_DB: - list = B.LIST_DB_ATTR - if topic == B.TOPIC_NODE_CLI: - list = B.LIST_CLI_ATTR - if topic == B.TOPIC_NODE_API: - list = B.LIST_API_ATTR - if topic == B.TOPIC_NODE_FILE: - list = B.LIST_FILE_ATTR + attrlist = B.LIST_DB_ATTR + elif topic == B.TOPIC_NODE_CLI: + attrlist = B.LIST_CLI_ATTR + elif topic == B.TOPIC_NODE_API: + attrlist = B.LIST_API_ATTR + elif topic == B.TOPIC_NODE_FILE: + attrlist = B.LIST_FILE_ATTR + else: + attrlist = [] for a in conf[B.SUBJECT_ARTIFACTS][topic]: if topic not in conn: continue - if a in list: + if a in attrlist: if a in conn[topic]: conf[B.SUBJECT_ARTIFACTS][topic][a] = conn[topic][a] else: for b in conf[B.SUBJECT_ARTIFACTS][topic][a]: - if b not in list: - msg.logError("not-topic-attribute in topic-connection: "+topic+", "+b) + if b not in attrlist: + msg.logError("not-topic-attribute in topic-connection: " + topic + ", " + b) continue if a not in conn[topic]: continue if b in conn[topic][a]: conf[B.SUBJECT_ARTIFACTS][topic][a][b] = conn[topic][a][b] - for a in list: + for a in attrlist: if topic not in conn: break if topic not in conn: continue if a in conn[topic]: conf[B.SUBJECT_ARTIFACTS][topic][a] = conn[topic][a] - return conf \ No newline at end of file + return conf diff --git a/tools/make_tool.py b/tools/make_tool.py index e69de29..7a01d07 100644 --- a/tools/make_tool.py +++ b/tools/make_tool.py @@ -0,0 +1,36 @@ +# --------------------------------------- +# functions for managing diverse repositories +# namescheme: +# server/project_element.git +# project_element_server/.git +import os +import tools.config_tool +import basic.constants as B +import tools.path_const as P +import tools.data_const as D + + +def createWorkspaces(job: any, project=""): + projects = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_PROJECTS, ttype=D.CSV_SPECTYPE_KEYS) + servers = tools.config_tool.getConfig(job, P.KEY_BASIC, "servers", ttype=D.CSV_SPECTYPE_KEYS) + repositories = tools.config_tool.getConfig(job, P.KEY_BASIC, "repositories", ttype=D.CSV_SPECTYPE_KEYS) + home = job.conf[B.TOPIC_PATH][B.ATTR_PATH_HOME] + pp = [] + if project == "": + for p in projects[B.SUBJECT_PROJECTS]: + pp.append(projects[B.SUBJECT_PROJECTS][p]["short"]) + else: + pp.append(project) + sp = str(os.path.sep) + a = home.split(sp) + while a[-1] != "workspace": + a.pop() + print(str(a)) + workroot = sp.join(a) + print(str(servers)) + + for s in servers["servers"]: + print("s: "+str(servers["servers"][s])) + for p in pp: + workpath = os.path.join(workroot, p+"_workspace_"+servers["servers"][s]["name"]) + print(workpath) diff --git a/tools/path_tool.py b/tools/path_tool.py index fc9e0e4..dbe1fe4 100644 --- a/tools/path_tool.py +++ b/tools/path_tool.py @@ -54,8 +54,7 @@ def getActualJsonPath(job): return path - -def compose_path(job, pathname, comp): +def compose_path(job: any, pathname: str, comp=None) -> str: """ 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/value.yml.