Example #1
0
    def build_default(deployment_home, cwd, CommandClasses):
        """
        Create a runtime from the command line arguments and configuration on
        disk.

        If you want something more custom, e.g. in testing, you can build
        it yourself ;)
        """

        if len(CommandClasses):
            arg_parser = CommandClasses[0].build_arg_parser()
        else:
            arg_parser = Runtime.__create_placeholder_arg_parser()
        Runtime.add_default_arguments(arg_parser)

        runtime = Runtime()

        for CommandClass in CommandClasses:
            CommandClass.register_services(runtime)

        for ServiceClass in runtime.each_service_class():
            add_default_arguments_method = getattr(ServiceClass,
                                                   'add_default_arguments',
                                                   None)
            if add_default_arguments_method and callable(
                    add_default_arguments_method):
                ServiceClass.add_default_arguments(arg_parser)

        options = arg_parser.parse_args()
        if not hasattr(options, 'deployment_home'):
            options.deployment_home = deployment_home

        config = Config()
        config.set_options(options)
        config.set_cwd(cwd)
        if hasattr(CommandClass, 'DOTFILE_NAME'):
            config.set_dotfile_name(CommandClass.DOTFILE_NAME)

        try:
            config.read()
        except Exception as e:
            if not hasattr(
                    CommandClass,
                    'is_config_required') or CommandClass.is_config_required():
                exc_info = sys.exc_info()
                raise e, None, exc_info[2]

        log = Log()
        log.set_options(options)

        runtime.set_options(options)
        runtime.set_config(config)
        runtime.set_log(log)
        runtime.set_cwd(cwd)

        return runtime
Example #2
0
    def build_default(deployment_home, cwd, CommandClasses):
        """
        Create a runtime from the command line arguments and configuration on
        disk.

        If you want something more custom, e.g. in testing, you can build
        it yourself ;)
        """

        if len(CommandClasses):
            arg_parser = CommandClasses[0].build_arg_parser()
        else:
            arg_parser = Runtime.__create_placeholder_arg_parser()
        Runtime.add_default_arguments(arg_parser)

        runtime = Runtime()

        for CommandClass in CommandClasses:
            CommandClass.register_services(runtime)

        for ServiceClass in runtime.each_service_class():
            add_default_arguments_method = getattr(ServiceClass, 'add_default_arguments', None)
            if add_default_arguments_method and callable(add_default_arguments_method):
                ServiceClass.add_default_arguments(arg_parser)

        options = arg_parser.parse_args()
        if not hasattr(options, 'deployment_home'):
            options.deployment_home = deployment_home

        config = Config()
        config.set_options(options)
        config.set_cwd(cwd)
        if hasattr(CommandClass, 'DOTFILE_NAME'):
            config.set_dotfile_name(CommandClass.DOTFILE_NAME)

        try:
            config.read()
        except Exception as e:
            if not hasattr(CommandClass, 'is_config_required') or CommandClass.is_config_required():
                exc_info = sys.exc_info()
                raise e, None, exc_info[2]

        log = Log()
        log.set_options(options)

        runtime.set_options(options)
        runtime.set_config(config)
        runtime.set_log(log)
        runtime.set_cwd(cwd)

        return runtime