Browse Source

refactor create Job() with args

refactor
Ulrich 2 years ago
parent
commit
8a307baaa4
  1. 1
      basic/constants.py
  2. 16
      basic/message.py
  3. 155
      basic/program.py
  4. 58
      test/test_71job.py
  5. 4
      utils/config/path.yml
  6. 40
      utils/config_tool.py
  7. 1
      utils/date_tool.py
  8. 38
      utils/path_tool.py

1
basic/constants.py

@ -58,6 +58,7 @@ PAR_DESCRIPT = 'desription'
PAR_TESTCASE = "testcase"
PAR_TESTCASES = "testcases"
PAR_TESTSUITE = "usecase"
# todo Trennung testsuite - usecase denn n:1-Zuordnung
PAR_TCTIME = "tctime"
PAR_TSTIME = "tstime"
PAR_TESTINSTANCES = "testinstances"

16
basic/message.py

@ -23,6 +23,7 @@ from datetime import datetime
import utils.path_tool
import utils.i18n_tool
import basic.text_const as T
import basic.constants as B
LIMIT_FATAL = 0
LIMIT_ERROR = 4
@ -84,6 +85,8 @@ class Message:
self.logfile = self.debugfile
elif job.program == "unit":
self.logfile = self.debugfile
elif hasattr(job.par, B.PAR_MODUS) and getattr(job.par, B.PAR_MODUS) == "unit":
self.logfile = self.debugfile
else:
self.setLogdir(job, logTime)
self.topmessage = ""
@ -94,11 +97,17 @@ class Message:
def setLogdir(self, job, logTime):
basedir = job.par.basedir
basedir = basedir.replace("base", "log")
os.makedirs(basedir, exist_ok=True)
# basedir = utils.path_tool.composePath(basedir, None)
basedir = utils.path_tool.composePath(job, basedir, None)
# basedir = utils.path_tool.composePath(job, basedir, None)
logpath = job.getLogpath()
basedir = os.path.dirname(logpath)
os.makedirs(basedir, exist_ok=True)
logpath = os.path.join(basedir , job.program + "_" + logTime + ".txt")
# logpath = os.path.join(basedir , job.program + "_" + logTime + ".txt")
self.logDebug("logfile " + logpath)
if os.path.exists(logpath):
self.logfile = open(logpath, "a")
else:
self.logfile = open(logpath, "w")
@ -117,6 +126,7 @@ class Message:
"rc4": "info",
"rc5": "debug",
"rc6": "trace",
"rc8": "fatal",
"1": "fatal",
"2": "error",
"3": "warn",
@ -194,7 +204,7 @@ class Message:
self.setRc(RC_MSG, text)
self.logInfo(text)
def getMessageText(self, text, args):
def getMessageText(self, job, text, args):
out = ""
constName = ""
for i in range(0, len(T.LIST_EXP_TEXT)):

155
basic/program.py

@ -30,84 +30,120 @@ jobdef = {
"pfiletarget": "",
"basedir": "workbase",
"dirname": "workdir",
"logdir": "{job.par.debugs}/webflask/log_{time}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.conf.data}/workspace/webflask_{job.start:H}.txt" },
"declare_result": {
"pardef": "",
"pfilesource": "",
"pfiletarget": "",
"basedir": "workbase",
"dirname": "workdir",
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.conf.data}/workspace/reorg_{job.start:H}.txt" },
"temp": {
"pardef": "",
"pfilesource": "",
"pfiletarget": "",
"basedir": "workbase",
"dirname": "workdir",
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.envdir}/{log}/log_{job.start:H}.txt" },
"unit": {
"pardef": "",
"pfilesource": "",
"pfiletarget": "envparfile",
"basedir": "envbase",
"dirname": "envdir",
"logdir": "{job.par.envdir}/{log}/log_{time}.txt" },
"loglevel": basic.message.LIMIT_DEBUG,
"logpath": "{job.par.envdir}/{log}/log_{job.start:H}.txt" },
"check_environment": {
"pardef": "",
"pfilesource": "",
"pfiletarget": "envparfile",
"basedir": "envbase",
"dirname": "envdir",
"logdir": "{job.par.envdir}/{log}/log_{time}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.envdir}/{log}/log_{job.start}.txt" },
"test_executer": {
"pardef": "",
"pfilesource": "tsparfile",
"pfiletarget": "tsparfile",
"basedir": "tsbase",
"dirname": "tsdir",
"logdir": "{job.par.tsdir}/{log}/log_{time}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tsdir}/{log}/{job.program}_{job.start}.txt" },
"init_testsuite": {
"pardef": "tsdir", # ,tdtyp,tdsrc,tdname",
"pfilesource": "envparfile",
"pfiletarget": "tsparfile",
"basedir": "tsbase",
"dirname": "tsdir",
"logdir": "{job.par.tsdir}/{log}/log_{tstime}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tsdir}/{log}/{job.program}_{job.start}.txt" },
"init_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource": "envparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt" },
"execute_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource": "tcparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt" },
"collect_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource": "tcparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt" },
"copy_appdummy": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource": "tcparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt"},
"compare_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource": "tcparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt" },
"test_system": {
"pardef": "tcdir,tdtyp,tdsrc,tdname",
"pfilesource": "tsparfile",
"pfiletarget": "tsparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"},
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt"},
"finish_testcase": {
"pardef": "tcdir",
"pfilesource": "tcparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"},
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt"},
"finish_testsuite": {
"pardef": "tsdir",
"pfilesource": "tsparfile",
"pfiletarget": "tssarfile",
"basedir": "tsbase",
"dirname": "tsdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"}
"loglevel": basic.message.LIMIT_INFO,
"logpath": "{job.par.tcdir}/{log}/{job.program}_{job.start}.txt"}
}
@ -125,6 +161,8 @@ DEFAULT_ENV = "Workspace"
DEFAULT_MODE = "test"
DEFAULT_TIME = "2022-08-29_17-29-59"
def createJob(pprg="", pgran="", papp="", penv="", ptstamp="", pmode=""):
"""
this creates a Job-Object with the main arguments.
@ -187,18 +225,31 @@ class Job:
__instances = []
__jobid = 100000
def __init__ (self, program):
def __init__ (self, program, args=None):
"""
initializing the job-object as a global structure for the actual doing
type of job:
a) (single) job for testing work [--args]
work-folder is the testcase-folder, logging into testcase-log
b) (single) job for reorganization of the testing area [--args]
working-folder is the workspace or the environment-folder, logging is there
c) webflask-job for the web-server --args
work-folder is the web-workspace,
if real jobs created these jobs runs as testing resp. reorganization-job
d) unit-testing job --args!
work-folder is the debug-area
if real jobs for unit-testing created these jobs runs with unit-mode like a unit-test
:param program:
:param args: optional with arguments otherwise the cli-parameter
"""
# postcondition
# - job.conf with basis config
# - job.par with parameter-args or cli-args
# - job.msg
print ("################# init Job ## " + program + " #################")
Job.__jobid += 1
self.jobid = str(Job.__jobid)
self.program = program
Job.__instance = self
if Job.__instances is None:
Job.__instances = []
#Job.pushInstance(self)
par = Parameter(self, program)
self.par = par
print("prog-42 " + str(self.par.basedir))
conf = Configuration(self, program)
self.conf = conf
try:
@ -211,7 +262,18 @@ class Job:
print(appl)
if appl is not None:
self.conf.confs[B.SUBJECT_APPS] = appl[B.SUBJECT_APPS]
print("prog-45 " + str(self.par.basedir))
par = Parameter(self, program, args)
self.par = par
logTime = utils.date_tool.getActdate(utils.date_tool.F_LOG)
self.start = logTime
self.m = basic.message.Message(self, jobdef[program]["loglevel"], logTime, None)
def getLogpath(self):
path = utils.path_tool.composePattern(self, jobdef[self.program]["logpath"], None)
return path
def murks(self, par, program):
self.par = par
dirpath = self.par.getDirParameter()
setGlobal()
if dirpath is not None:
@ -237,6 +299,7 @@ class Job:
if not hasattr(self.par, jobdef[program]["dirname"]):
setattr(self.par, jobdef[program]["dirname"],
utils.path_tool.composePattern(self, "{"+basedir+"}", None))
print(parstring)
self.par.setParameterLoaded(self)
@ -250,6 +313,7 @@ class Job:
self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
self.m.debug(basic.message.LIMIT_INFO, "# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
self.par.checkParameter(self)
self.m.logInfo(self.par.parstring)
def stopJob(self, reboot=0):
@ -292,9 +356,11 @@ class Job:
if len(str(jobdef[self.program]["pfilesource"])) < 2:
return None
parpath = utils.path_tool.composePath(self, jobdef[self.program]["pfilesource"], None)
print("parpath "+parpath)
if not os.path.join(parpath):
return None
doc = utils.file_tool.readFileDict(self, parpath, self.m)
print("parpath "+parpath)
doc = utils.file_tool.readFileDict(self, parpath, None)
for k in doc.keys():
output[k] = copy.deepcopy(doc[k])
return output
@ -307,6 +373,10 @@ class Job:
neu = utils.date_tool.getActdate(utils.date_tool.F_DIR)
# setattr(self.par, parameter, neu)
return neu
else:
print("Parameter "+parameter+" nicht in job.par ")
for attr, value in self.par.__dict__.items():
print(attr, value)
def hasElement(self, parameter, elem):
@ -371,17 +441,34 @@ class Job:
# ------------------------------------------------------------------------------------------------------------------
class Parameter:
"""
parameter with source either the list args or the args of the main-program
content of parameter:
+ single arguments
+ dirname of work-folder either from dir-parameter or composed from single parameter
comparison with a parameter-file from the work-folder
"""
print ("class Parameter")
def __init__ (self, job, program):
def __init__ (self, job, program, args=None):
print ("# init Parameter for " + program)
self.program = program
self.basedir = "debugs"
self.setBasedir(program)
if args is not None and isinstance(args, dict):
self.setParameterArgs(job, args)
else:
self.setParameter(job)
self.basedir = jobdef[program]["basedir"]
job.basedir = jobdef[program]["basedir"]
print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}")
if (program not in ["unit", "webflask"] ): self.setParameter(job)
job.par = self
if not hasattr(self, jobdef[program]["dirname"]):
setattr(self, jobdef[program]["dirname"],
utils.path_tool.composePattern(job, "{"+self.basedir+"}", None))
else:
utils.path_tool.extractPath(job, jobdef[program]["basedir"], getattr(self, jobdef[program]["dirname"]))
self.setParameterLoaded(job)
def setBasedir(self, program):
def setBasedir(self, job, program):
if jobdef[program]:
self.basedir = jobdef[program]["basedir"]
if hasattr(self, jobdef[program]["dirname"]):
@ -391,7 +478,8 @@ class Parameter:
dirpath = os.path.join(home, "data", "workspace")
setattr(self, jobdef[program]["dirname"], dirpath)
elif program != "unit":
dirpath = utils.path_tool.composePattern(None, "{"+jobdef[program]["basedir"]+"}", None)
# compose after setargs
dirpath = utils.path_tool.composePattern(job, "{"+jobdef[program]["basedir"]+"}", None)
setattr(self, jobdef[program]["dirname"], dirpath)
else:
self.basedir = "debugs"
@ -468,21 +556,20 @@ class Parameter:
if getattr(args, k) is not None:
self.setJobAttr(k , getattr(args, k))
dirpath = self.getDirParameter()
if dirpath is not None:
utils.path_tool.extractPath(job, dirpath[0], dirpath[1])
app = self.application
if self.application in job.conf.confs[B.SUBJECT_APPS]:
#if dirpath is not None:
# utils.path_tool.extractPath(job, dirpath[0], dirpath[1])
if hasattr(self, "application") and 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, job):
#job = Job.getInstance()
print("setParLoaded " )
print("setParLoaded "+job.program)
readedPar = job.loadParameter()
if readedPar is not None:
print(str(readedPar))
for k in readedPar["par"].keys():
if not hasattr(self, k):
self.setJobAttr(k, readedPar["par"][k])

58
test/test_71job.py

@ -25,7 +25,7 @@ class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_00create(self):
def test_01create(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -33,8 +33,62 @@ class MyTestCase(unittest.TestCase):
return
job = basic.program.createJob()
print(str(job))
args = { "application" : "TESTAPP" , "environment" : "ENV01", "step": "2", "tcdir": "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job.par.setParameterArgs(job, args)
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-12-08")
job.setProgram("init_testcase")
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_00create(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
#
# start a webflask-job - a temp. job for responding an html-request, - with session-parameter?
args = {}
job = basic.program.Job("webflask", args)
print(str(job.par))
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "2",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job = basic.program.Job("unit", args)
print(str(job))
#job.par.setParameterArgs(job, args)
self.assertEqual(hasattr(job.par, B.PAR_TESTCASE), False)
self.assertEqual(hasattr(job.par, B.PAR_TCTIME), False)
self.assertEqual(True, hasattr(job, "m"))
msg = job.m
self.assertNotIn("testdata", msg.logfile.name)
#
# start a testing-job as unit-test - without log ?! - artifacts would be saved in tcdir
# in unit-tests often there is a dir not necessary
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "1", B.PAR_MODUS: "unit",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job = basic.program.Job("init_testcase", args)
print(str(job))
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-12-08")
self.assertEqual(hasattr(job, "m"), True)
self.assertNotIn("testdata", msg.logfile.name)
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "1",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-22-08"}
job = basic.program.Job("init_testcase", args)
print(str(job))
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-22-08")
self.assertEqual(hasattr(job, "m"), True)
self.assertNotIn("testdata", msg.logfile.name)
#
# start a job for workspace-reorganization - appending to central log
args = { B.PAR_APP: "TESTAPP",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-22-08"}
job = basic.program.Job("declare_result", args)
print(str(job.par))
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parameter(self):
global mymsg
@ -43,7 +97,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug",
args = { "application" : "TEST" , "environment" : "ENV01", B.PAR_MODUS : "unit", "loglevel" : "debug",
"tool" : "job_tool", "function": "reset_TData,load_TData" }
job.par.setParameterArgs(job, args)
self.assertEqual(job.hascomponente("TestA"), True)

4
utils/config/path.yml

@ -22,8 +22,8 @@ pattern:
preexec: env-pre-exec # only for dry unit-test
postexec: env-post-exec # only for dry unit-test
debugs: "{job.conf.home}/test/log"
# environment
workbase: "{job.conf.debugs}/workspace"
# workspace
workbase: "{job.conf.data}/workspace"
worklog: "{workbase}/{log}"
workparfile: "{workbase}/PARAMETER_workspace"
workappdir: "{workbase}/{appdir}/{comp.name}"

40
utils/config_tool.py

@ -41,34 +41,34 @@ def getConfigPath(job, modul, name, subname=""):
* yaml, json, csv
"""
if job is None:
verify = 24 # job = basic.program.Job.getInstance()
verify = False # job = basic.program.Job.getInstance()
else:
verify = job.getDebugLevel("config_tool")-4
job.debug(verify, "getConfig " + modul + ", " + name)
if verify: job.debug(verify, "getConfig " + modul + ", " + name)
#TODO path rejoin, config as const
if modul == P.KEY_TOOL:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
P.VAL_CONFIG, P.KEY_TOOL+"_"+name+"."+format)
job.debug(verify, "1 " + pathname)
if verify: job.debug(verify, "1 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
P.VAL_CONFIG, P.KEY_TOOL+"_"+name+"."+format)
job.debug(verify, "1 " + pathname)
if verify: job.debug(verify, "1 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM),
P.VAL_UTIL, P.VAL_CONFIG, name+"."+format)
job.debug(verify, "2 " + pathname)
if verify: job.debug(verify, "2 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_ENV),
job.par.environment, P.VAL_CONFIG, P.KEY_TOOL+"_"+ name+"."+format)
job.debug(verify, "3 " + pathname)
if verify: job.debug(verify, "3 " + pathname)
if os.path.exists(pathname):
return pathname
job.debug(verify, "3x " + pathname)
@ -77,16 +77,16 @@ def getConfigPath(job, modul, name, subname=""):
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
P.VAL_CONFIG, P.KEY_COMP+"_" + name + "."+format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
basic.componentHandling.getComponentFolder(name), "CONFIG." + format)
job.debug(verify, "5 " + pathname)
if verify: job.debug(verify, "5 " + pathname)
if os.path.exists(pathname):
return pathname
job.debug(verify, "6 " + pathname)
if verify: job.debug(verify, "6 " + pathname)
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
elif modul in COMP_FILES:
# for example DATASTRUCURE or the table
@ -106,70 +106,70 @@ def getConfigPath(job, modul, name, subname=""):
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
P.VAL_CONFIG , name + "."+format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
elif modul == P.KEY_TESTCASE:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_TDATA),
name, D.DFILE_TESTCASE_NAME + "."+format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
elif modul == P.KEY_TESTSUITE:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_TDATA),
name, D.DFILE_TESTSUITE_NAME + "." + format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
elif modul == P.KEY_CATALOG:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_TDATA),
P.KEY_CATALOG, name + "." + format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
P.KEY_CATALOG, name + "." + format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM),
P.KEY_CATALOG, name + "." + format)
job.debug(verify, "4 " + pathname)
if verify: job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
else:
pathname = utils.path_tool.composePath(job, P.P_TCPARFILE)
job.debug(verify, "7 " + pathname)
if verify: job.debug(verify, "7 " + pathname)
if os.path.exists(pathname):
return pathname
pathname = utils.path_tool.composePath(job, P.P_TSPARFILE)
job.debug(verify, "8 " + pathname)
if verify: job.debug(verify, "8 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
if len(subname) > 1:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_RELEASE),
P.VAL_CONFIG, "basis."+format)
job.debug(verify, "9 " + pathname)
if verify: job.debug(verify, "9 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
if len(subname) > 1:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_ENV),
P.VAL_CONFIG, "basis."+format)
job.debug(verify, "9 " + pathname)
if verify: job.debug(verify, "9 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
if len(subname) > 1:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
P.VAL_CONFIG, "basis."+format)
job.debug(verify, "9 " + pathname)
if verify: job.debug(verify, "9 " + pathname)
if os.path.exists(pathname):
return pathname
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)

1
utils/date_tool.py

@ -13,6 +13,7 @@ F_DIR = "%Y-%m-%d_%H-%M-%S"
F_DB_DATE = "%Y-%m-%d"
F_DE = "%d.%m.%Y"
F_N8 = "%Y%m%d"
F_LOG = "%Y%m%d_%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"]
def getActdate(format):

38
utils/path_tool.py

@ -53,15 +53,26 @@ def getKeyValue(job, key, comp=None):
:return:
"""
#job = basic.program.Job.getInstance()
try:
verify = job.getDebugLevel(TOOL_NAME)-4
except:
verify = False
pt = PathConf.getInstance(job)
job.debug(verify, "getKeyValue " + key)
if verify: job.debug(verify, "getKeyValue " + key)
if 'job.par' in key:
val = job.getParameter(key[8:])
return val
elif 'job.conf' in key:
val = job.conf.confs[B.SUBJECT_PATH][key[9:]]
job.debug(verify, val)
if verify: job.debug(verify, val)
return val
elif 'job.' in key:
a = key[4:].split(":")
val = getattr(job, a[0])
# only date with hours
if len(a) > 1 and a[1] == "H":
val = val[0:-4]+"00"
if verify: job.debug(verify, val)
return val
# return job.conf.confs["paths"][key[9:]]
elif 'comp.' in key:
@ -76,9 +87,10 @@ def getKeyValue(job, key, comp=None):
if key[4:] in comp.conf["conn"]:
return comp.conf["conn"][key[4:]]
pass
elif (pt.pattern):
elif key in pt.pattern:
return pt.pattern[key]
job.debug(verify, "pt exists")
elif "time" in key and hasattr(job, "start"):
return getattr(job, "start")
else:
return "xx-"+key+"-xx"
@ -112,23 +124,27 @@ def composePattern(job, pattern, comp):
:return: path
"""
#job = basic.program.Job.getInstance()
try:
verify = job.getDebugLevel(TOOL_NAME)
verbose = False
job.debug(verify, "composePattern " + pattern)
except:
verify = False
verbose = not False
#job.debug(verify, "composePattern " + pattern)
max=5
l = re.findall('\{.*?\}', pattern)
job.debug(verify, l)
#job.debug(verify, l)
print(l)
for pat in l:
if verbose: print(str(max) + ": " + pattern + ": " + pat)
pit = getKeyValue(job, pat[1:-1], comp)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
pattern = pattern.replace(pat, pit)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
while ("{" in pattern):
max = max-1
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
pattern = composePattern(job, pattern, comp)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
#job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
if (max < 3) :
break
return pattern

Loading…
Cancel
Save