def on_complete(self, pypy=None):
        if pypy.executor.broken:
            return

        if self.log_file:
            IO.write(self.log_file, self.content)

        enabled = False
        if self.policy == self.POLICY_ALWAYS:
            enabled = True
        elif self.policy == self.POLICY_BATCH_OR_ERROR:
            enabled = pypy.with_error() or (not Printer.batched.is_muted())
        elif self.policy == self.POLICY_ERROR_ONLY:
            enabled = pypy.with_error()

        if enabled:
            with Printer.all.with_level():

                if self.pypy.full_output:
                    Printer.all.sep()
                    Printer.all.out(
                        'Output from file {self.pypy.full_output}'.format(
                            **locals()))

                if not Printer.batched.is_muted():
                    Printer.batched.raw(
                        format_n_lines(self.content, pypy.was_successful()))

                if not Printer.console.is_muted():
                    Printer.console.raw(
                        format_n_lines(self.content, pypy.was_successful()))
示例#2
0
    def on_complete(self, pypy=None):
        if pypy.executor.broken:
            return

        if self.log_file:
            IO.write(self.log_file, self.content)

        enabled = False
        if self.policy == self.POLICY_ALWAYS:
            enabled = True
        elif self.policy == self.POLICY_BATCH_OR_ERROR:
            enabled = pypy.with_error() or (not Printer.batched.is_muted())
        elif self.policy == self.POLICY_ERROR_ONLY:
            enabled = pypy.with_error()

        if enabled:
            with Printer.all.with_level():

                if self.pypy.full_output:
                    Printer.all.sep()
                    Printer.all.out('Output from file {self.pypy.full_output}'.format(**locals()))

                if not Printer.batched.is_muted():
                    Printer.batched.raw(format_n_lines(self.content, pypy.was_successful()))

                if not Printer.console.is_muted():
                    Printer.console.raw(format_n_lines(self.content, pypy.was_successful()))
示例#3
0
文件: job.py 项目: jbrezmorf/flow123d
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
示例#4
0
文件: job.py 项目: jbrezmorf/flow123d
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
示例#5
0
    def on_complete(self, pypy=None):

        if self.log_file:
            IO.write(self.log_file, self.content)

        # finish after update
        if self.update_format and (not self.complete_format
                                   and not self.color_complete_format):
            printf.finish_rewrite()

        # print regular messages
        for fmt in ensure_iterable(self.complete_format):
            printf.out(fmt, monitor=self)

        # print messages if error
        if self.pypy.with_error():
            for fmt in ensure_iterable(self.error_complete_format):
                printf.error(fmt, monitor=self)

        # print regular color messages based on result
        for fmt in ensure_iterable(self.color_complete_format):
            if self.pypy.returncode() == 0:
                printf.success(fmt, monitor=self)
            elif self.pypy.returncode() is None:
                printf.warning(fmt, monitor=self)
            else:
                printf.error(fmt, monitor=self)

        with printf:
            if printf.verbosity() is printf.OutputVerbosity.FULL:
                printf.sep()
                printf.out('Output from file {self.pypy.full_output}'.format(
                    **locals()))
                printf.opt(raw=True).stream(
                    format_n_lines(self.content, pypy.was_successful()))
            elif printf.verbosity(
            ) is printf.OutputVerbosity.SMART and pypy.with_error():
                printf.sep()
                printf.out(
                    'Last 50 lines from file {self.pypy.full_output}'.format(
                        **locals()))
                printf.opt(raw=True).stream(
                    format_n_lines(self.content, success=False, n_lines=-50))
            elif printf.verbosity(
            ) is printf.OutputVerbosity.MINIMAL and pypy.with_error():
                printf.sep()
                printf.out(
                    'Last 50 lines from file {self.pypy.full_output}'.format(
                        **locals()))
                printf.opt(raw=True).stream(
                    format_n_lines(self.content, success=False, n_lines=-50))
示例#6
0
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
示例#7
0
    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))
示例#8
0
    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 * '    '))
示例#9
0
    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 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 run_local_mode_one(proc, time_limit, memory_limit):
    if proc == 0:
        command = arg_rest[1:]
    else:
        command = [arg_rest[0], '-np', proc] + arg_rest[1:]

    n_lines = 0 if arg_options.batch else 10
    pypy = PyPy(BinExecutor(command))

    # set limits
    pypy.limit_monitor.time_limit = time_limit
    pypy.limit_monitor.memory_limit = memory_limit
    pypy.progress = not arg_options.batch
    pypy.info_monitor.deactivate()
    pypy.error_monitor.deactivate()

    # catch output to variable
    # in batch mode we will keep the files
    # otherwise we will keep logs only on error
    log_file = Paths.temp_file('exec-parallel-{date}-{time}-{rnd}.log')
    pypy.executor.output = OutputMode.variable_output()
    pypy.full_output = log_file

    # start and wait for exit
    pypy.start()
    pypy.join()

    # add result to global json result
    GlobalResult.add(pypy)

    # in batch mode or on error
    if not pypy.with_success() or arg_options.batch:
        content = pypy.executor.output.read()
        IO.write(log_file, content)
        Printer.close()
        Printer.out(format_n_lines(content, indent='    ', n_lines=-n_lines))
        Printer.open()
    return pypy
示例#12
0
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