Browse Source

environment object

refactor
Ulrich 2 years ago
parent
commit
234ae5179e
  1. 3
      basic/Testserver.py
  2. 5
      basic/constants.py
  3. 15
      test/test_06file.py
  4. 2
      test/test_10testserver.py
  5. 12
      utils/conn_tool.py
  6. 6
      utils/date_tool.py
  7. 8
      utils/db_abstract.py
  8. 9
      utils/file_tool.py
  9. 2
      utils/git_tool.py

3
basic/Testserver.py

@ -5,7 +5,8 @@ import utils.data_const as D
import utils.file_tool import utils.file_tool
COMP_NAME = "testserver" 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): class Testserver(basic.component.Component):
def __init__(self, job): def __init__(self, job):

5
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 # + substructure { : variable maybe scheme, table of a database-component
# + + _header [ : constant # + + _header [ : constant
# - fields : variable field-name # - fields : variable field-name
CONF_NODE_GENERAL = "_general"
""" This constant defines a subnode of a table for the column-names """
DATA_NODE_HEADER = "_header" DATA_NODE_HEADER = "_header"
""" This constant defines a subnode of a table for the column-names """ """ This constant defines a subnode of a table for the column-names """
DATA_NODE_DATA = "_data" DATA_NODE_DATA = "_data"
@ -145,6 +147,7 @@ LIST_API_ATTR = [] + LIST_ARTS_ATTR
TOPIC_NODE_FILE = "file" TOPIC_NODE_FILE = "file"
ATTR_FILE_OLD = "oldfile" ATTR_FILE_OLD = "oldfile"
ATTR_FILE_ROTATE = "rotate" ATTR_FILE_ROTATE = "rotate"
NODE_ATTRIBUTES = "attributes"
LIST_FILE_ATTR = [ATTR_FILE_OLD, ATTR_FILE_ROTATE] + LIST_ARTS_ATTR LIST_FILE_ATTR = [ATTR_FILE_OLD, ATTR_FILE_ROTATE] + LIST_ARTS_ATTR
LIST_ATTR = { LIST_ATTR = {
@ -166,7 +169,7 @@ ATTR_CONN_DOMPATH = "dompath"
""" directory where the component is stored in the filesystem """ """ directory where the component is stored in the filesystem """
ATTR_CONN_USER = "user" ATTR_CONN_USER = "user"
ATTR_CONN_PASSWD = "password" 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 # the configuration of a component or tool
# entity { : variable name of the group, basic, component-name or tool-name # entity { : variable name of the group, basic, component-name or tool-name

15
test/test_06file.py

@ -11,13 +11,24 @@ import json
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH DATA_PATH = test.constants.DATA_PATH
TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding", "test_11readYml", "test_14readXml"] TEST_FUNCTIONS = ["test_getFiles", "test_02getModTime", "test_pathTool", "test_encoding", "test_11readYml", "test_14readXml"]
TEST_FUNCTIONS = ["test_11readYml"] TEST_FUNCTIONS = ["test_02getModTime"]
verbose = False verbose = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "" 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): def test_getFiles(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)

2
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. # the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function # 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_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 # with this variable you can switch prints on and off
verbose = False verbose = False

12
utils/conn_tool.py

@ -54,20 +54,20 @@ def getConnections(job, comp):
pass pass
conn = utils.config_tool.getConfig(job, "tool", B.SUBJECT_CONN) 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) job.m.setFatal("Conn-Tool: Comp not configured " + comp)
attr = {} attr = {}
if "general" in conn["env"]: if B.CONF_NODE_GENERAL in conn[B.SUBJECT_ENV]:
for a in conn["env"]["general"]: for a in conn[B.SUBJECT_ENV][B.CONF_NODE_GENERAL]:
attr[a] = conn["env"]["general"] attr[a] = conn[B.SUBJECT_ENV][B.CONF_NODE_GENERAL]
for a in conn["env"][comp]: for a in conn[B.SUBJECT_ENV][comp]:
if "inst" in a and a != B.SUBJECT_INST: if "inst" in a and a != B.SUBJECT_INST:
continue continue
attr[a] = conn["env"][comp][a] attr[a] = conn["env"][comp][a]
#if ("types" in conn["env"][comp]): #if ("types" in conn["env"][comp]):
# xtypes = conn["env"][comp]["types"] # 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)) #print("range " + str(i + 1))
instnr = "inst" + str(i + 1) instnr = "inst" + str(i + 1)
#if (xtypes is not None): #if (xtypes is not None):

6
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" F_DE_TSTAMP = "%d.%m.%Y %H:%M:%S"
MONTH_EN = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"] 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"] MONTH_DE = ["jan", "feb", "mar", "apr", "mai", "jun", "jul", "aug", "sep", "okt", "nov", "dez"]
F_TIME_DEFAULT = F_DIR
def getActdate(format): def getActdate(format):
return getFormatdate(datetime.datetime.now(), format) return getFormatdate(datetime.datetime.now(), format)
@ -150,8 +152,8 @@ def parseDate(instring):
mon = int(res.group(2)) mon = int(res.group(2))
day = int(res.group(1)) day = int(res.group(1))
return (year, mon, day, hour, min, sec) 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()): 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}) (\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) month = res.group(1)
mon = getMonthInt(month) mon = getMonthInt(month)
day = int(res.group(2)) day = int(res.group(2))

8
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 * If the table is partitioned tables the functions delete/insert/select calls the callback-functions
COMP.nextTable() resp. COMP.nextTdata(). COMP.nextTable() resp. COMP.nextTdata().
""" """
import json
import re import re
import basic.program import basic.program
@ -216,7 +217,7 @@ def formatDbField(comp, val, field):
comp.m.logError("must-field is null "+ field[D.DDL_FNAME]) comp.m.logError("must-field is null "+ field[D.DDL_FNAME])
return None return None
print("formatDbField "+str(comp)) 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]) 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 dtyp == D.TYPE_STRING or dtyp == D.TYPE_STR:
if not isinstance(val, str): if not isinstance(val, str):
msg.logError("field must be " + dtyp + ", " + str(val)) 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) return str(val)
if dtyp == D.TYPE_DATE: if dtyp == D.TYPE_DATE:
if not isinstance(val, str): if not isinstance(val, str):

9
utils/file_tool.py

@ -8,14 +8,18 @@ import json
import os import os
import os.path import os.path
import re import re
import time
import xmltodict import xmltodict
import yaml import yaml
import platform
import basic.message import basic.message
import basic.program import basic.program
import utils.data_const as D import utils.data_const as D
from pprint import pp from pprint import pp
import utils.tdata_tool import utils.tdata_tool
import utils.date_tool
def getDump(obj): def getDump(obj):
result="" result=""
@ -199,6 +203,11 @@ def readFileText(job, path, msg):
file.close() file.close()
return text 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): def readFileDict(job, path, msg):
""" """

2
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_ID] = a[0].strip()
res[COMMIT_AUTHOR] = a[1].strip() res[COMMIT_AUTHOR] = a[1].strip()
cdate = utils.date_tool.parseDate(a[2].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() res[COMMIT_COMMENT] = a[3].strip()
logs.append(res) logs.append(res)
i += 1 i += 1

Loading…
Cancel
Save