15from abc
import abstractmethod
18from validationscript
import Script
23 Base class which provides basic functionality to wrap
basf2 into a shell
24 script setting up the environment
and checking
for completion of script
29 The default constructor.
39 self.logger = logging.getLogger("validate_basf2")
47 belle2_release_dir = os.environ.get(
"BELLE2_RELEASE_DIR",
None)
48 belle2_local_dir = os.environ.get(
"BELLE2_LOCAL_DIR",
None)
52 if belle2_release_dir
is not None:
53 self.
b2setup +=
" " + belle2_release_dir.split(
"/")[-1]
54 if belle2_local_dir
is not None:
61 if os.environ.get(
"BELLE2_OPTION") !=
"debug":
62 self.
b2setup +=
"; b2code-option " + os.environ.get(
"BELLE2_OPTION")
65 self.
logger.debug(f
"Setting up the following release: {self.b2setup}")
69 clusterlog_dir =
"./html/logs/__general__/"
70 if not os.path.exists(clusterlog_dir):
71 os.makedirs(clusterlog_dir)
74 self.
clusterlog = open(clusterlog_dir +
"clusterlog.log",
"w+")
78 Generate the file name used for the done output
80 return f
"{self.path}/script_{job.name}.done"
84 Setup output folders and create the wrapping shell script. Will
return
85 the full file name of the generated wrapper script.
93 output_dir = os.path.abspath(f
"./results/{tag}/{job.package}")
94 if not os.path.exists(output_dir):
95 os.makedirs(output_dir)
102 if os.path.isfile(donefile_path):
103 os.remove(donefile_path)
106 extension = os.path.splitext(job.path)[1]
107 if extension ==
".C":
109 command =
"root -b -q " + job.path
113 command = f
"basf2 {job.path} {options}"
121 tmp_name = self.
path +
"/" +
"script_" + job.name +
".sh"
122 with open(tmp_name,
"w+")
as tmp_file:
125 +
"BELLE2_NO_TOOLS_CHECK=1 \n"
126 + f
"source {self.tools}/b2setup \n"
127 + f
"cd {self.adjust_path(output_dir)} \n"
129 + f
"echo $? > {self.path}/script_{job.name}.done \n"
130 + f
"rm {tmp_name} \n"
134 st = os.stat(tmp_name)
135 os.chmod(tmp_name, st.st_mode | stat.S_IEXEC)
141 Checks whether the '.done'-file has been created
for a job. If so, it
142 returns
True,
else it returns
False in the first part of the tuple.
143 Also deletes the .done-File it
if exists.
144 The second entry
in the tuple will be the exit code read
from the done file
150 donefile_exists =
False
153 if os.path.isfile(donefile_path):
156 with open(donefile_path)
as f:
158 returncode = int(f.read().strip())
162 print(f
"donefile found with return code {returncode}")
163 donefile_exists =
True
164 os.remove(donefile_path)
166 print(
"no donefile found")
169 return [donefile_exists, returncode]
172 """! Terminate running job.
174 self.logger.error("Script termination not supported.")
179 This method can be used if path names are different on submission
181 @param path: The past that needs to be adjusted
182 @return: The adjusted path
logger
Contains a reference to the logger-object from validate_basf2 Set up the logging functionality for th...
str createDoneFileName(self, Script job)
Generate the file name used for the done output.
tools
Path to the basf2 tools and central/local release.
b2setup
The command for b2setup (and b2code-option)
clusterlog
The file object to which all cluster messages will be written.
path
The default constructor.
def checkDoneFile(self, job)
Checks whether the '.done'-file has been created for a job.
def adjust_path(self, path)
This method can be used if path names are different on submission and execution hosts.
def prepareSubmission(self, Script job, options, tag)
Setup output folders and create the wrapping shell script.
def terminate(self, Script job)
Terminate running job.
def __init__(self)
The default constructor.