Loading cccli/cli.py +19 −16 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ CloudControl CLI main module ''' import cccli from cccli.exception import * from cccli.printer import Printer, color Loading Loading @@ -69,7 +68,7 @@ class Cli(object): # load tagdisplay self.tagdisplay.load(self.settings.get("tagdisplay", "")) # parsing self._parse() self._parse_loop() # save history self.printer.history.write(self.settings.get("history", None)) Loading Loading @@ -100,29 +99,33 @@ class Cli(object): raise cliError(s) self.printer.debug("Authenticated.") def _parse(self): '''Parse a line''' def _parse_loop(self): '''Parse lines''' while True: try: line = self.printer.getline(self.prompt) self._parse(line) except KeyboardInterrupt: self.printer.out("") except EOFError: break except SystemExit: break self.printer.interactive("tcho!") def _parse(self, line): '''Parse a string''' try: argv = shlex.split(self.printer.getline(self.prompt), comments=True) argv = shlex.split(line, comments=True) except ValueError as e: self.printer.error("Lexer: %s"%str(e)) continue return if len(argv) == 0: continue return # alias subsitution argv = self.aliases.substitute(argv) # command execution self._exec_command(argv) except KeyboardInterrupt: self.printer.out("") continue except EOFError: break except SystemExit: break self.printer.interactive("tcho!") def _exec_command(self, argv): '''Execute command''' Loading cccli/commands/shell.py +18 −0 Original line number Diff line number Diff line Loading @@ -97,3 +97,21 @@ class Command_usage(Command): def usage(self): return "Usage: usage <command>" class Command_source(Command): '''Source a file an execute it''' def __call__(self, argv): if len(argv) != 2: raise cmdBadArgument() try: fo = open(argv[1], "r") except Exception as e: raise cmdError("Unable to open %s: %s" % (argv[1], e)) for line in fo.readlines(): self.cli._parse(line) fo.close() def usage(self): return "Usage: source <file>" Loading
cccli/cli.py +19 −16 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ CloudControl CLI main module ''' import cccli from cccli.exception import * from cccli.printer import Printer, color Loading Loading @@ -69,7 +68,7 @@ class Cli(object): # load tagdisplay self.tagdisplay.load(self.settings.get("tagdisplay", "")) # parsing self._parse() self._parse_loop() # save history self.printer.history.write(self.settings.get("history", None)) Loading Loading @@ -100,29 +99,33 @@ class Cli(object): raise cliError(s) self.printer.debug("Authenticated.") def _parse(self): '''Parse a line''' def _parse_loop(self): '''Parse lines''' while True: try: line = self.printer.getline(self.prompt) self._parse(line) except KeyboardInterrupt: self.printer.out("") except EOFError: break except SystemExit: break self.printer.interactive("tcho!") def _parse(self, line): '''Parse a string''' try: argv = shlex.split(self.printer.getline(self.prompt), comments=True) argv = shlex.split(line, comments=True) except ValueError as e: self.printer.error("Lexer: %s"%str(e)) continue return if len(argv) == 0: continue return # alias subsitution argv = self.aliases.substitute(argv) # command execution self._exec_command(argv) except KeyboardInterrupt: self.printer.out("") continue except EOFError: break except SystemExit: break self.printer.interactive("tcho!") def _exec_command(self, argv): '''Execute command''' Loading
cccli/commands/shell.py +18 −0 Original line number Diff line number Diff line Loading @@ -97,3 +97,21 @@ class Command_usage(Command): def usage(self): return "Usage: usage <command>" class Command_source(Command): '''Source a file an execute it''' def __call__(self, argv): if len(argv) != 2: raise cmdBadArgument() try: fo = open(argv[1], "r") except Exception as e: raise cmdError("Unable to open %s: %s" % (argv[1], e)) for line in fo.readlines(): self.cli._parse(line) fo.close() def usage(self): return "Usage: source <file>"