diff --git a/basic/componentHandling.py b/basic/componentHandling.py index 135fd0b..4a349cb 100644 --- a/basic/componentHandling.py +++ b/basic/componentHandling.py @@ -212,3 +212,8 @@ def isParameterSubnode(key): if key in k: return False return True + +def getPlainCompname(name): + if "_0" in name: + return name[0:-3] + return name \ No newline at end of file diff --git a/basic/constants.py b/basic/constants.py new file mode 100644 index 0000000..8aa5683 --- /dev/null +++ b/basic/constants.py @@ -0,0 +1,17 @@ +# +# the internal datastructure is a tree with this design: +# root { : constant +# + option { : constant +# + +# + steps +# + comp { : variable component-name +# + substructure { : variable maybe scheme, table of a database-component +# + + _header [ : constant +# - fields : variable field-name +DATA_NODE_DATA = "_data" + +# the configuration of a component or tool +# entity { : variable name of the group, basic, component-name or tool-name +# + subject { : variable subject-name - it correspondends to a tool +# + + sub-subject { : variable subject-name - it correspondends to a tool +# + attributes : constant of the tool in which the attribute ist implemented diff --git a/basic/program.py b/basic/program.py index 5bd7609..2529519 100644 --- a/basic/program.py +++ b/basic/program.py @@ -145,7 +145,7 @@ class Job: output = {} output["comps"] = basic.componentHandling.getComponentDict() output["par"] = self.par.__dict__ - print(str(output)) + # print(str(output)) with open(parpath, "w") as file: doc = yaml.dump(output, file) file.close() @@ -304,6 +304,15 @@ class Parameter: setattr(self, key, val) self.parstring = self.parstring + " --" + key + " " + val + def getJobPar(self, key): + a = key.split(":") + if len(a) == 1: + return self[a[0]] + if len(a) == 2: + return self[a[0]][a[1]] + + return + class Configuration: def __init__ (self, program): self.program = program @@ -327,3 +336,10 @@ class Configuration: self.confs[a[0]][a[1]] = val elif len(a) == 3: self.confs[a[0]][a[1]][a[2]] = val + + def getJobConf(self, key): + a = key.split(":") + if len(a) == 1: + return self.confs[a[0]] + if len(a) == 2: + return self.confs[a[0]][a[1]] diff --git a/basic/toolHandling.py b/basic/toolHandling.py index 31000d3..05c7d97 100644 --- a/basic/toolHandling.py +++ b/basic/toolHandling.py @@ -1,9 +1,61 @@ -# +import importlib, os + +import basic.program # ------------------------------------------------- + +def hasAttr(o, name): + print("hasAttr " + str(type(o))+" "+name) + if (isinstance(o, dict)): + if (name in o.keys()): + print("hasAttr dict ok " + str(type(o))) + return True + print("hasAttr dict "+str(type(o))) + elif (isinstance(o, list)): + print("hasAttr list "+str(type(o))) + elif hasattr(o, name): + print("hasAttr class ok "+str(type(o))) + return True + return False + """ Toolmanager """ -class ToolManager: - # for c job.conf.toolscls - # c = importlib. [c].capital(c()) - pass \ No newline at end of file +# class ToolManager: +def getDbTool(comp): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("db_tool")) + if not hasAttr(comp.conf["conn"], "dbtype"): + if hasAttr(comp.conf["conn"], "types") and hasAttr(comp.conf["conn"]["types"], "dbtype"): + dbtype = comp.conf["conn"]["types"]["dbtype"] + else: + raise LookupError("dbtype is not set in comp " + comp.name) + else: + dbtype = comp.conf["conn"]["dbtype"] + toolname = "db"+dbtype+"_tool" + print("toolname "+toolname) + filepath = os.path.join(job.conf.confs["paths"]["program"], "utils", toolname+".py") + print("toolname "+filepath) + if not os.path.exists(filepath): + raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath) + cmodul = importlib.import_module("utils."+toolname) + class_ = getattr(cmodul, "DbFcts") + c = class_() + c.setComp(comp) + return c + +def getCliTool(comp): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("db_tool")) + if not hasAttr(comp.conf["conn"], "clitype"): + raise LookupError("dbtype is not set in comp " + comp.name) + toolname = "cli"+comp.conf["conn"]["clitype"]+"_tool" + print("toolname "+toolname) + filepath = os.path.join(job.conf.confs["paths"]["program"], "utils", toolname+".py") + print("toolname "+filepath) + if not os.path.exists(filepath): + raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath) + cmodul = importlib.import_module("utils."+toolname) + class_ = getattr(cmodul, "CliFcts") + c = class_() + c.setComp(comp) + return c diff --git a/utils/config_tool.py b/utils/config_tool.py index 0c27e25..a968333 100644 --- a/utils/config_tool.py +++ b/utils/config_tool.py @@ -11,6 +11,9 @@ import basic.componentHandling import utils.path_tool import os.path +COMP_FILES = ["DATASTRUCTURE"] +CONFIG_FORMAT = ["yml", "json", "csv"] + def getConfigPath(modul, name): """ gets the most specified configuration of different sources @@ -52,6 +55,11 @@ def getConfigPath(modul, name): if os.path.exists(pathname): return pathname job.debug(verify, "6 " + pathname) + elif modul in COMP_FILES: + for format in CONFIG_FORMAT: + pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components", basic.componentHandling.getComponentFolder(name), modul+"."+format) + if os.path.exists(pathname): + return pathname else: pathname = utils.path_tool.composePath("tcparfile") job.debug(verify, "7 " + pathname) diff --git a/utils/conn_tool.py b/utils/conn_tool.py index 52eb04c..b039084 100644 --- a/utils/conn_tool.py +++ b/utils/conn_tool.py @@ -11,8 +11,13 @@ def getConnection(comp, nr): conn = {} if job.conf.confs.get("tools").get("connsrc") == "yml": conn = utils.config_tool.getConfig("tool", "conn") + xtypes = None + if ("types" in conn["env"][comp]): + xtypes = conn["env"][comp]["types"] instnr = "inst" + str(nr) if conn["env"][comp][instnr]: + if (xtypes is not None): + conn["env"][comp][instnr]["types"] = xtypes return conn["env"][comp][instnr] else: job.m.setFatal("Conn-Tool: Comp not configured " + comp + " " + str(nr)) @@ -39,8 +44,13 @@ def getConnections(comp): print(comp) print(conn["env"].keys()) print(conn["env"][comp]["instance"]) + xtypes = None + if ("types" in conn["env"][comp]): + xtypes = conn["env"][comp]["types"] for i in range(conn["env"][comp]["instance"]): print("range " + str(i+1)) instnr = "inst" + str(i+1) + if (xtypes is not None): + conn["env"][comp][instnr]["types"] = xtypes conns.append(conn["env"][comp][instnr]) return conns