Exemplo n.º 1
0
def main_runner(argv, parser, exe_runner_func,
                level=logging.DEBUG, str_formatter=_LOG_FORMAT):
    """
    Fundamental interface to commandline applications
    """
    started_at = time.time()
    args = parser.parse_args(argv)

    console_or_file = getattr(args, 'log_file', None)

    if hasattr(args, 'log_level'):
        level = getattr(args, 'log_level')

    # Debug will override
    if hasattr(args, 'debug'):
        if args.debug:
            if args.debug is True:
                level = logging.DEBUG

    # Quiet will override everything
    if hasattr(args, 'quiet'):
        if args.quiet:
            level = logging.ERROR

    setup_logger(console_or_file, level, formatter=str_formatter)

    log.debug(args)
    log.info("Starting tool version {v}".format(v=parser.version))

    rcode = exe_runner_func(args)

    run_time = time.time() - started_at
    _d = dict(r=rcode, s=run_time)
    log.info("exiting with return code {r} in {s:.2f} sec.".format(**_d))
    return rcode
Exemplo n.º 2
0
def main_runner(argv, parser, exe_runner_func,
                level=logging.DEBUG, str_formatter=_LOG_FORMAT):
    """
    Fundamental interface to commandline applications
    """

    dep_msg = "The `pbservice` commandline is deprecated and will be removed " \
              "in a future version. Please using the scala implementation in smrtflow " \
              "at https://github.com/PacificBiosciences/smrtflow"

    started_at = time.time()
    args = parser.parse_args(argv)

    level = get_parsed_args_log_level(args, default_level=level)
    console_or_file = args.log_file
    setup_logger(console_or_file, level, formatter=str_formatter)

    log.warn(dep_msg)

    log.debug(args)
    log.info("Starting tool version {v}".format(v=parser.version))

    rcode = exe_runner_func(args)

    run_time = time.time() - started_at
    _d = dict(r=rcode, s=run_time)
    log.info("exiting with return code {r} in {s:.2f} sec.".format(**_d))
    return rcode
Exemplo n.º 3
0
def main_runner(argv, parser, exe_runner_func,
                level=logging.DEBUG, str_formatter=_LOG_FORMAT):
    """
    Fundamental interface to commandline applications
    """

    dep_msg = "The `pbservice` commandline is deprecated and will be removed " \
              "in a future version. Please using the scala implementation in smrtflow " \
              "at https://github.com/PacificBiosciences/smrtflow"

    started_at = time.time()
    args = parser.parse_args(argv)

    level = get_parsed_args_log_level(args, default_level=level)
    console_or_file = args.log_file
    setup_logger(console_or_file, level, formatter=str_formatter)

    warnings.warn(dep_msg, DeprecationWarning)
    log.warn(dep_msg)

    log.debug(args)
    log.info("Starting tool version {v}".format(v=parser.version))

    rcode = exe_runner_func(args)

    run_time = time.time() - started_at
    _d = dict(r=rcode, s=run_time)
    log.info("exiting with return code {r} in {s:.2f} sec.".format(**_d))
    return rcode
Exemplo n.º 4
0
def _args_run_butler(args):

    butler = B.config_parser_to_butler(args.testkit_cfg)

    test_cases = L.parse_cfg_file(args.testkit_cfg)

    if not os.path.exists(butler.output_dir):
        os.mkdir(butler.output_dir)

    output_xml = args.output_xml
    if output_xml is None:
        output_xml = os.path.join(butler.output_dir, 'testkit_xunit.xml')

    if args.log_file is None:
        log_file = os.path.join(butler.output_dir, 'testkit.log')
    else:
        log_file = args.log_file

    force_distribute, force_chunk = resolve_dist_chunk_overrides(args)

    log_level = args.log_level

    # Short hand for --log-level=DEBUG
    if args.debug:
        log_level = logging.DEBUG

    if log_level == logging.DEBUG:
        # The logger isn't setup yet
        print "Args", args

    if args.only_tests:
        # in test only mode, only emit to stdout (to avoid overwritten the
        # log file
        setup_logger(None, level=log_level)
        return run_butler_tests(test_cases, butler.output_dir, output_xml,
                                butler.job_id, butler.requirements)
    else:
        rcode = run_butler(butler,
                           test_cases,
                           output_xml,
                           log_file,
                           log_level=log_level,
                           force_distribute=force_distribute,
                           force_chunk=force_chunk,
                           ignore_test_failures=args.ignore_test_failures)
        return rcode
Exemplo n.º 5
0
    def _w(args):

        started_at = time.time()

        def run_time():
            return time.time() - started_at

        def exit_msg(rcode_):
            return "Completed running {r} exitcode {e} in {t:.2f} sec.".format(
                r=rtc, e=rcode_, t=run_time())

        level = get_parsed_args_log_level(args)
        setup_logger(None, level=level)

        log.info("Loading pbcommand {v}".format(v=pbcommand.get_version()))
        log.info("Registry {r}".format(r=registry))
        log.info("Setting log-level to {d}".format(d=level))
        log.debug("args {a}".format(a=args))
        log.info("loading RTC from {i}".format(i=args.rtc_path))
        rtc = load_resolved_tool_contract_from(args.rtc_path)
        id_funcs = {
            t.task.task_id: func
            for t, func in registry.rtc_runners.iteritems()
        }
        func = id_funcs.get(rtc.task.task_id, None)
        if func is None:
            rcode = 1
            log.error(
                "Unknown tool contract id '{x}' Registered TC ids {i}".format(
                    x=rtc.task.task_id, i=id_funcs.keys()))
            log.error(exit_msg(rcode))
            return rcode
        else:
            log.info("Running id:{i} Resolved Tool Contract {r}".format(
                r=rtc, i=rtc.task.task_id))
            log.info("Runner func {f}".format(f=func))
            exit_code = func(rtc)
            if exit_code == 0:
                log.info(exit_msg(exit_code))
            else:
                log.error(exit_msg(exit_code))

            return exit_code
Exemplo n.º 6
0
def _args_run_butler(args):

    butler = B.config_parser_to_butler(args.testkit_cfg)

    test_cases = L.parse_cfg_file(args.testkit_cfg)

    if not os.path.exists(butler.output_dir):
        os.mkdir(butler.output_dir)

    output_xml = args.output_xml
    if output_xml is None:
        output_xml = os.path.join(butler.output_dir, 'testkit_xunit.xml')

    if args.log_file is None:
        log_file = os.path.join(butler.output_dir, 'testkit.log')
    else:
        log_file = args.log_file

    force_distribute, force_chunk = resolve_dist_chunk_overrides(args)

    log_level = args.log_level

    # Short hand for --log-level=DEBUG
    if args.debug:
        log_level = logging.DEBUG

    if log_level == logging.DEBUG:
        # The logger isn't setup yet
        print "Args", args

    if args.only_tests:
        # in test only mode, only emit to stdout (to avoid overwritten the
        # log file
        setup_logger(None, level=log_level)
        return run_butler_tests(test_cases, butler.output_dir, output_xml, butler.job_id)
    else:
        rcode = run_butler(butler, test_cases, output_xml, log_file,
                           log_level=log_level,
                           force_distribute=force_distribute,
                           force_chunk=force_chunk,
                           ignore_test_failures=args.ignore_test_failures)
        return rcode
Exemplo n.º 7
0
def main_runner(argv, parser, exe_runner_func,
                level=logging.DEBUG, str_formatter=_LOG_FORMAT):
    """
    Fundamental interface to commandline applications
    """
    started_at = time.time()
    args = parser.parse_args(argv)

    level = get_parsed_args_log_level(args, default_level=level)
    console_or_file = args.log_file
    setup_logger(console_or_file, level, formatter=str_formatter)

    log.debug(args)
    log.info("Starting tool version {v}".format(v=parser.version))

    rcode = exe_runner_func(args)

    run_time = time.time() - started_at
    _d = dict(r=rcode, s=run_time)
    log.info("exiting with return code {r} in {s:.2f} sec.".format(**_d))
    return rcode
Exemplo n.º 8
0
    def _w(args):

        started_at = time.time()

        def run_time():
            return time.time() - started_at

        def exit_msg(rcode_):
            return "Completed running {r} exitcode {e} in {t:.2f} sec.".format(r=rtc, e=rcode_, t=run_time())

        level = get_parsed_args_log_level(args)
        setup_logger(None, level=level)

        log.info("Loading pbcommand {v}".format(v=pbcommand.get_version()))
        log.info("Registry {r}".format(r=registry))
        log.info("Setting log-level to {d}".format(d=level))
        log.debug("args {a}".format(a=args))
        log.info("loading RTC from {i}".format(i=args.rtc_path))
        rtc = load_resolved_tool_contract_from(args.rtc_path)
        id_funcs = {t.task.task_id: func for t, func in registry.rtc_runners.iteritems()}
        func = id_funcs.get(rtc.task.task_id, None)
        if func is None:
            rcode = 1
            log.error("Unknown tool contract id '{x}' Registered TC ids {i}".format(x=rtc.task.task_id, i=id_funcs.keys()))
            log.error(exit_msg(rcode))
            return rcode
        else:
            log.info("Running id:{i} Resolved Tool Contract {r}".format(r=rtc, i=rtc.task.task_id))
            log.info("Runner func {f}".format(f=func))
            exit_code = func(rtc)
            if exit_code == 0:
                log.info(exit_msg(exit_code))
            else:
                log.error(exit_msg(exit_code))

            return exit_code
Exemplo n.º 9
0
def main_runner(argv,
                parser,
                exe_runner_func,
                level=logging.DEBUG,
                str_formatter=_LOG_FORMAT):
    """
    Fundamental interface to commandline applications
    """
    started_at = time.time()
    args = parser.parse_args(argv)

    level = get_parsed_args_log_level(args, default_level=level)
    console_or_file = args.log_file
    setup_logger(console_or_file, level, formatter=str_formatter)

    log.debug(args)
    log.info("Starting tool version {v}".format(v=parser.version))

    rcode = exe_runner_func(args)

    run_time = time.time() - started_at
    _d = dict(r=rcode, s=run_time)
    log.info("exiting with return code {r} in {s:.2f} sec.".format(**_d))
    return rcode