|
@ -20,6 +20,9 @@ import utils.date_tool |
|
|
import utils.path_tool |
|
|
import utils.path_tool |
|
|
import utils.file_tool |
|
|
import utils.file_tool |
|
|
|
|
|
|
|
|
|
|
|
BASIS_FILE = "basis.yml" |
|
|
|
|
|
EXCP_NO_BASIS_FILE = "basis file cant be found" |
|
|
|
|
|
|
|
|
jobdef = { |
|
|
jobdef = { |
|
|
"unit": { |
|
|
"unit": { |
|
|
"pardef": "", |
|
|
"pardef": "", |
|
@ -104,14 +107,17 @@ jobdef = { |
|
|
def setGlobal(): |
|
|
def setGlobal(): |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
EXCP_CANT_POP = "cant pop this job from the instances" |
|
|
|
|
|
|
|
|
class Job: |
|
|
class Job: |
|
|
__instance = None |
|
|
__instance = None |
|
|
|
|
|
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 |
|
|
|
|
|
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)) |
|
@ -129,16 +135,42 @@ class Job: |
|
|
print("prog-50 " + str(self.par.basedir)) |
|
|
print("prog-50 " + str(self.par.basedir)) |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def popInstance(): |
|
|
def popInstance(pjob=None): |
|
|
job = Job.getInstance() |
|
|
if pjob is not None and Job.__instance is not None and Job.__instance != pjob: |
|
|
|
|
|
raise Exception(EXCP_CANT_POP) |
|
|
|
|
|
if len(Job.instances) < 1: |
|
|
|
|
|
return None |
|
|
|
|
|
if len(Job.instances) == 1: |
|
|
|
|
|
job = Job.__instance |
|
|
|
|
|
job.stopJob(1) |
|
|
|
|
|
Job.instances.pop() |
|
|
|
|
|
Job.__instance = None |
|
|
|
|
|
return None |
|
|
|
|
|
job = Job.instances.pop() |
|
|
|
|
|
if pjob is not None and job is not None and job != pjob: |
|
|
|
|
|
Job.instances.append(job) |
|
|
|
|
|
Job.__instance = job |
|
|
|
|
|
raise Exception(EXCP_CANT_POP) |
|
|
|
|
|
if len(Job.instances) > 0: |
|
|
|
|
|
topjob = Job.instances.pop() |
|
|
|
|
|
Job.instances.append(topjob) |
|
|
|
|
|
Job.__instance = topjob |
|
|
|
|
|
else: |
|
|
Job.__instance = None |
|
|
Job.__instance = None |
|
|
return job |
|
|
return job |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def pushInstance(job): |
|
|
def pushInstance(pjob): |
|
|
Job.__instance = job |
|
|
if len(Job.instances) > 0: |
|
|
return job |
|
|
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.__instance = pjob |
|
|
|
|
|
return pjob |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
def resetInstance(program): |
|
|
def resetInstance(program): |
|
|
job = Job.getInstance() |
|
|
job = Job.getInstance() |
|
|
if job is not None: |
|
|
if job is not None: |
|
@ -147,9 +179,11 @@ class Job: |
|
|
Job(program) |
|
|
Job(program) |
|
|
return Job.__instance |
|
|
return Job.__instance |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setProgram(self, program): |
|
|
def setProgram(self, program): |
|
|
self.program = program |
|
|
self.program = program |
|
|
basedir = jobdef[program]["basedir"] |
|
|
basedir = jobdef[program]["basedir"] |
|
|
|
|
|
self.basedir = basedir |
|
|
if (self.par is not None): |
|
|
if (self.par is not None): |
|
|
setattr(self.par, "program", program) |
|
|
setattr(self.par, "program", program) |
|
|
setattr(self.par, "basedir", basedir) |
|
|
setattr(self.par, "basedir", basedir) |
|
@ -162,12 +196,14 @@ class Job: |
|
|
utils.path_tool.composePattern("{"+basedir+"}", None)) |
|
|
utils.path_tool.composePattern("{"+basedir+"}", None)) |
|
|
self.par.setParameterLoaded() |
|
|
self.par.setParameterLoaded() |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
def getInstance(): |
|
|
def getInstance(): |
|
|
if (Job.__instance is not None): |
|
|
if (Job.__instance is not None): |
|
|
return Job.__instance |
|
|
return Job.__instance |
|
|
else: |
|
|
else: |
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def startJob(self): |
|
|
def startJob(self): |
|
|
self.start = datetime.now() |
|
|
self.start = datetime.now() |
|
|
print("prog-68 " + str(self.par.basedir)) |
|
|
print("prog-68 " + str(self.par.basedir)) |
|
@ -179,6 +215,7 @@ class Job: |
|
|
self.m.debug(basic.message.LIMIT_INFO, "# # # 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.par.checkParameter() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stopJob(self, reboot=0): |
|
|
def stopJob(self, reboot=0): |
|
|
self.ende = datetime.now() |
|
|
self.ende = datetime.now() |
|
|
self.dumpParameter() |
|
|
self.dumpParameter() |
|
@ -193,21 +230,24 @@ class Job: |
|
|
if reboot == 0: |
|
|
if reboot == 0: |
|
|
exit(rc) |
|
|
exit(rc) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dumpParameter(self): |
|
|
def dumpParameter(self): |
|
|
parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None) |
|
|
parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None) |
|
|
if not os.path.exists(parpath): |
|
|
|
|
|
return None |
|
|
|
|
|
output = {} |
|
|
output = {} |
|
|
cconf = basic.componentHandling.getComponentDict() |
|
|
cconf = basic.componentHandling.getComponentDict() |
|
|
output["par"] = self.par.__dict__ |
|
|
output["par"] = self.par.__dict__ |
|
|
|
|
|
if len(cconf) < 1: |
|
|
|
|
|
utils.file_tool.writeFileDict(self.m, parpath, output) |
|
|
|
|
|
return |
|
|
output["comps"] = {} |
|
|
output["comps"] = {} |
|
|
for c in cconf: |
|
|
for c in cconf: |
|
|
output["comps"][c] = {} |
|
|
output["comps"][c] = {} |
|
|
for x in ["function", "conn"]: |
|
|
for x in ["function", "conn"]: |
|
|
output["comps"][c][x] = cconf[c][x] |
|
|
output["comps"][c][x] = cconf[c][x] |
|
|
if x == "conn" and "passwd" in cconf[c][x]: |
|
|
if x == "conn" and "passwd" in cconf[c][x]: |
|
|
output["comps"][c][x]["passwd"] = "xxxxx" |
|
|
cconf["comps"][c][x]["passwd"] = "xxxxx" |
|
|
utils.file_tool.writeFileText(self.m, parpath, output) |
|
|
utils.file_tool.writeFileDict(self.m, parpath, output) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def loadParameter(self): |
|
|
def loadParameter(self): |
|
|
output = {} |
|
|
output = {} |
|
@ -221,6 +261,7 @@ class Job: |
|
|
output[k] = copy.deepcopy(doc[k]) |
|
|
output[k] = copy.deepcopy(doc[k]) |
|
|
return output |
|
|
return output |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getParameter(self, parameter): |
|
|
def getParameter(self, parameter): |
|
|
if hasattr(self.par, parameter): |
|
|
if hasattr(self.par, parameter): |
|
|
return getattr(self.par, parameter) |
|
|
return getattr(self.par, parameter) |
|
@ -228,6 +269,8 @@ class Job: |
|
|
neu = utils.date_tool.getActdate(utils.date_tool.F_DIR) |
|
|
neu = utils.date_tool.getActdate(utils.date_tool.F_DIR) |
|
|
# setattr(self.par, parameter, neu) |
|
|
# setattr(self.par, parameter, neu) |
|
|
return neu |
|
|
return neu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hasElement(self, parameter, elem): |
|
|
def hasElement(self, parameter, elem): |
|
|
if hasattr(self.par, parameter): |
|
|
if hasattr(self.par, parameter): |
|
|
print (parameter + " in Parameter") |
|
|
print (parameter + " in Parameter") |
|
@ -264,6 +307,7 @@ class Job: |
|
|
else: |
|
|
else: |
|
|
print(text) |
|
|
print(text) |
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
|
class Parameter: |
|
|
class Parameter: |
|
|
print ("class Parameter") |
|
|
print ("class Parameter") |
|
|
def __init__ (self, program): |
|
|
def __init__ (self, program): |
|
@ -274,6 +318,7 @@ class Parameter: |
|
|
print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}") |
|
|
print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}") |
|
|
if (program != "unit"): self.setParameter() |
|
|
if (program != "unit"): self.setParameter() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setBasedir(self, program): |
|
|
def setBasedir(self, program): |
|
|
if jobdef[program]: |
|
|
if jobdef[program]: |
|
|
self.basedir = jobdef[program]["basedir"] |
|
|
self.basedir = jobdef[program]["basedir"] |
|
@ -285,6 +330,7 @@ class Parameter: |
|
|
else: |
|
|
else: |
|
|
self.basedir = "debugs" |
|
|
self.basedir = "debugs" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def checkParameter(self): |
|
|
def checkParameter(self): |
|
|
job = Job.getInstance() |
|
|
job = Job.getInstance() |
|
|
print (f"Parameter initialisiert {self.program}") |
|
|
print (f"Parameter initialisiert {self.program}") |
|
@ -344,6 +390,7 @@ class Parameter: |
|
|
return ("tsbase", str(self.tsdir)) |
|
|
return ("tsbase", str(self.tsdir)) |
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setParameterArgs(self, args): |
|
|
def setParameterArgs(self, args): |
|
|
job = Job.getInstance() |
|
|
job = Job.getInstance() |
|
|
print("setParArgs " + str(type(args))) |
|
|
print("setParArgs " + str(type(args))) |
|
@ -381,18 +428,23 @@ class Parameter: |
|
|
return self[a[0]][a[1]] |
|
|
return self[a[0]][a[1]] |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
|
class Configuration: |
|
|
class Configuration: |
|
|
def __init__ (self, program): |
|
|
def __init__ (self, program): |
|
|
self.program = program |
|
|
self.program = program |
|
|
print (f"job initialisiert {self.program}") |
|
|
print (f"job initialisiert {self.program}") |
|
|
if program == "unit": |
|
|
if program == "unit": |
|
|
if (os.path.exists('../conf/basis.yml')): |
|
|
if (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))): |
|
|
self.setConfiguration('../conf/basis.yml') |
|
|
self.setConfiguration(utils.path_tool.rejoinPath("..", "config", BASIS_FILE)) |
|
|
|
|
|
return |
|
|
|
|
|
elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", BASIS_FILE))): |
|
|
|
|
|
self.setConfiguration(utils.path_tool.rejoinPath("..", "config", BASIS_FILE)) |
|
|
return |
|
|
return |
|
|
elif (os.path.exists('conf/basis.yml')): |
|
|
elif (os.path.exists(utils.path_tool.rejoinPath("config", BASIS_FILE))): |
|
|
self.setConfiguration('../conf/basis.yml') |
|
|
self.setConfiguration(utils.path_tool.rejoinPath("config", BASIS_FILE)) |
|
|
return |
|
|
return |
|
|
self.setConfiguration('conf/basis.yml') |
|
|
raise Exception(EXCP_NO_BASIS_FILE) |
|
|
|
|
|
|
|
|
def setConfiguration(self, path): |
|
|
def setConfiguration(self, path): |
|
|
self.confs = {} |
|
|
self.confs = {} |
|
|