165 def run(self, dry_run=False):
166 cmd = '{} {}'.format(self.executable, self.args)
167 if self.cmd_prefix:
168 cmd = self.cmd_prefix + cmd
169 if self.cmd_suffix:
170 cmd += self.cmd_suffix
171 if self.output_stream == self.OutputStream.NO_PRINT:
172 cmd += ' >/dev/null 2>&1'
173 elif self.output_stream == self.OutputStream.FILE_ONLY:
174 cmd += ' >{} 2>&1'.format(self.get_log_file_name())
175 elif self.output_stream == self.OutputStream.FILE_AND_STDOUT:
176 cmd += ' 2>&1 | tee {}; exit ${{PIPESTATUS[0]}}'.format(self.get_log_file_name())
177 elif self.output_stream == self.OutputStream.STDOUT_ONLY:
178 cmd += ' 2>&1'
179
180 self.log.info('Running %s step using command:\n%s', self.name, cmd)
181 if dry_run:
182 self.result = 0
183 else:
184 with remember_cwd():
185 if self.workdir:
186 assert '..' not in self.workdir, "Illegal path for workdir -- must be a subdirectory of CWD"
187 assert not self.workdir.startswith('/'), "Illegal path for workdir -- no absolute paths!"
188 os.makedirs(self.workdir,exist_ok=True)
189 os.chdir(self.workdir)
190
191 if self.prmon:
192 prmon_proc = self.__start_prmon()
193 if self.timeout:
194 self.result = self.__execute_with_timeout(cmd, self.timeout)
195 else:
196 self.result = subprocess.call(cmd, shell=True)
197 if self.prmon:
198 self.__stop_prmon(prmon_proc)
199
200 if self.auto_report_result:
201 self.report_result()
202
203
204 if self.required \
205 and self.result != 0 \
206 and running_in_CI() \
207 and self.output_stream==self.OutputStream.FILE_ONLY:
208 self.log.
error(
'Step failure while running in CI. Printing partial log %s', self.get_log_file_name())
209
210
211 error_patterns = '^ERROR| ERROR | FATAL |[Tt]raceback'
212 grep_with_context(open(self.get_log_file_name()), error_patterns, lines=100)
213
214
215 if self.executable.endswith('_tf.py'):
216 log = open(self.get_log_file_name()).
read()
217 step_matches = re.findall('Logs for (.*) are in (.*)', log)
218 if not step_matches:
219 self.log.warning('Failed to determine sub-step log names, cannot print the full sub-step logs')
220 else:
221 step_log_names = [m[1] for m in step_matches]
222 for step_log_name in step_log_names:
223 if os.path.isfile(step_log_name):
224 self.log.info('Printing partial sub-step log file %s', step_log_name)
225 grep_with_context(open(step_log_name), error_patterns, lines=100)
226
227 return self.result, cmd
228
229
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)