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")
return
for k in job.conf.confs[B.SUBJECT_APPS].get(anw):
if k == B.ATTR_APPS_PROJECT:
continue
job.m.logDebug("applicationscomponente -- " + k + ":")
print("applicationscomponente -- " + k + ":")
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 """
SUBJECT_APPS = "applications" # | x | | | | CompHandling
ATTR_APPS_PROJECT = "project" # | | | | x | CompHanlding
SUBJECT_INST = "instance" # | | | | 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.path_tool
import utils.file_tool
import utils.config_tool
jobdef = {
@ -109,18 +110,24 @@ EXCP_CANT_POP = "cant pop this job from the instances"
class Job:
__instance = None
instances = []
__instances = []
def __init__ (self, program):
print ("################# init Job ## " + program + " #################")
self.program = program
Job.__instance = self
if Job.__instances is None:
Job.__instances = []
Job.pushInstance(self)
par = Parameter(program)
self.par = par
print("prog-42 " + str(self.par.basedir))
conf = Configuration(program)
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))
dirpath = self.par.getDirParameter()
setGlobal()
@ -138,27 +145,27 @@ class Job:
if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
raise Exception(B.EXP_CANT_POP)
# 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
return None
if Job.__instance is None:
while len(Job.instances) > 0:
Job.instances.pop()
while len(Job.__instances) > 0:
Job.__instances.pop()
return None
if len(Job.instances) == 1:
if len(Job.__instances) == 1:
job = Job.__instance
job.stopJob(1)
Job.instances.pop()
Job.__instances.pop()
Job.__instance = None
return None
job = Job.instances.pop()
job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob:
Job.instances.append(job)
Job.__instances.append(job)
Job.__instance = job
raise Exception(B.EXP_CANT_POP)
if len(Job.instances) > 0:
topjob = Job.instances.pop()
Job.instances.append(topjob)
if len(Job.__instances) > 0:
topjob = Job.__instances.pop()
Job.__instances.append(topjob)
Job.__instance = topjob
else:
Job.__instance = None
@ -168,11 +175,11 @@ class Job:
@staticmethod
def pushInstance(pjob):
""" push a new created subjob """
if len(Job.instances) > 0:
job = Job.instances.pop()
if len(Job.__instances) > 0:
job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob:
Job.instances.append(job)
Job.instances.append(pjob)
Job.__instances.append(job)
Job.__instances.append(pjob)
Job.__instance = pjob
return pjob
@ -249,6 +256,8 @@ class Job:
for c in cconf:
output[B.SUBJECT_COMPS][c] = {}
for x in ["function", "conn"]:
if x not in cconf[c]:
continue
output[B.SUBJECT_COMPS][c][x] = cconf[c][x]
if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]:
cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx"
@ -435,6 +444,12 @@ class Parameter:
dirpath = self.getDirParameter()
if dirpath is not None:
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):

2
test/constants.py

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

3
test/test_01date.py

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

4
test/test_02css.py

@ -4,7 +4,7 @@ unit-test
import unittest
import utils.css_tool
import basic.program
import json
import test.testtools
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
@ -18,7 +18,7 @@ class MyTestCase(unittest.TestCase):
self.test_css()
def test_01css(self):
job = basic.program.Job("unit")
job = test.testtools.getJob()
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"}

10
test/test_04config.py

@ -3,13 +3,11 @@ import os
import inspect
import utils.config_tool
import utils.conn_tool
import test.constants
import test.constants as T
import test.testtools
import utils.path_const as P
import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
PROG_PATH = test.constants.PROG_PATH
TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"]
VERIFY = False
@ -23,9 +21,13 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
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"
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
x = "conn"
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":
path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp
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,
gran+"dir": path,
"step": 2}

7
utils/config_tool.py

@ -93,6 +93,13 @@ def getConfigPath(modul, name, subname=""):
if os.path.exists(pathname):
return pathname
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:
pathname = utils.path_tool.composePath(P.P_TCPARFILE)
job.debug(verify, "7 " + pathname)

2
utils/path_const.py

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

Loading…
Cancel
Save