|
|
@ -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 << |
|
|
@ -58,24 +62,20 @@ def select_config_path(job, modul, name, subname=""): |
|
|
|
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) |
|
|
|
basic.componentHandling.getComponentFolder(name), subname + "." + f) |
|
|
|
if os.path.exists(pathname): |
|
|
|
return 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,29 +453,31 @@ 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: |
|
|
|