def compare(self, reference_filepath, other_filepath, **kwargs): """ Method can do anything as long as int value is returned :param reference_filepath: :param other_filepath: :param kwargs: :return: """ reference_content = IO.read( Paths.abspath(reference_filepath) ) other_content = IO.read( Paths.abspath(other_filepath) ) self.output.write("In case of emergency,") self.output.write(" you can provide details on what went wrong") self.output.write(" using self.output.write method") self.output.write("") self.output.write("Error while comparing files \n{} \n{}" .format(reference_filepath, other_filepath)) # must return return-code! return 1
def finish_pbs_exec(job, batch): """ Upon PBS finish determine Job exit :rtype: scripts.serialization.PyPyResult :type job: scripts.pbs.job.Job """ job.is_active = False try: result = load_pypy(job.case.fs.dump_output) except Exception as e: # no output file was generated assuming it went wrong job.status = JobState.EXIT_ERROR Printer.all.err('Job {} ended (no output file found). Case: {}', job, job.full_name) Printer.all.out(' pbs output: ') Printer.all.raw(format_n_lines(IO.read(job.case.fs.pbs_output), False)) return # check result if result.returncode == 0: job.status = JobState.EXIT_OK Printer.all.suc('Job {}({}) ended', job, job.full_name) else: job.status = JobState.EXIT_ERROR Printer.all.err('Job {}({}) ended', job, job.full_name) if result.returncode != 0 or batch: with Printer.all.with_level(1): Printer.all.raw(format_n_lines(IO.read(result.output), result.returncode == 0)) return result
def finish_pbs_runtest(job, batch): """ Upon PBS runtest finish determine Job exit :type job: scripts.pbs.job.Job :rtype: ResultParallelThreads """ job.is_active = False try: runner = load_runtest(job.case.fs.dump_output) except: # no output file was generated assuming it went wrong job.status = JobState.EXIT_ERROR Printer.all.err('Job {} ended (no output file found). Case: {}', job, job.full_name) Printer.all.out(' pbs output: ') Printer.all.raw(format_n_lines(IO.read(job.case.fs.pbs_output), False)) return job.status = JobState.EXIT_OK if runner.returncode == 0 else JobState.EXIT_ERROR for thread in runner.threads: StatusPrinter.print_test_result(thread) if thread.returncode != 0 or batch: with Printer.all.with_level(): Printer.all.out('Log file {}', job.case.fs.job_output) Printer.all.raw(format_n_lines(IO.read(job.case.fs.job_output), thread.returncode == 0)) # print status line only if pbs job container more cases if len(runner.threads) > 1: Printer.all.sep() StatusPrinter.print_runner_stat(runner) Printer.all.sep() return runner
def finish_pbs_exec(job, batch): """ Upon PBS finish determine Job exit :rtype: scripts.serialization.PyPyResult :type job: scripts.pbs.job.Job """ job.is_active = False try: result = load_pypy(job.case.fs.dump_output) except Exception as e: # no output file was generated assuming it went wrong job.status = JobState.EXIT_ERROR Printer.all.err('Job {} ended (no output file found). Case: {}', job, job.full_name) Printer.all.out(' pbs output: ') Printer.all.raw(format_n_lines(IO.read(job.case.fs.pbs_output), False)) return # check result if result.returncode == 0: job.status = JobState.EXIT_OK Printer.all.suc('Job {}({}) ended', job, job.full_name) else: job.status = JobState.EXIT_ERROR Printer.all.err('Job {}({}) ended', job, job.full_name) if result.returncode != 0 or batch: with Printer.all.with_level(1): Printer.all.raw( format_n_lines(IO.read(result.output), result.returncode == 0)) return result
def read(self): if self.mode is self.DUMMY: return self.content if self.filename: if self.content is None: self.content = IO.read(self.filename) return self.content
def print_log_file(cls, f, n_lines): log_file = IO.read(f) if log_file: if n_lines == 0: printf.out('Full log from file {}:', f) else: printf.out('Last {} lines from file {}:', abs(n_lines), f) printf.stream(format_n_lines(log_file.rstrip(), -n_lines))
def print_log_file(cls, f, n_lines): log_file = IO.read(f) if log_file: if n_lines == 0: Printer.out('Full log from file {}:', f) else: Printer.out('Last {} lines from file {}:', abs(n_lines), f) Printer.wrn(format_n_lines(log_file.rstrip(), -n_lines, indent=Printer.indent * ' '))
def print_log_file(cls, f, n_lines): log_file = IO.read(f) if log_file: if n_lines == 0: Printer.out('Full log from file {}:', f) else: Printer.out('Last {} lines from file {}:', abs(n_lines), f) Printer.wrn( format_n_lines(log_file.rstrip(), -n_lines, indent=Printer.indent * ' '))
def close(self): if self.mode in {self.WRITE, self.APPEND, self.VARIABLE}: if self.fp is not None: if type(self.fp) is int: os.close(self.fp) else: self.fp.close() self.fp = None # remove temp file if self.mode in {self.VARIABLE}: self.content = IO.read(self.filename) os.unlink(self.filename)
def finish_pbs_job(job, batch): """ :type job: scripts.pbs.job.Job """ # try to get more detailed job status job.is_active = False job_output = IO.read(job.case.fs.json_output) if job_output: job_json = JsonParser(json.loads(job_output), batch) if job_json.returncode == 0: job.status = JobState.EXIT_OK Printer.out('OK: Job {}({}) ended', job, job.full_name) Printer.open() # in batch mode print all logs if batch: Printer.open() for test in job_json.tests: test.get_result() Printer.close() Printer.close() else: job.status = JobState.EXIT_ERROR Printer.out('ERROR: Job {}({}) ended', job, job.full_name) # in batch mode print all logs Printer.open() for test in job_json.tests: test.get_result() Printer.close() else: # no output file was generated assuming it went wrong job.status = JobState.EXIT_ERROR Printer.out('ERROR: Job {} ended (no output file found). Case: {}', job, job.full_name) Printer.out(' pbs output: ') Printer.out(format_n_lines(IO.read(job.case.fs.pbs_output), 0)) return 0 if job.status == JobState.EXIT_OK else 1
def close(self): if self.mode is self.DUMMY: return if self.mode in {self.WRITE, self.APPEND, self.VARIABLE}: if self.fp is not None: if type(self.fp) is int: os.close(self.fp) else: self.fp.close() self.fp = None # remove temp file if self.mode in {self.VARIABLE}: self.content = IO.read(self.filename) os.unlink(self.filename)
def compare(self, reference_filepath, other_filepath, **kwargs): """ Method can do anything as long as int value is returned :param reference_filepath: :param other_filepath: :param kwargs: :return: """ regex = kwargs.get('regex', None) substr = kwargs.get('substr', None) if regex is None and substr is None: self.output.write( "Invalid check rule! Specify either 'regex' or 'substr' keyword." ) return 1 # convert to str or compile to regex if substr is not None: substr = str(substr) if regex is not None: regex = re.compile(str(regex)) # for regex comparison we ignore reference file # read job_output.log content = IO.read(Paths.abspath(other_filepath)) # substr find if substr: found = False for line in content.splitlines(): if line.find(substr) != -1: found = True self.output.write( '[OK] Found substr "{substr}" in line:'.format( **locals())) self.output.write(' ' + line) break if not found: self.output.write( '[ERROR] Could not find substr "{substr}":'.format( **locals())) return 1 # regex match if regex: found = False for line in content.splitlines(): if regex.findall(line): found = True self.output.write( '[OK] Found regex "{regex.pattern}" in line:'.format( **locals())) self.output.write(' ' + line) break if not found: self.output.write( '[ERROR] Could not find regex {regex.pattern}:'.format( **locals())) return 1 # self.output.write("In case of emergency,") # self.output.write(" you can provide details on what went wrong") # self.output.write(" using self.output.write method") # self.output.write("") # self.output.write("Error while comparing files \n{} \n{}" # .format(reference_filepath, other_filepath)) # must return return-code! return 0
def read(self): if self.filename: if self.content is None: self.content = IO.read(self.filename) return self.content