def exit_usage(self, msg=None, exit_code=1, *args, **kwargs): if msg: Printer.err('Error: {}'.format(msg), *args, **kwargs) Printer.err(self.usage()) if exit_code is not None: raise ArgumentException(exit_code, msg)
def on_complete(self, pypy=None): # print either error that command failed or on_complete info id exists if self.pypy.returncode > 0: Printer.err('Error! Command ({process.pid}) ended with {process.returncode}'. format(process=self.pypy.executor.process)) Printer.err(Command.to_string(self.pypy.executor.command)) elif self.end_fmt: Printer.out(self.end_fmt.format(**dict(self=self))) if not self.pypy.progress: Printer.separator() output = self.pypy.executor.output.read() if output: Printer.out(output)
def on_complete(self, pypy=None): if self.pypy.returncode > 0: if self.message: Printer.separator() Printer.open() Printer.out(self.message) else: Printer.open() # if file pointer exist try to read errors and outputs output = self.pypy.executor.output.read() if output: if self.pypy.full_output: Printer.out('Output (last {} lines, rest in {}): ', self.tail, Paths.abspath(self.pypy.full_output)) else: Printer.out('Output (last {} lines): ', self.tail) Printer.err(format_n_lines(output, -self.tail, indent=Printer.indent * ' ')) Printer.close()
def on_update(self, pypy=None): if self.terminated: return if self.time_limit: try: runtime = self.process.runtime() if runtime > self.time_limit: Printer.out() Printer.err( 'Error: Time limit exceeded! {:1.2f}s of runtime, {:1.2f}s allowed'.format( runtime, self.time_limit ) ) self.terminated_cause = 'TIME_LIMIT' self.terminated = True self.process.secure_kill() return except AttributeError as e2: pass if self.memory_limit: try: memory_usage = self.process.memory_usage() if memory_usage > self.memory_limit: Printer.out() Printer.err('Error: Memory limit exceeded! {:1.2f}MB used, {:1.2f}MB allowed'.format( memory_usage, self.memory_limit ) ) self.terminated_cause = 'MEMORY_LIMIT' self.terminated = True self.process.secure_kill() return # except NoSuchProcess as e1: # pass except AttributeError as e2: pass
def create_comparisons(self): comparisons = ComparisonMultiThread(self.case.fs.ndiff_log) comparisons.thread_name_property = True for check_rule in self.case.check_rules: method = str(check_rule.keys()[0]) module = getattr(file_comparison, 'Compare{}'.format(method.capitalize()), None) comp_data = check_rule[method] if not module: Printer.err('Warning! No module for check_rule method "{}"', method) continue pairs = self._get_ref_output_files(comp_data) if pairs: for pair in pairs: command = module.get_command(*pair, **comp_data) pm = PyPy(BinExecutor(command), progress=True) # if we fail, set error to 13 pm.custom_error = 13 pm.info_monitor.active = False pm.limit_monitor.active = False pm.progress_monitor.active = False pm.error_monitor.message = 'Error! Comparison using method {} failed!'.format(method) # catch output pm.executor.output = OutputMode.variable_output() pm.full_output = self.case.fs.ndiff_log path = Paths.path_end_until(pair[0], 'ref_output') test_name = Paths.basename(Paths.dirname(Paths.dirname(self.case.fs.ref_output))) size = Paths.filesize(pair[0], True) pm.name = '{}: {} ({})'.format(test_name, path, size) comparisons.add(pm) return comparisons
def do_work(parser, args=None, debug=False): """ :type parser: utils.argparser.ArgParser """ # parse arguments global arg_options, arg_others, arg_rest arg_options, arg_others, arg_rest = parser.parse(args) Paths.format = PathFormat.ABSOLUTE Paths.base_dir('' if not arg_options.root else arg_options.root) # configure printer Printer.batch_output = arg_options.batch Printer.dynamic_output = not arg_options.batch # we need flow123d, mpiexec and ndiff to exists in LOCAL mode if not arg_options.queue and not Paths.test_paths('flow123d', 'mpiexec', 'ndiff'): Printer.err('Missing obligatory files! Exiting') GlobalResult.error = "missing obligatory files" sys.exit(1) # test yaml args if not arg_others: parser.exit_usage('Error: No yaml files or folder given') GlobalResult.error = "no yaml files or folder given" sys.exit(2) all_yamls = list() for path in arg_others: if not Paths.exists(path): Printer.err('Error! given path does not exists, ignoring path "{}"', path) GlobalResult.error = "path does not exist" sys.exit(3) if Paths.is_dir(path): all_yamls.extend(Paths.walk(path, filters=[ PathFilters.filter_type_is_file(), PathFilters.filter_ext('.yaml'), PathFilters.filter_not(PathFilters.filter_name('config.yaml')) ])) else: all_yamls.append(path) Printer.out("Found {} .yaml file/s", len(all_yamls)) if not all_yamls: Printer.wrn('Warning! No yaml files found in locations: \n {}', '\n '.join(arg_others)) GlobalResult.error = "no yaml files or folders given" sys.exit(3) configs = read_configs(all_yamls) configs.update( proc=arg_options.cpu, time_limit=arg_options.time_limit, memory_limit=arg_options.memory_limit, ) if arg_options.queue: Printer.out('Running in PBS mode') return run_pbs_mode(configs, debug) else: Printer.out('Running in LOCAL mode') return run_local_mode(configs, debug)