diff --git a/basic/Testserver.py b/basic/Testserver.py index f75b30b..4f3ae68 100644 --- a/basic/Testserver.py +++ b/basic/Testserver.py @@ -5,7 +5,8 @@ import utils.data_const as D import utils.file_tool COMP_NAME = "testserver" -COMP_TABLES = ["application", "ap_component", "ap_project"] +COMP_TABLES = ["application", "ap_component", "ap_project", "ap_application", + "environment", "en_component", "en_project"] class Testserver(basic.component.Component): def __init__(self, job): diff --git a/basic/constants.py b/basic/constants.py index 84a366c..9931c88 100644 --- a/basic/constants.py +++ b/basic/constants.py @@ -85,6 +85,8 @@ LIST_MAIN_PAR = [PAR_APP, PAR_ENV, PAR_VAR, PAR_REL, PAR_TSDIR, PAR_TSDIR] # + substructure { : variable maybe scheme, table of a database-component # + + _header [ : constant # - fields : variable field-name +CONF_NODE_GENERAL = "_general" +""" This constant defines a subnode of a table for the column-names """ DATA_NODE_HEADER = "_header" """ This constant defines a subnode of a table for the column-names """ DATA_NODE_DATA = "_data" @@ -145,6 +147,7 @@ LIST_API_ATTR = [] + LIST_ARTS_ATTR TOPIC_NODE_FILE = "file" ATTR_FILE_OLD = "oldfile" ATTR_FILE_ROTATE = "rotate" +NODE_ATTRIBUTES = "attributes" LIST_FILE_ATTR = [ATTR_FILE_OLD, ATTR_FILE_ROTATE] + LIST_ARTS_ATTR LIST_ATTR = { @@ -166,7 +169,7 @@ ATTR_CONN_DOMPATH = "dompath" """ directory where the component is stored in the filesystem """ ATTR_CONN_USER = "user" ATTR_CONN_PASSWD = "password" -LIST_CONN_ATTR = [ATTR_DB_CONN_JAR, ATTR_CONN_HOST, ATTR_CONN_IP, ATTR_CONN_PORT, ATTR_CONN_DOMPATH, ATTR_CONN_USER, ATTR_CONN_PASSWD] +LIST_CONN_ATTR = [ATTR_CONN_HOST, ATTR_CONN_IP, ATTR_CONN_PORT, ATTR_CONN_DOMPATH, ATTR_CONN_USER, ATTR_CONN_PASSWD] # the configuration of a component or tool # entity { : variable name of the group, basic, component-name or tool-name diff --git a/test/test_06file.py b/test/test_06file.py index 8954f0a..3e37426 100644 --- a/test/test_06file.py +++ b/test/test_06file.py @@ -11,13 +11,24 @@ import json HOME_PATH = test.constants.HOME_PATH DATA_PATH = test.constants.DATA_PATH -TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding", "test_11readYml", "test_14readXml"] -TEST_FUNCTIONS = ["test_11readYml"] +TEST_FUNCTIONS = ["test_getFiles", "test_02getModTime", "test_pathTool", "test_encoding", "test_11readYml", "test_14readXml"] +TEST_FUNCTIONS = ["test_02getModTime"] verbose = False class MyTestCase(unittest.TestCase): mymsg = "" + def test_02getModTime(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + filepath = "/etc/hosts" + result = utils.file_tool.getModTime(job, filepath) + print("result "+result) + def test_getFiles(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) diff --git a/test/test_10testserver.py b/test/test_10testserver.py index 8842081..9035bfb 100644 --- a/test/test_10testserver.py +++ b/test/test_10testserver.py @@ -14,7 +14,7 @@ import utils.path_const as P # the list of TEST_FUNCTIONS defines which function will be really tested. # if you minimize the list you can check the specific test-function TEST_FUNCTIONS = ["test_01createTestserver", "test_02getDBSchema", "test_11createDBTables", "test_11syncApplication"] -TEST_FUNCTIONS = ["test_02getDBSchema"] +#TEST_FUNCTIONS = ["test_02getDBSchema"] # with this variable you can switch prints on and off verbose = False diff --git a/utils/conn_tool.py b/utils/conn_tool.py index deffbe7..a928a2d 100644 --- a/utils/conn_tool.py +++ b/utils/conn_tool.py @@ -54,20 +54,20 @@ def getConnections(job, comp): pass conn = utils.config_tool.getConfig(job, "tool", B.SUBJECT_CONN) - if not comp in conn["env"]: + if not comp in conn[B.SUBJECT_ENV]: job.m.setFatal("Conn-Tool: Comp not configured " + comp) attr = {} - if "general" in conn["env"]: - for a in conn["env"]["general"]: - attr[a] = conn["env"]["general"] - for a in conn["env"][comp]: + if B.CONF_NODE_GENERAL in conn[B.SUBJECT_ENV]: + for a in conn[B.SUBJECT_ENV][B.CONF_NODE_GENERAL]: + attr[a] = conn[B.SUBJECT_ENV][B.CONF_NODE_GENERAL] + for a in conn[B.SUBJECT_ENV][comp]: if "inst" in a and a != B.SUBJECT_INST: continue attr[a] = conn["env"][comp][a] #if ("types" in conn["env"][comp]): # xtypes = conn["env"][comp]["types"] - for i in range(conn["env"][comp][B.SUBJECT_INST][B.ATTR_INST_CNT]): + for i in range(conn[B.SUBJECT_ENV][comp][B.SUBJECT_INST][B.ATTR_INST_CNT]): #print("range " + str(i + 1)) instnr = "inst" + str(i + 1) #if (xtypes is not None): diff --git a/utils/date_tool.py b/utils/date_tool.py index a599f86..1f17cfc 100644 --- a/utils/date_tool.py +++ b/utils/date_tool.py @@ -18,6 +18,8 @@ F_LOG = "%Y%m%d_%H%M%S" F_DE_TSTAMP = "%d.%m.%Y %H:%M:%S" MONTH_EN = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"] MONTH_DE = ["jan", "feb", "mar", "apr", "mai", "jun", "jul", "aug", "sep", "okt", "nov", "dez"] +F_TIME_DEFAULT = F_DIR + def getActdate(format): return getFormatdate(datetime.datetime.now(), format) @@ -150,8 +152,8 @@ def parseDate(instring): mon = int(res.group(2)) day = int(res.group(1)) return (year, mon, day, hour, min, sec) - if re.match(r"\w{3} \w{3} \d{1,2} \d{1,2}[:]\d{1,2}[:]\d{2} \d{4}", instring.strip()): - res = re.search(r"\w{3} (\w{3}) (\d{1,2}) (\d{1,2})[:](\d{1,2})[:](\d{2}) (\d{4})", instring.strip()) + if re.match(r"\w{3} \w{3}\s+\d{1,2} \d{1,2}[:]\d{1,2}[:]\d{2} \d{4}", instring.strip()): + res = re.search(r"\w{3} (\w{3})\s+(\d{1,2}) (\d{1,2})[:](\d{1,2})[:](\d{2}) (\d{4})", instring.strip()) month = res.group(1) mon = getMonthInt(month) day = int(res.group(2)) diff --git a/utils/db_abstract.py b/utils/db_abstract.py index 706428a..4502b8f 100644 --- a/utils/db_abstract.py +++ b/utils/db_abstract.py @@ -38,6 +38,7 @@ SPECIAL CASES: * If the table is partitioned tables the functions delete/insert/select calls the callback-functions COMP.nextTable() resp. COMP.nextTdata(). """ +import json import re import basic.program @@ -216,7 +217,7 @@ def formatDbField(comp, val, field): comp.m.logError("must-field is null "+ field[D.DDL_FNAME]) return None print("formatDbField "+str(comp)) - print("formatDbField "+str(field)+" "+str(val)) + print("formatDbField "+str(field)+" , "+str(val)) return formatDbVal(comp.m, val, field[D.DDL_TYPE]) @@ -225,6 +226,11 @@ def formatDbVal(msg, val, dtyp): if dtyp == D.TYPE_STRING or dtyp == D.TYPE_STR: if not isinstance(val, str): msg.logError("field must be " + dtyp + ", " + str(val)) + if isinstance(val, dict): + val = json.dumps(val) + if isinstance(val, str): + val = val.replace("\"", "\\\"") + val = val.replace("\'", "\\\"") return str(val) if dtyp == D.TYPE_DATE: if not isinstance(val, str): diff --git a/utils/file_tool.py b/utils/file_tool.py index a1eb593..046daf0 100644 --- a/utils/file_tool.py +++ b/utils/file_tool.py @@ -8,14 +8,18 @@ import json import os import os.path import re +import time + import xmltodict import yaml +import platform import basic.message import basic.program import utils.data_const as D from pprint import pp import utils.tdata_tool +import utils.date_tool def getDump(obj): result="" @@ -199,6 +203,11 @@ def readFileText(job, path, msg): file.close() return text +def getModTime(job, filepath): + out = "" + mtime = os.path.getmtime(filepath) + out = utils.date_tool.formatParsedDate(time.ctime(mtime), utils.date_tool.F_TIME_DEFAULT) + return out def readFileDict(job, path, msg): """ diff --git a/utils/git_tool.py b/utils/git_tool.py index c71a65c..28543cd 100644 --- a/utils/git_tool.py +++ b/utils/git_tool.py @@ -70,7 +70,7 @@ def gitLog(job, repo, arg="", cnt=DEFAULT_CNT_COMMITS): res[COMMIT_ID] = a[0].strip() res[COMMIT_AUTHOR] = a[1].strip() cdate = utils.date_tool.parseDate(a[2].strip()) - res[COMMIT_DATE] = utils.date_tool.getFormatDatetupel(cdate, utils.date_tool.F_DIR) + res[COMMIT_DATE] = utils.date_tool.getFormatDatetupel(cdate, utils.date_tool.F_TIME_DEFAULT) res[COMMIT_COMMENT] = a[3].strip() logs.append(res) i += 1