OLD | NEW |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # | 3 # |
4 # This file is part of logilab-common. | 4 # This file is part of logilab-common. |
5 # | 5 # |
6 # logilab-common is free software: you can redistribute it and/or modify it unde
r | 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
9 # later version. | 9 # later version. |
10 # | 10 # |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 help_do_ronfle = ("ronfle", "ronfle volume", _("met les autres en veille
")) | 38 help_do_ronfle = ("ronfle", "ronfle volume", _("met les autres en veille
")) |
39 def do_ronfle(self): | 39 def do_ronfle(self): |
40 print 'fuuuuuuuuuuuu rhhhhhrhrhrrh' | 40 print 'fuuuuuuuuuuuu rhhhhhrhrhrrh' |
41 | 41 |
42 cl = BookShell() | 42 cl = BookShell() |
43 """ | 43 """ |
44 | 44 |
45 __docformat__ = "restructuredtext en" | 45 __docformat__ = "restructuredtext en" |
46 | 46 |
47 from six.moves import builtins, input | 47 from logilab.common.compat import raw_input, builtins |
48 | |
49 if not hasattr(builtins, '_'): | 48 if not hasattr(builtins, '_'): |
50 builtins._ = str | 49 builtins._ = str |
51 | 50 |
52 | 51 |
53 def init_readline(complete_method, histfile=None): | 52 def init_readline(complete_method, histfile=None): |
54 """Init the readline library if available.""" | 53 """Init the readline library if available.""" |
55 try: | 54 try: |
56 import readline | 55 import readline |
57 readline.parse_and_bind("tab: complete") | 56 readline.parse_and_bind("tab: complete") |
58 readline.set_completer(complete_method) | 57 readline.set_completer(complete_method) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 def __init__(self, histfile=None) : | 100 def __init__(self, histfile=None) : |
102 self._topics = {} | 101 self._topics = {} |
103 self.commands = None | 102 self.commands = None |
104 self._completer = Completer(self._register_commands()) | 103 self._completer = Completer(self._register_commands()) |
105 init_readline(self._completer.complete, histfile) | 104 init_readline(self._completer.complete, histfile) |
106 | 105 |
107 def run(self): | 106 def run(self): |
108 """loop on user input, exit on EOF""" | 107 """loop on user input, exit on EOF""" |
109 while True: | 108 while True: |
110 try: | 109 try: |
111 line = input('>>> ') | 110 line = raw_input('>>> ') |
112 except EOFError: | 111 except EOFError: |
113 print | 112 print |
114 break | 113 break |
115 s_line = line.strip() | 114 s_line = line.strip() |
116 if not s_line: | 115 if not s_line: |
117 continue | 116 continue |
118 args = s_line.split() | 117 args = s_line.split() |
119 if args[0] in self.commands: | 118 if args[0] in self.commands: |
120 try: | 119 try: |
121 cmd = 'do_%s' % self.commands[args[0]] | 120 cmd = 'do_%s' % self.commands[args[0]] |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 for command_help_method in self._topics[command]: | 187 for command_help_method in self._topics[command]: |
189 try: | 188 try: |
190 if callable(command_help_method): | 189 if callable(command_help_method): |
191 self._print_help(*command_help_method()) | 190 self._print_help(*command_help_method()) |
192 else: | 191 else: |
193 self._print_help(*command_help_method) | 192 self._print_help(*command_help_method) |
194 except: | 193 except: |
195 import traceback | 194 import traceback |
196 traceback.print_exc() | 195 traceback.print_exc() |
197 print 'ERROR in help method %s'% ( | 196 print 'ERROR in help method %s'% ( |
198 command_help_method.__name__) | 197 command_help_method.func_name) |
199 | 198 |
200 help_do_help = ("help", "help [topic|command]", | 199 help_do_help = ("help", "help [topic|command]", |
201 _("print help message for the given topic/command or \ | 200 _("print help message for the given topic/command or \ |
202 available topics when no argument")) | 201 available topics when no argument")) |
203 | 202 |
204 def do_quit(self): | 203 def do_quit(self): |
205 """quit the CLI""" | 204 """quit the CLI""" |
206 raise EOFError() | 205 raise EOFError() |
207 | 206 |
208 def help_do_quit(self): | 207 def help_do_quit(self): |
209 return ("quit", "quit", _("quit the application")) | 208 return ("quit", "quit", _("quit the application")) |
OLD | NEW |