|
@ -10,37 +10,50 @@ import basic.constants as B |
|
|
# ------------------------------------------------- |
|
|
# ------------------------------------------------- |
|
|
|
|
|
|
|
|
def hasAttr(o, name): |
|
|
def hasAttr(o, name): |
|
|
print("hasAttr " + str(type(o))+" "+name) |
|
|
|
|
|
if (isinstance(o, dict)): |
|
|
if (isinstance(o, dict)): |
|
|
if (name in o.keys()): |
|
|
if (name in o.keys()): |
|
|
print("hasAttr dict ok " + str(type(o))) |
|
|
|
|
|
return True |
|
|
return True |
|
|
print("hasAttr dict "+str(type(o))) |
|
|
|
|
|
elif (isinstance(o, list)): |
|
|
elif (isinstance(o, list)): |
|
|
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))) |
|
|
|
|
|
return True |
|
|
return True |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def getAttr(o, name): |
|
|
|
|
|
if (isinstance(o, dict)): |
|
|
|
|
|
if (name in o.keys()): |
|
|
|
|
|
return o[name] |
|
|
|
|
|
elif (isinstance(o, list)): |
|
|
|
|
|
print("getAttr c list "+str(type(o))) |
|
|
|
|
|
elif hasattr(o, name): |
|
|
|
|
|
return o.get(name) |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
Toolmanager |
|
|
Toolmanager |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
def getCompAttr(comp, topic, attr, table=""): |
|
|
|
|
|
out = "" |
|
|
|
|
|
print(topic+" "+attr+" "+str(comp)) |
|
|
|
|
|
if hasAttr(comp.conf[B.SUBJECT_CONN], topic) and hasAttr(comp.conf[B.SUBJECT_CONN][topic], attr): |
|
|
|
|
|
return getAttr(comp.conf[B.SUBJECT_CONN][topic], attr) |
|
|
|
|
|
if len(table) > 1 and hasAttr(comp.conf[B.SUBJECT_ARTS][topic], table) \ |
|
|
|
|
|
and hasAttr(comp.conf[B.SUBJECT_ARTS][topic][table], attr): |
|
|
|
|
|
return getAttr(comp.conf[B.SUBJECT_ARTS][topic][table], attr) |
|
|
|
|
|
if hasAttr(comp.conf[B.SUBJECT_ARTS], topic) and hasAttr(comp.conf[B.SUBJECT_ARTS][topic], attr): |
|
|
|
|
|
print("attr "+attr+" vorhanden") |
|
|
|
|
|
return getAttr(comp.conf[B.SUBJECT_ARTS][topic], attr) |
|
|
|
|
|
raise LookupError(topic+"."+attr+" is not set in comp " + comp.name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# class ToolManager: |
|
|
# class ToolManager: |
|
|
def getDbTool(comp): |
|
|
def getDbTool(comp): |
|
|
job = basic.program.Job.getInstance() |
|
|
job = basic.program.Job.getInstance() |
|
|
verify = int(job.getDebugLevel("db_tool")) |
|
|
verify = int(job.getDebugLevel("db_tool")) |
|
|
if not hasAttr(comp.conf[B.SUBJECT_CONN], "dbtype"): |
|
|
dbtype = getCompAttr(comp, B.TOPIC_NODE_DB, B.ATTR_TYPE, "") |
|
|
if hasAttr(comp.conf[B.SUBJECT_CONN], "types") and hasAttr(comp.conf[B.SUBJECT_CONN]["types"], "dbtype"): |
|
|
|
|
|
dbtype = comp.conf[B.SUBJECT_CONN]["types"]["dbtype"] |
|
|
|
|
|
else: |
|
|
|
|
|
raise LookupError("dbtype is not set in comp " + comp.name) |
|
|
|
|
|
else: |
|
|
|
|
|
dbtype = comp.conf["conn"]["dbtype"] |
|
|
|
|
|
toolname = "db"+dbtype+"_tool" |
|
|
toolname = "db"+dbtype+"_tool" |
|
|
print("toolname "+toolname) |
|
|
filepath = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_PROGRAM], "utils", toolname+".py") |
|
|
filepath = os.path.join(job.conf.confs["paths"]["program"], "utils", toolname+".py") |
|
|
#comp.m.debug(verify, "toolname "+filepath) |
|
|
print("toolname "+filepath) |
|
|
|
|
|
if not os.path.exists(filepath): |
|
|
if not os.path.exists(filepath): |
|
|
raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath) |
|
|
raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath) |
|
|
cmodul = importlib.import_module("utils."+toolname) |
|
|
cmodul = importlib.import_module("utils."+toolname) |
|
@ -52,12 +65,10 @@ def getDbTool(comp): |
|
|
def getCliTool(comp): |
|
|
def getCliTool(comp): |
|
|
job = basic.program.Job.getInstance() |
|
|
job = basic.program.Job.getInstance() |
|
|
verify = int(job.getDebugLevel("db_tool")) |
|
|
verify = int(job.getDebugLevel("db_tool")) |
|
|
if not hasAttr(comp.conf["conn"], "clitype"): |
|
|
clitype = getCompAttr(comp, B.TOPIC_NODE_CLI, B.ATTR_TYPE, "") |
|
|
raise LookupError("dbtype is not set in comp " + comp.name) |
|
|
toolname = "cli"+clitype+"_tool" |
|
|
toolname = "cli"+comp.conf["conn"]["clitype"]+"_tool" |
|
|
filepath = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_PROGRAM], "utils", toolname+".py") |
|
|
print("toolname "+toolname) |
|
|
#comp.m.debug(verify, "toolname "+filepath) |
|
|
filepath = os.path.join(job.conf.confs["paths"]["program"], "utils", toolname+".py") |
|
|
|
|
|
print("toolname "+filepath) |
|
|
|
|
|
if not os.path.exists(filepath): |
|
|
if not os.path.exists(filepath): |
|
|
raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath) |
|
|
raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath) |
|
|
cmodul = importlib.import_module("utils."+toolname) |
|
|
cmodul = importlib.import_module("utils."+toolname) |
|
|