8 from abc
import abstractmethod
11 from validationscript
import Script
16 Base class which provides basic functionality to wrap basf2 into a shell
17 script setting up the environment and checking for completion of script
22 The default constructor.
32 self.
logger = logging.getLogger(
'validate_basf2')
40 belle2_release_dir = os.environ.get(
'BELLE2_RELEASE_DIR',
None)
41 belle2_local_dir = os.environ.get(
'BELLE2_LOCAL_DIR',
None)
45 if belle2_release_dir
is not None:
46 self.
b2setup +=
' ' + belle2_release_dir.split(
'/')[-1]
47 if belle2_local_dir
is not None:
48 self.
b2setup =
'MY_BELLE2_DIR=' + \
50 if os.environ.get(
'BELLE2_OPTION') !=
'debug':
51 self.
b2setup +=
'; b2code-option ' + os.environ.get(
'BELLE2_OPTION')
54 self.
logger.debug(f
'Setting up the following release: {self.b2setup}')
58 clusterlog_dir =
'./html/logs/__general__/'
59 if not os.path.exists(clusterlog_dir):
60 os.makedirs(clusterlog_dir)
63 self.
clusterlog = open(clusterlog_dir +
'clusterlog.log',
'w+')
67 Generate the file name used for the done output
69 return f
"{self.path}/script_{job.name}.done"
73 Setup output folders and create the wrapping shell script. Will return
74 the full file name of the generated wrapper script.
82 output_dir = os.path.abspath(f
'./results/{tag}/{job.package}')
83 if not os.path.exists(output_dir):
84 os.makedirs(output_dir)
87 log_file = output_dir +
'/' + os.path.basename(job.path) +
'.log'
91 if os.path.isfile(donefile_path):
92 os.remove(donefile_path)
95 extension = os.path.splitext(job.path)[1]
98 command =
'root -b -q ' + job.path
102 command = f
'basf2 {job.path} {options}'
110 tmp_name = self.
path +
'/' +
'script_' + job.name +
'.sh'
111 with open(tmp_name,
'w+')
as tmp_file:
112 tmp_file.write(
'#!/bin/bash \n\n' +
113 'BELLE2_NO_TOOLS_CHECK=1 \n' +
114 'source {0}/b2setup \n'.format(self.
tools) +
116 '{0} \n'.format(command) +
117 'echo $? > {0}/script_{1}.done \n'
118 .format(self.
path, job.name) +
119 'rm {0} \n'.format(tmp_name))
122 st = os.stat(tmp_name)
123 os.chmod(tmp_name, st.st_mode | stat.S_IEXEC)
129 Checks whether the '.done'-file has been created for a job. If so, it
130 returns True, else it returns False in the first part of the tuple.
131 Also deletes the .done-File it if exists.
132 The second entry in the tuple will be the exit code read from the done file
138 donefile_exists =
False
141 if os.path.isfile(donefile_path):
144 with open(donefile_path)
as f:
146 returncode = int(f.read().strip())
150 print(f
"donefile found with return code {returncode}")
151 donefile_exists =
True
152 os.remove(donefile_path)
154 print(
"no donefile found")
157 return [donefile_exists, returncode]
160 """! Terminate running job.
162 self.
logger.error(
"Script termination not supported.")
167 This method can be used if path names are different on submission
169 @param path: The past that needs to be adjusted
170 @return: The adjusted path