Browse Source

config functions

master
Ulrich Carmesin 3 years ago
parent
commit
b2cd5e8ec8
  1. 5
      basic/componentHandling.py
  2. 17
      basic/constants.py
  3. 18
      basic/program.py
  4. 62
      basic/toolHandling.py
  5. 8
      utils/config_tool.py
  6. 10
      utils/conn_tool.py

5
basic/componentHandling.py

@ -212,3 +212,8 @@ def isParameterSubnode(key):
if key in k: if key in k:
return False return False
return True return True
def getPlainCompname(name):
if "_0" in name:
return name[0:-3]
return name

17
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

18
basic/program.py

@ -145,7 +145,7 @@ class Job:
output = {} output = {}
output["comps"] = basic.componentHandling.getComponentDict() output["comps"] = basic.componentHandling.getComponentDict()
output["par"] = self.par.__dict__ output["par"] = self.par.__dict__
print(str(output)) # print(str(output))
with open(parpath, "w") as file: with open(parpath, "w") as file:
doc = yaml.dump(output, file) doc = yaml.dump(output, file)
file.close() file.close()
@ -304,6 +304,15 @@ class Parameter:
setattr(self, key, val) setattr(self, key, val)
self.parstring = self.parstring + " --" + 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: class Configuration:
def __init__ (self, program): def __init__ (self, program):
self.program = program self.program = program
@ -327,3 +336,10 @@ class Configuration:
self.confs[a[0]][a[1]] = val self.confs[a[0]][a[1]] = val
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 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]]

62
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 Toolmanager
""" """
class ToolManager: # class ToolManager:
# for c job.conf.toolscls def getDbTool(comp):
# c = importlib. [c].capital(c()) job = basic.program.Job.getInstance()
pass 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

8
utils/config_tool.py

@ -11,6 +11,9 @@ import basic.componentHandling
import utils.path_tool import utils.path_tool
import os.path import os.path
COMP_FILES = ["DATASTRUCTURE"]
CONFIG_FORMAT = ["yml", "json", "csv"]
def getConfigPath(modul, name): def getConfigPath(modul, name):
""" """
gets the most specified configuration of different sources gets the most specified configuration of different sources
@ -52,6 +55,11 @@ def getConfigPath(modul, name):
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
job.debug(verify, "6 " + 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: else:
pathname = utils.path_tool.composePath("tcparfile") pathname = utils.path_tool.composePath("tcparfile")
job.debug(verify, "7 " + pathname) job.debug(verify, "7 " + pathname)

10
utils/conn_tool.py

@ -11,8 +11,13 @@ def getConnection(comp, nr):
conn = {} conn = {}
if job.conf.confs.get("tools").get("connsrc") == "yml": if job.conf.confs.get("tools").get("connsrc") == "yml":
conn = utils.config_tool.getConfig("tool", "conn") conn = utils.config_tool.getConfig("tool", "conn")
xtypes = None
if ("types" in conn["env"][comp]):
xtypes = conn["env"][comp]["types"]
instnr = "inst" + str(nr) instnr = "inst" + str(nr)
if conn["env"][comp][instnr]: if conn["env"][comp][instnr]:
if (xtypes is not None):
conn["env"][comp][instnr]["types"] = xtypes
return conn["env"][comp][instnr] return conn["env"][comp][instnr]
else: else:
job.m.setFatal("Conn-Tool: Comp not configured " + comp + " " + str(nr)) job.m.setFatal("Conn-Tool: Comp not configured " + comp + " " + str(nr))
@ -39,8 +44,13 @@ def getConnections(comp):
print(comp) print(comp)
print(conn["env"].keys()) print(conn["env"].keys())
print(conn["env"][comp]["instance"]) 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"]): for i in range(conn["env"][comp]["instance"]):
print("range " + str(i+1)) print("range " + str(i+1))
instnr = "inst" + 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]) conns.append(conn["env"][comp][instnr])
return conns return conns

Loading…
Cancel
Save