Ejemplo n.º 1
0
Archivo: main.py Proyecto: mmilata/osbs
def main():
    parser, args = cli()
    os_conf = Configuration(conf_file=args.config, conf_section=args.config_section, cli_args=args)
    build_conf = Configuration(conf_file=args.config, conf_section=args.config_section, cli_args=args)

    if os_conf.get_verbosity():
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    elif args.quiet:
        set_logging(level=logging.WARNING)
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    try:
        args.func(args, osbs)
    except AttributeError as ex:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        pass
    except HTTPError as ex:
        logger.error("HTTP error: %d", ex.getcode())
    except Exception as ex:
        if args.verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
Ejemplo n.º 2
0
def main():
    parser, args = cli()
    try:
        os_conf = Configuration(conf_file=args.config,
                                conf_section=args.instance,
                                cli_args=args)
        build_conf = Configuration(conf_file=args.config,
                                   conf_section=args.instance,
                                   cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    elif args.quiet:
        set_logging(level=logging.WARNING)
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    try:
        args.func(args, osbs)
    except AttributeError as ex:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s",
                         ex.url, ex.status_code, ex.message)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
Ejemplo n.º 3
0
def main():
    parser, args = cli()
    try:
        os_conf = Configuration(conf_file=args.config,
                                conf_section=args.instance,
                                cli_args=args)
        build_conf = Configuration(conf_file=args.config,
                                   conf_section=args.instance,
                                   cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if args.quiet:
        set_logging(level=logging.WARNING)
    elif is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    if args.capture_dir is not None:
        setup_json_capture(osbs, os_conf, args.capture_dir)

    try:
        args.func(args, osbs)
    except AttributeError as ex:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s", ex.url,
                         ex.status_code, ex.message)
            return -1
    except OsbsAuthException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Authentication failure: %s", ex.message)
            return -1
    except OsbsResponseException as ex:
        if is_verbose:
            raise
        else:
            if isinstance(ex.json, dict) and 'message' in ex.json:
                msg = ex.json['message']
            else:
                msg = ex.message
            logger.error("Server returned error %s: %s", ex.status_code, msg)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
Ejemplo n.º 4
0
def main():
    parser, args = cli()
    # OSBS2 TBD if we remove setup_json_capture, we can just create configuration without instance
    # as verbosity is read from general section
    # also we could even just read verbosity from args and create configurations only in
    # cmd functions
    try:
        if args.instance:
            os_conf = Configuration(conf_file=args.config,
                                    conf_section=args.instance,
                                    cli_args=args)
        else:
            os_conf = Configuration(conf_file=args.config, cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if args.quiet:
        set_logging(level=logging.WARNING)
    elif is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    else:
        set_logging(level=logging.INFO)

    # required just for setup_json_capture, if we don't need it anymore we could just remove it
    # OSBS2 TBD
    osbs = OSBS(os_conf)

    if args.capture_dir is not None:
        setup_json_capture(osbs, os_conf, args.capture_dir)

    return_value = -1
    try:
        # OSBS2 TBD
        # this breaks all other commands which require 2nd osbs arg, which have to be cleaned,
        # also if we will still use some, like login/token, we would have to require
        # instance name, as we can't choose default since we have now 2 defaults
        # one for binary and another for source
        return_value = args.func(args)
    except AttributeError:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s", ex.url,
                         ex.status_code, ex)
            return -1
    except OsbsAuthException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Authentication failure: %s", ex)
            return -1
    except OsbsResponseException as ex:
        if is_verbose:
            raise
        else:
            if isinstance(ex.json, dict) and 'message' in ex.json:
                msg = ex.json['message']
            else:
                msg = str(ex)
            logger.error("Server returned error %s: %s", ex.status_code, msg)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1
    return return_value
Ejemplo n.º 5
0
def main():
    parser, args = cli()
    try:
        os_conf = Configuration(conf_file=args.config,
                                conf_section=args.instance,
                                cli_args=args)
        build_conf = Configuration(conf_file=args.config,
                                   conf_section=args.instance,
                                   cli_args=args)
    except OsbsException as ex:
        logger.error("Configuration error: %s", ex.message)
        return -1

    is_verbose = os_conf.get_verbosity()

    if args.quiet:
        set_logging(level=logging.WARNING)
    elif is_verbose:
        set_logging(level=logging.DEBUG)
        logger.debug("Logging level set to debug")
    else:
        set_logging(level=logging.INFO)

    osbs = OSBS(os_conf, build_conf)

    if args.capture_dir is not None:
        setup_json_capture(osbs, os_conf, args.capture_dir)

    try:
        args.func(args, osbs)
    except AttributeError as ex:
        if hasattr(args, 'func'):
            raise
        else:
            parser.print_help()
    except KeyboardInterrupt:
        print("Quitting on user request.")
        return -1
    except OsbsNetworkException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Network error at %s (%d): %s",
                         ex.url, ex.status_code, ex.message)
            return -1
    except OsbsAuthException as ex:
        if is_verbose:
            raise
        else:
            logger.error("Authentication failure: %s",
                         ex.message)
            return -1
    except OsbsResponseException as ex:
        if is_verbose:
            raise
        else:
            if isinstance(ex.json, dict) and 'message' in ex.json:
                msg = ex.json['message']
            else:
                msg = ex.message
            logger.error("Server returned error %s: %s", ex.status_code, msg)
            return -1
    except Exception as ex:  # pylint: disable=broad-except
        if is_verbose:
            raise
        else:
            logger.error("Exception caught: %s", repr(ex))
            return -1