Exemplo n.º 1
0
def run_cmd_in_context(cmd_klass, cmd_name, cmd_argv, context_klass, run_node, top_node, package):
    """Run the given Command instance inside its context, including any hook
    and/or override."""
    package_options = PackageOptions.from_file(BENTO_SCRIPT)

    cmd = cmd_klass()
    options_context = OptionsContext.from_command(cmd)
    _setup_options_parser(options_context, package_options)

    context = context_klass(cmd_argv, options_context, package, run_node)
    # FIXME: hack to pass package_options to configure command - most likely
    # this needs to be known in option context ?
    context.package_options = package_options

    if get_command_override(cmd_name):
        cmd_funcs = get_command_override(cmd_name)
    else:
        cmd_funcs = [(cmd.run, top_node.abspath())]

    try:
        def _run_hooks(hook_iter):
            for hook, local_dir, help_bypass in hook_iter:
                local_node = top_node.find_dir(relpath(local_dir, top_node.abspath()))
                context.pre_recurse(local_node)
                try:
                    if not context.help:
                        hook(context)
                finally:
                    context.post_recurse()

        _run_hooks(get_pre_hooks(cmd_name))

        while cmd_funcs:
            cmd_func, local_dir = cmd_funcs.pop(0)
            local_node = top_node.find_dir(relpath(local_dir, top_node.abspath()))
            context.pre_recurse(local_node)
            try:
                cmd_func(context)
            finally:
                context.post_recurse()

        _run_hooks(get_post_hooks(cmd_name))

        cmd.shutdown(context)
    finally:
        context.shutdown()

    return cmd, context
Exemplo n.º 2
0
 def _big_ugly_hack():
     # FIXME: huge ugly hack - we need to specify once and for all when the
     # package info is parsed and available, so that we can define options
     # and co for commands
     from bento.commands.configure import _setup_options_parser
     # FIXME: logic to handle codepaths which work without a bento.info
     # should be put in one place
     n = top_node.find_node(BENTO_SCRIPT)
     if n:
         package_options = __get_package_options(top_node)
         _setup_options_parser(OPTIONS_REGISTRY.retrieve("configure"), package_options)
     else:
         import warnings
         warnings.warn("No %r file in current directory - not all options "
                       "will be displayed" % BENTO_SCRIPT)
         return
Exemplo n.º 3
0
def global_context_factory(package_options):
    # FIXME: factor this out with the similar code in bentomakerlib
    options_registry = OptionsRegistry()
    # This is a dummy for now, to fulfill global_context API
    cmd_scheduler = CommandScheduler()
    commands_registry = CommandRegistry()
    register_commands(commands_registry)
    register_command_contexts()
    for cmd_name in commands_registry.command_names():
        if not options_registry.is_registered(cmd_name):
            cmd = commands_registry.retrieve(cmd_name)
            options_context = OptionsContext.from_command(cmd)
            options_registry.register(cmd_name, options_context)

    configure_options_context = options_registry.retrieve("configure")
    _setup_options_parser(configure_options_context, package_options)
    global_context = GlobalContext(commands_registry, CONTEXT_REGISTRY,
                                   options_registry, cmd_scheduler)
    return global_context
Exemplo n.º 4
0
def prepare_configure(run_node, bento_info, context_klass=ConfigureYakuContext, cmd_argv=None):
    if cmd_argv is None:
        cmd_argv = []

    top_node = run_node._ctx.srcnode
    top_node.make_node("bento.info").safe_write(bento_info)

    package = PackageDescription.from_string(bento_info)
    package_options = PackageOptions.from_string(bento_info)

    configure = ConfigureCommand()
    opts = OptionsContext.from_command(configure)

    # FIXME: this emulates the big ugly hack inside bentomaker.
    _setup_options_parser(opts, package_options)

    context = context_klass(None, cmd_argv, opts, package, run_node)
    context.package_options = package_options

    return context, configure