Пример #1
0
    def _run(self, config, cmd_options, cmd_args):
        self._require_args(cmd_args, 0, 0)
        require_box(config)

        box_name = '(%s)' % config.box.name
        shell_prompt = r'\[\033[01;31m\]%(box_name)s\[\033[01;32m\] \u@\h\[\033[01;34m\] \w \$\[\033[00m\] ' % locals()

        cur_box = get_current_box()
        if cur_box and cur_box == config.box:
            # Already inside the box env, just execute a shell with the new prompt
            new_env = dict(os.environ)
            new_env['PS1'] = shell_prompt
            call(['bash', '-norc', '-noprofile'], env=new_env)
        else:
            # Have to set the correct environment, so execute a shell using the env script
            # XXX(ot): does this spawn two bashs?
            call(['bash', config.box.env_script, 'PS1="%s"' % shell_prompt, 'bash', '-norc', '-noprofile'])
Пример #2
0
    def _run(self, config, cmd_options, cmd_args):
        self._require_args(cmd_args, 0, 0)
        require_box(config)

        box_name = '(%s)' % config.box.name
        shell_prompt = r'\[\033[01;31m\]%(box_name)s\[\033[01;32m\] \u@\h\[\033[01;34m\] \w \$\[\033[00m\] ' % locals(
        )

        cur_box = get_current_box()
        if cur_box and cur_box == config.box:
            # Already inside the box env, just execute a shell with the new prompt
            new_env = dict(os.environ)
            new_env['PS1'] = shell_prompt
            call(['bash', '-norc', '-noprofile'], env=new_env)
        else:
            # Have to set the correct environment, so execute a shell using the env script
            # XXX(ot): does this spawn two bashs?
            call([
                'bash', config.box.env_script,
                'PS1="%s"' % shell_prompt, 'bash', '-norc', '-noprofile'
            ])
Пример #3
0
def main(argv, do_log=True):
    # set up default logging 
    # TODO(giuott): Add a verbosity option
    if do_log:
        logging.basicConfig()
        log.setLevel(logging.INFO)
    
    try:
        parser = setup_optparse()
        options, args = parser.parse_args(argv[1:])
    except ParserExit:
        return 0
    
    if not args:
        parser.print_help()
        return 255

    command = args[0]
    cmd_args = args[1:]
    config = Config()

    try:
        if options.box_path is not None:
            config.box = Box(options.box_path)
        else:
            config.box = get_current_box()
            if config.box is not None:
                log.info('Using current box "%s"', config.box.name)

        return ui.command.dispatch(command, config, cmd_args)
    except ui.command.CommandNotFound:
        log.error("Command %s not found", command)
        parser.print_help()
        return 255
    except bpt.UserError, exc:
        log.error('Aborting: %s', str(exc))
        return 1