Loading README +2 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,8 @@ alias vm "list vm&status=running$cpu" ======= History ======= History is stored in ~/.local/share/cc-cli/history CLI history is stored in ~/.local/share/cc-cli/history Expoert mode history is stored in ~/.local/share/cc-cli/expert === TQL Loading bin/cc-cli +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ settings = { "hsize": "100", "alias": "%s/alias"%BaseDirectory.save_config_path(cccli.canonical_name), "history": "%s/history"%BaseDirectory.save_data_path(cccli.canonical_name), "expert": "%s/expert"%BaseDirectory.save_data_path(cccli.canonical_name), } try: Loading cccli/cli.py +1 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ class Cli(object): # parsing self._parse() # save history self.printer.history.save(self.settings.get("history", "")) self.printer.history.write(self.settings.get("history", "")) def _connect(self): '''Connect to a cloud control server''' Loading cccli/command.py +5 −3 Original line number Diff line number Diff line Loading @@ -453,16 +453,18 @@ class Command(object): def cmd_expert(self, argv): '''Switch in expert mode''' self.printer.history.save(self.cli.settings.get("history", "")) h = list(self.printer.history) self.printer.history.read(self.cli.settings.get("expert", "")) 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") c.interact("Use Ctrl+D to go back in CLI. Type dir() to see variables.") finally: self.printer.history.load(self.cli.settings.get("history", "")) self.printer.history.write(self.cli.settings.get("expert", "")) self.printer.history.load(h) cmd_expert.usage = "expert" def cmd_whoami(self, argv): Loading cccli/printer.py +21 −5 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ class Printer(object): self.history = History(self.readline) else: self.history.readline = readline self.history.load(self.historyfile) self.history.read(self.historyfile) self.history.maxsize(self.historysize) def out(self, message="", fd=sys.stdout, nl=os.linesep, flush=True): Loading Loading @@ -101,6 +101,7 @@ class Printer(object): self.out(message, fd, nl) def getline(self, prompt, history=True): '''Read a line from stdin''' try: s = raw_input(prompt) except EOFError: Loading @@ -123,7 +124,13 @@ class Printer(object): '''Used to ask a question. Default answer not saved to history''' if self.readline is None: raise cliError("Unable to ask question in non-interactive mode") return self.getline(prompt, history=False) h = list(self.history) self.history.clear() try: r = self.getline(prompt, history=False) finally: self.history.load(h) return r class History(object): Loading @@ -143,7 +150,9 @@ class History(object): return object.__getattribute__(self, name) def __iter__(self): for i in range(1, len(self)): if self.readline is None: return for i in range(1, self.readline.get_current_history_length() + 1): yield self.readline.get_history_item(i) def __len__(self): Loading @@ -151,14 +160,21 @@ class History(object): return 0 return self.readline.get_current_history_length() def load(self, path): def load(self, items): '''Load history from a list''' self.clear() for l in items: self.readline.add_history(l) def read(self, path): '''Load history from a file''' self.clear() try: self.readline.read_history_file(path) except IOError: pass def save(self, path): def write(self, path): '''Save history into path''' try: self.readline.write_history_file(path) Loading Loading
README +2 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,8 @@ alias vm "list vm&status=running$cpu" ======= History ======= History is stored in ~/.local/share/cc-cli/history CLI history is stored in ~/.local/share/cc-cli/history Expoert mode history is stored in ~/.local/share/cc-cli/expert === TQL Loading
bin/cc-cli +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ settings = { "hsize": "100", "alias": "%s/alias"%BaseDirectory.save_config_path(cccli.canonical_name), "history": "%s/history"%BaseDirectory.save_data_path(cccli.canonical_name), "expert": "%s/expert"%BaseDirectory.save_data_path(cccli.canonical_name), } try: Loading
cccli/cli.py +1 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ class Cli(object): # parsing self._parse() # save history self.printer.history.save(self.settings.get("history", "")) self.printer.history.write(self.settings.get("history", "")) def _connect(self): '''Connect to a cloud control server''' Loading
cccli/command.py +5 −3 Original line number Diff line number Diff line Loading @@ -453,16 +453,18 @@ class Command(object): def cmd_expert(self, argv): '''Switch in expert mode''' self.printer.history.save(self.cli.settings.get("history", "")) h = list(self.printer.history) self.printer.history.read(self.cli.settings.get("expert", "")) 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") c.interact("Use Ctrl+D to go back in CLI. Type dir() to see variables.") finally: self.printer.history.load(self.cli.settings.get("history", "")) self.printer.history.write(self.cli.settings.get("expert", "")) self.printer.history.load(h) cmd_expert.usage = "expert" def cmd_whoami(self, argv): Loading
cccli/printer.py +21 −5 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ class Printer(object): self.history = History(self.readline) else: self.history.readline = readline self.history.load(self.historyfile) self.history.read(self.historyfile) self.history.maxsize(self.historysize) def out(self, message="", fd=sys.stdout, nl=os.linesep, flush=True): Loading Loading @@ -101,6 +101,7 @@ class Printer(object): self.out(message, fd, nl) def getline(self, prompt, history=True): '''Read a line from stdin''' try: s = raw_input(prompt) except EOFError: Loading @@ -123,7 +124,13 @@ class Printer(object): '''Used to ask a question. Default answer not saved to history''' if self.readline is None: raise cliError("Unable to ask question in non-interactive mode") return self.getline(prompt, history=False) h = list(self.history) self.history.clear() try: r = self.getline(prompt, history=False) finally: self.history.load(h) return r class History(object): Loading @@ -143,7 +150,9 @@ class History(object): return object.__getattribute__(self, name) def __iter__(self): for i in range(1, len(self)): if self.readline is None: return for i in range(1, self.readline.get_current_history_length() + 1): yield self.readline.get_history_item(i) def __len__(self): Loading @@ -151,14 +160,21 @@ class History(object): return 0 return self.readline.get_current_history_length() def load(self, path): def load(self, items): '''Load history from a list''' self.clear() for l in items: self.readline.add_history(l) def read(self, path): '''Load history from a file''' self.clear() try: self.readline.read_history_file(path) except IOError: pass def save(self, path): def write(self, path): '''Save history into path''' try: self.readline.write_history_file(path) Loading