From aac3ab2b4b6958f9fdd05c0f7de58d2be30cb6b3 Mon Sep 17 00:00:00 2001 From: Seblu Date: Mon, 3 Jan 2011 15:12:26 +0100 Subject: [PATCH] command expert --- bin/cc-cli | 4 ++-- cccli/cli.py | 2 +- cccli/command.py | 16 ++++++++++++++++ cccli/printer.py | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bin/cc-cli b/bin/cc-cli index a47e380..995bad1 100755 --- a/bin/cc-cli +++ b/bin/cc-cli @@ -135,10 +135,10 @@ try: except BadArgument as e: printer.error("Bad Argument: %s"%str(e)) oparser.print_help() -except cliError as e: - printer.error(str(e)) except KeyboardInterrupt: exit(1) +except cliError as e: + printer.error(str(e)) except Exception as e: if cccli.debug: printer.fatal(str(e), quit=False) diff --git a/cccli/cli.py b/cccli/cli.py index 33601e9..4b73985 100644 --- a/cccli/cli.py +++ b/cccli/cli.py @@ -18,7 +18,7 @@ from cccli.printer import Printer, color from cccli.exception import * from sjrpc.client import SimpleRpcClient -from sjrpc.utils import RpcHandler, ConnectionProxy, pure +from sjrpc.utils import RpcHandler, pure from sjrpc.core.exceptions import * class Cli(object): diff --git a/cccli/command.py b/cccli/command.py index db4ceaf..35480c5 100644 --- a/cccli/command.py +++ b/cccli/command.py @@ -10,6 +10,7 @@ import sys import re import pprint import ConfigParser +import code from optparse import OptionParser import cccli @@ -17,6 +18,7 @@ from cccli.exception import * from cccli.printer import color from sjrpc.client import SimpleRpcClient +from sjrpc.utils import ConnectionProxy from sjrpc.core.exceptions import * class Command(object): @@ -367,6 +369,20 @@ class Command(object): raise cmdError("RPCError: %s"%str(e)) cmd_passwd.usage = "passwd [password]" + def cmd_expert(self, argv): + '''Switch in expert mode''' + self.printer.history.save(self.cli.settings.get("history", "")) + try: + local = dict() + local["cli"] = self.cli + local["rpc"] = self.cli.rpc + local["proxy"] = ConnectionProxy(self.cli.rpc) + c = code.InteractiveConsole(local) + c.interact("Use Ctrl+D to go back in CLI") + finally: + self.printer.history.load(self.cli.settings.get("history", "")) + cmd_expert.usage = "expert" + class Alias(dict): ''' Alias wrapper''' diff --git a/cccli/printer.py b/cccli/printer.py index 6bd75d9..51accd8 100644 --- a/cccli/printer.py +++ b/cccli/printer.py @@ -106,8 +106,8 @@ class Printer(object): raise except KeyboardInterrupt: raise - except: - raise cliError + except Exception as e: + raise cliError(str(e)) if not history and s: self.history.removelast() return s -- GitLab