Exemplo n.º 1
0
Arquivo: main.py Projeto: lge/crmsh
def do_work(context, user_args):
    compatibility_setup()
    rc = handle_noninteractive_use(context, user_args)
    if rc is not None:
        return rc

    setup_context(context)

    rc = 0
    while True:
        try:
            inp = utils.multi_input(render_prompt(context))
            if inp is None:
                if options.interactive:
                    rc = 0
                context.quit(rc)
            try:
                if not context.run(inp):
                    rc = 1
            except ValueError, msg:
                rc = 1
                common_err(msg)
        except KeyboardInterrupt:
            if options.interactive and not options.batch:
                print "Ctrl-C, leaving"
            context.quit(1)
    return rc
Exemplo n.º 2
0
def do_work(context, user_args):
    compatibility_setup()
    rc = handle_noninteractive_use(context, user_args)
    if rc is not None:
        return rc

    setup_context(context)

    rc = 0
    while True:
        try:
            inp = utils.multi_input(render_prompt(context))
            if inp is None:
                if options.interactive:
                    rc = 0
                context.quit(rc)
            try:
                if not context.run(inp):
                    rc = 1
            except ValueError, msg:
                rc = 1
                common_err(msg)
        except KeyboardInterrupt:
            if options.interactive and not options.batch:
                print "Ctrl-C, leaving"
            context.quit(1)
    return rc
Exemplo n.º 3
0
Arquivo: main.py Projeto: lge/crmsh
def load_rc(context, rcfile):
    # only load the RC file if there is no new-style user config
    if config.has_user_config():
        return

    try:
        f = open(rcfile)
    except:
        return
    save_stdin = sys.stdin
    sys.stdin = f
    while True:
        inp = utils.multi_input()
        if inp is None:
            break
        try:
            if not context.run(inp):
                raise ValueError("Error in RC file: " + rcfile)
        except ValueError, msg:
            common_err(msg)
Exemplo n.º 4
0
def load_rc(context, rcfile):
    # only load the RC file if there is no new-style user config
    if config.has_user_config():
        return

    try:
        f = open(rcfile)
    except:
        return
    save_stdin = sys.stdin
    sys.stdin = f
    while True:
        inp = utils.multi_input()
        if inp is None:
            break
        try:
            if not context.run(inp):
                raise ValueError("Error in RC file: " + rcfile)
        except ValueError, msg:
            common_err(msg)
Exemplo n.º 5
0
        context.setup_readline()

    rc = 0
    while True:
        try:
            if options.interactive and not options.batch:
                # TODO: fix how color interacts with readline,
                # seems the color prompt messes it up
                termctrl = TerminalController.getInstance()
                cli_display = CliDisplay.getInstance()
                promptstr = "crm(%s)%s# " % (cib_prompt(), context.prompt())
                if cli_display.colors_enabled():
                    vars.prompt = termctrl.render(cli_display.prompt(promptstr))
                else:
                    vars.prompt = promptstr
            inp = utils.multi_input(vars.prompt)
            if inp is None:
                if options.interactive:
                    rc = 0
                context.quit(rc)
            try:
                if not context.run(inp):
                    rc = 1
            except ValueError, msg:
                rc = 1
                common_err(msg)
        except KeyboardInterrupt:
            if options.interactive and not options.batch:
                print "Ctrl-C, leaving"
            context.quit(1)
    return rc
Exemplo n.º 6
0
        context.setup_readline()

    rc = 0
    while True:
        try:
            rendered_prompt = constants.prompt
            if options.interactive and not options.batch:
                # TODO: fix how color interacts with readline,
                # seems the color prompt messes it up
                promptstr = "crm(%s)%s# " % (cib_prompt(), context.prompt())
                constants.prompt = promptstr
                if clidisplay.colors_enabled():
                    rendered_prompt = term.render(clidisplay.prompt(promptstr))
                else:
                    rendered_prompt = promptstr
            inp = utils.multi_input(rendered_prompt)
            if inp is None:
                if options.interactive:
                    rc = 0
                context.quit(rc)
            try:
                if not context.run(inp):
                    rc = 1
            except ValueError, msg:
                rc = 1
                common_err(msg)
        except KeyboardInterrupt:
            if options.interactive and not options.batch:
                print "Ctrl-C, leaving"
            context.quit(1)
    return rc