Browse Source

config application from components

master
Ulrich Carmesin 2 years ago
parent
commit
3307c789db
  1. 2
      basic/componentHandling.py
  2. 1
      basic/constants.py
  3. 45
      basic/program.py
  4. 2
      test/constants.py
  5. 3
      test/test_01date.py
  6. 4
      test/test_02css.py
  7. 10
      test/test_04config.py
  8. 2
      test/testtools.py
  9. 7
      utils/config_tool.py
  10. 2
      utils/path_const.py

2
basic/componentHandling.py

@ -86,6 +86,8 @@ class ComponentManager:
job.m.setFatal("application " + job.par.application + " is not configured") job.m.setFatal("application " + job.par.application + " is not configured")
return return
for k in job.conf.confs[B.SUBJECT_APPS].get(anw): for k in job.conf.confs[B.SUBJECT_APPS].get(anw):
if k == B.ATTR_APPS_PROJECT:
continue
job.m.logDebug("applicationscomponente -- " + k + ":") job.m.logDebug("applicationscomponente -- " + k + ":")
print("applicationscomponente -- " + k + ":") print("applicationscomponente -- " + k + ":")
self.createComponent(k, 0, "") self.createComponent(k, 0, "")

1
basic/constants.py

@ -172,6 +172,7 @@ ATTR_PATH_PATTN = "pattern"
""" This constant defines the debug-folder in testing-filesystem """ """ This constant defines the debug-folder in testing-filesystem """
SUBJECT_APPS = "applications" # | x | | | | CompHandling SUBJECT_APPS = "applications" # | x | | | | CompHandling
ATTR_APPS_PROJECT = "project" # | | | | x | CompHanlding
SUBJECT_INST = "instance" # | | | | x | CompHanlding SUBJECT_INST = "instance" # | | | | x | CompHanlding
ATTR_INST_CNT = "count" # | | | | x | CompHanlding ATTR_INST_CNT = "count" # | | | | x | CompHanlding

45
basic/program.py

@ -19,6 +19,7 @@ import basic.componentHandling
import utils.date_tool import utils.date_tool
import utils.path_tool import utils.path_tool
import utils.file_tool import utils.file_tool
import utils.config_tool
jobdef = { jobdef = {
@ -109,18 +110,24 @@ EXCP_CANT_POP = "cant pop this job from the instances"
class Job: class Job:
__instance = None __instance = None
instances = [] __instances = []
def __init__ (self, program): def __init__ (self, program):
print ("################# init Job ## " + program + " #################") print ("################# init Job ## " + program + " #################")
self.program = program self.program = program
Job.__instance = self Job.__instance = self
if Job.__instances is None:
Job.__instances = []
Job.pushInstance(self) Job.pushInstance(self)
par = Parameter(program) par = Parameter(program)
self.par = par self.par = par
print("prog-42 " + str(self.par.basedir)) print("prog-42 " + str(self.par.basedir))
conf = Configuration(program) conf = Configuration(program)
self.conf = conf self.conf = conf
appl = utils.config_tool.getConfig("basic", B.SUBJECT_APPS)
print(appl)
if appl is not None:
self.conf.confs[B.SUBJECT_APPS] = appl[B.SUBJECT_APPS]
print("prog-45 " + str(self.par.basedir)) print("prog-45 " + str(self.par.basedir))
dirpath = self.par.getDirParameter() dirpath = self.par.getDirParameter()
setGlobal() setGlobal()
@ -138,27 +145,27 @@ class Job:
if pjob is not None and Job.__instance is not None and Job.__instance != pjob: if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
raise Exception(B.EXP_CANT_POP) raise Exception(B.EXP_CANT_POP)
# for guarantee that both the stack and the original variable is empty if one is empty # for guarantee that both the stack and the original variable is empty if one is empty
if len(Job.instances) < 1: if len(Job.__instances) < 1:
Job.__instance = None Job.__instance = None
return None return None
if Job.__instance is None: if Job.__instance is None:
while len(Job.instances) > 0: while len(Job.__instances) > 0:
Job.instances.pop() Job.__instances.pop()
return None return None
if len(Job.instances) == 1: if len(Job.__instances) == 1:
job = Job.__instance job = Job.__instance
job.stopJob(1) job.stopJob(1)
Job.instances.pop() Job.__instances.pop()
Job.__instance = None Job.__instance = None
return None return None
job = Job.instances.pop() job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob: if pjob is not None and job is not None and job != pjob:
Job.instances.append(job) Job.__instances.append(job)
Job.__instance = job Job.__instance = job
raise Exception(B.EXP_CANT_POP) raise Exception(B.EXP_CANT_POP)
if len(Job.instances) > 0: if len(Job.__instances) > 0:
topjob = Job.instances.pop() topjob = Job.__instances.pop()
Job.instances.append(topjob) Job.__instances.append(topjob)
Job.__instance = topjob Job.__instance = topjob
else: else:
Job.__instance = None Job.__instance = None
@ -168,11 +175,11 @@ class Job:
@staticmethod @staticmethod
def pushInstance(pjob): def pushInstance(pjob):
""" push a new created subjob """ """ push a new created subjob """
if len(Job.instances) > 0: if len(Job.__instances) > 0:
job = Job.instances.pop() job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob: if pjob is not None and job is not None and job != pjob:
Job.instances.append(job) Job.__instances.append(job)
Job.instances.append(pjob) Job.__instances.append(pjob)
Job.__instance = pjob Job.__instance = pjob
return pjob return pjob
@ -249,6 +256,8 @@ class Job:
for c in cconf: for c in cconf:
output[B.SUBJECT_COMPS][c] = {} output[B.SUBJECT_COMPS][c] = {}
for x in ["function", "conn"]: for x in ["function", "conn"]:
if x not in cconf[c]:
continue
output[B.SUBJECT_COMPS][c][x] = cconf[c][x] output[B.SUBJECT_COMPS][c][x] = cconf[c][x]
if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]: if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]:
cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx" cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx"
@ -435,6 +444,12 @@ class Parameter:
dirpath = self.getDirParameter() dirpath = self.getDirParameter()
if dirpath is not None: if dirpath is not None:
utils.path_tool.extractPath(dirpath[0], dirpath[1]) utils.path_tool.extractPath(dirpath[0], dirpath[1])
app = self.application
if self.application in job.conf.confs[B.SUBJECT_APPS]:
if B.ATTR_APPS_PROJECT in job.conf.confs[B.SUBJECT_APPS][self.application]:
setattr(self, B.ATTR_APPS_PROJECT, job.conf.confs[B.SUBJECT_APPS][self.application][B.ATTR_APPS_PROJECT])
proj = getattr(self, B.ATTR_APPS_PROJECT)
app2 = self.application
def setParameterLoaded(self): def setParameterLoaded(self):

2
test/constants.py

@ -4,6 +4,8 @@ constants
import os import os
home = os.getcwd() home = os.getcwd()
prgdir = "" prgdir = ""
if home[-4:] == "test" and home[-6:] != "datest":
home = home[0:-5]
if home[-6:] == "datest": if home[-6:] == "datest":
prgdir = home[-6:] prgdir = home[-6:]
home = home[0:-7] home = home[0:-7]

3
test/test_01date.py

@ -3,7 +3,6 @@ import inspect
import unittest import unittest
import datetime import datetime
import utils.date_tool import utils.date_tool
import test.abstractTestcase
TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"] TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
#TEST_FUNCTIONS = ["test_parseFormula"] #TEST_FUNCTIONS = ["test_parseFormula"]
@ -11,7 +10,7 @@ verbose = True
# class MyTestCase(unittest.TestCase): # class MyTestCase(unittest.TestCase):
class MyTestCase(test.abstractTestcase.MyTestCase): class MyTestCase(unittest.TestCase):
TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"] TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"

4
test/test_02css.py

@ -4,7 +4,7 @@ unit-test
import unittest import unittest
import utils.css_tool import utils.css_tool
import basic.program import basic.program
import json import test.testtools
# 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
@ -18,7 +18,7 @@ class MyTestCase(unittest.TestCase):
self.test_css() self.test_css()
def test_01css(self): def test_01css(self):
job = basic.program.Job("unit") job = test.testtools.getJob()
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"} "modus": "unit"}

10
test/test_04config.py

@ -3,13 +3,11 @@ import os
import inspect import inspect
import utils.config_tool import utils.config_tool
import utils.conn_tool import utils.conn_tool
import test.constants import test.constants as T
import test.testtools import test.testtools
import utils.path_const as P import utils.path_const as P
import basic.constants as B import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
PROG_PATH = test.constants.PROG_PATH
TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"] TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"]
VERIFY = False VERIFY = False
@ -23,9 +21,13 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
x = B.SUBJECT_APPS
r = utils.config_tool.getConfigPath(P.KEY_BASIC, x)
self.assertIn(os.path.join(T.COMP_PATH, B.SUBJECT_APPS), r)
cnttest += 1
x = "path" x = "path"
r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) r = utils.config_tool.getConfigPath(P.KEY_TOOL, x)
self.assertIn(os.path.join(PROG_PATH, P.VAL_UTIL, P.VAL_CONFIG), r) self.assertIn(os.path.join(T.PROG_PATH, P.VAL_UTIL, P.VAL_CONFIG), r)
cnttest += 1 cnttest += 1
x = "conn" x = "conn"
r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) r = utils.config_tool.getConfigPath(P.KEY_TOOL, x)

2
test/testtools.py

@ -73,7 +73,7 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
elif gran == "ts": elif gran == "ts":
path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp
job = basic.program.Job("unit") job = basic.program.Job("unit")
job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH #job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH
args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp, args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp,
gran+"dir": path, gran+"dir": path,
"step": 2} "step": 2}

7
utils/config_tool.py

@ -93,6 +93,13 @@ def getConfigPath(modul, name, subname=""):
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name) raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
elif modul == P.KEY_BASIC:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
name + "."+format)
job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
else: else:
pathname = utils.path_tool.composePath(P.P_TCPARFILE) pathname = utils.path_tool.composePath(P.P_TCPARFILE)
job.debug(verify, "7 " + pathname) job.debug(verify, "7 " + pathname)

2
utils/path_const.py

@ -13,6 +13,8 @@ KEY_TESTCASE = "tc"
KEY_TESTSUITE = "ts" KEY_TESTSUITE = "ts"
KEY_DEBUGNAME = "debugname" KEY_DEBUGNAME = "debugname"
KEY_LOGNAME = "logname" KEY_LOGNAME = "logname"
KEY_BASIC = "basic"
""" keyword for basic config in components """
KEY_COMP = "comp" KEY_COMP = "comp"
""" keyword for individual component """ """ keyword for individual component """
KEY_TOOL = "tool" KEY_TOOL = "tool"

Loading…
Cancel
Save