From a20be40283c873707354a676c8742368bf5088b1 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Wed, 29 Dec 2010 14:33:24 +0100 Subject: [PATCH] remplace , by as in exception --- bin/cc-cli | 4 +- cccli/builtins.py | 7 ---- cccli/cli.py | 10 ++--- cccli/parser.py | 99 ----------------------------------------------- 4 files changed, 7 insertions(+), 113 deletions(-) delete mode 100644 cccli/builtins.py delete mode 100644 cccli/parser.py diff --git a/bin/cc-cli b/bin/cc-cli index 0482435..cd80251 100755 --- a/bin/cc-cli +++ b/bin/cc-cli @@ -125,12 +125,12 @@ try: # start cli cli = Cli(settings) cli.start(" ".join(args)) -except BadArgument, e: +except BadArgument as e: printer.error("Bad Argument: %s"%str(e)) oparser.print_help() except KeyboardInterrupt: exit(1) -except Exception, e: +except Exception as e: if cccli.debug: printer.fatal(str(e), exitcode=-1) raise diff --git a/cccli/builtins.py b/cccli/builtins.py deleted file mode 100644 index 7973025..0000000 --- a/cccli/builtins.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python -#coding=utf8 - -''' -CloudControl CLI Builtins -''' - diff --git a/cccli/cli.py b/cccli/cli.py index 1384ff6..fc80e91 100644 --- a/cccli/cli.py +++ b/cccli/cli.py @@ -84,7 +84,7 @@ class Cli(object): # alias subsitution if argv[0] in self.alias: argv[0] = self.alias[argv[0]] - except ValueError, e: + except ValueError as e: self.printer.error("Lexer: %s"%str(e)) continue except EOFError: @@ -108,7 +108,7 @@ class Cli(object): Command(["help"], self).call() else: Command(argv, self).call() - except BadArgument, e: + except BadArgument as e: if str(e): self.printer.error("Bad argument: %s."%str(e)) else: @@ -116,15 +116,15 @@ class Cli(object): usage = Command.usage(argv[0]) if usage != "": self.printer.out("usage: %s."%usage) - except BadCommand, e: + except BadCommand as e: if str(e): self.printer.error("command: %s."%str(e)) else: self.printer.error("No command: %s."%argv[0]) - except RpcError, e: + except RpcError as e: if debug: raise self.printer.error("sjRPC: %s"%str(e)) - except Exception, e: + except Exception as e: if debug: raise self.printer.error("%s: %s."%(argv[0], str(e))) diff --git a/cccli/parser.py b/cccli/parser.py deleted file mode 100644 index e461a30..0000000 --- a/cccli/parser.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -#coding=utf8 - -''' -CloudControl CLI Parser -''' - -import sys -import os, os.path - -class Parser(object): - def __init__(self, options, alias): - self.interactive = sys.stderr.isatty() and sys.stdin.isatty() - # if os.environ.has_key("ITPASS_HISTFILE"): - # self.histfile = os.environ["ITPASS_HISTFILE"] - # else: - # self.histfile = "%s/.history"%os.environ["ITPASS_ROOT"] - # if os.environ.has_key("ITPASS_HISTSIZE"): - # self.histsize = int(os.environ["ITPASS_HISTSIZE"]) - # else: - # self.histsize = 500 - # if self.interactive: - # try: - # readline.read_history_file(self.histfile) - # except IOError: - # pass - # readline.set_history_length(self.histsize) - # readline.parse_and_bind("tab: complete") - # readline.set_completer_delims(string.whitespace) - # readline.set_completer(Completer().syntax_completion) - - def _prompt(self): - '''Show a parser prompt''' - return "> " - bang = "#" if Keyring().has_unlocked_key() else "$" - try: - cwd = re.sub(self.rootpath, '~', os.getcwd()) - except: - cwd = "?" - return "%s:%s %s "%(os.path.basename(sys.argv[0]), cwd, bang) - - def _interactive_parser(self): - '''Interactive shell parser''' - while True: - try: - line = raw_input(self._prompt()) - Keyring().check_timeout() - ret = self._parser(line) - if ret != 0: - warn("function return %s, not 0"%ret) - except EOFError: - out("") - break - except SystemExit: - break - except KeyboardInterrupt: - out("") - except myError, e: - error(str(e)) - except Exception, e: - error(e) - if os.environ.has_key("ITPASS_DEBUG"): - raise - else: - warn("this is a not expected error, please report it") - try: - readline.write_history_file(self.histfile) - except IOError: - pass - out("Tcho!") - - def _parser(self, string): - '''Parse a string''' - cmd_list = [ x.strip() for x in Parser.split(string, ";|\n", show_quote=True) ] - ret = 0 - for cmd in cmd_list: - if (cmd == "" or cmd[0] == "#"): - continue - elif (cmd[0] == "!"): - p = subprocess.Popen(cmd[1:], close_fds=True, shell=True) - p.wait() - ret = p.returncode - elif (cmd[0] == "?"): - Command("help").call() - ret = 0 - else: - Command(cmd).call() - ret = 0 - return ret - - def parse(self, command = ""): - '''Parser start''' - if command == "": - if self.interactive: - return self._interactive_parser() - else: - fatal("Not a TTY. Unable to start interactive parser") - else: - self._parser(command) -- GitLab