Show More
@@ -11,11 +11,7 b' ip = IPython.ipapi.get()' | |||
|
11 | 11 | |
|
12 | 12 | from ipy_completers import * |
|
13 | 13 | |
|
14 |
ip.set_hook('complete_command', apt_completer |
|
|
15 | ip.set_hook('complete_command', apt_completers, re_key = '.*yum') | |
|
16 | ||
|
14 | ip.set_hook('complete_command', apt_completer, re_key = '.*apt-get') | |
|
17 | 15 | ip.set_hook('complete_command', svn_completer, str_key = 'svn') |
|
18 | ||
|
19 | 16 | ip.set_hook('complete_command', hg_completer, str_key = 'hg') |
|
20 | ||
|
21 | 17 | ip.set_hook('complete_command', bzr_completer, str_key = 'bzr') |
@@ -165,32 +165,6 b' def vcs_completer(commands, event):' | |||
|
165 | 165 | return ip.IP.Completer.file_matches(event.symbol) |
|
166 | 166 | |
|
167 | 167 | |
|
168 | ||
|
169 | def apt_completers(self, event): | |
|
170 | """ This should return a list of strings with possible completions. | |
|
171 | ||
|
172 | Note that all the included strings that don't start with event.symbol | |
|
173 | are removed, in order to not confuse readline. | |
|
174 | ||
|
175 | """ | |
|
176 | # print event # dbg | |
|
177 | ||
|
178 | # commands are only suggested for the 'command' part of package manager | |
|
179 | # invocation | |
|
180 | ||
|
181 | cmd = (event.line + "<placeholder>").rsplit(None,1)[0] | |
|
182 | # print cmd | |
|
183 | if cmd.endswith('apt-get') or cmd.endswith('yum'): | |
|
184 | return ['update', 'upgrade', 'install', 'remove'] | |
|
185 | ||
|
186 | # later on, add dpkg -l / whatever to get list of possible | |
|
187 | # packages, add switches etc. for the rest of command line | |
|
188 | # filling | |
|
189 | ||
|
190 | raise IPython.ipapi.TryNext | |
|
191 | ||
|
192 | ||
|
193 | ||
|
194 | 168 | pkg_cache = None |
|
195 | 169 | |
|
196 | 170 | def module_completer(self,event): |
@@ -350,3 +324,32 b' def cd_completer(self, event):' | |||
|
350 | 324 | raise IPython.ipapi.TryNext |
|
351 | 325 | return found |
|
352 | 326 | |
|
327 | def apt_get_packages(prefix): | |
|
328 | out = os.popen('apt-cache pkgnames') | |
|
329 | for p in out: | |
|
330 | if p.startswith(prefix): | |
|
331 | yield p.rstrip() | |
|
332 | ||
|
333 | ||
|
334 | apt_commands = """\ | |
|
335 | update upgrade install remove purge source build-dep dist-upgrade | |
|
336 | dselect-upgrade clean autoclean check""" | |
|
337 | ||
|
338 | def apt_completer(self, event): | |
|
339 | """ Completer for apt-get (uses apt-cache internally) | |
|
340 | ||
|
341 | """ | |
|
342 | ||
|
343 | ||
|
344 | cmd_param = event.line.split() | |
|
345 | if event.line.endswith(' '): | |
|
346 | cmd_param.append('') | |
|
347 | ||
|
348 | if cmd_param[0] == 'sudo': | |
|
349 | cmd_param = cmd_param[1:] | |
|
350 | ||
|
351 | if len(cmd_param) == 2 or 'help' in cmd_param: | |
|
352 | return apt_commands.split() | |
|
353 | ||
|
354 | return list(apt_get_packages(event.symbol)) | |
|
355 |
@@ -620,8 +620,8 b' class IPCompleter(Completer):' | |||
|
620 | 620 | except IndexError: |
|
621 | 621 | return None |
|
622 | 622 | except: |
|
623 |
|
|
|
624 |
|
|
|
623 | from IPython.ultraTB import AutoFormattedTB; # dbg | |
|
624 | tb=AutoFormattedTB('Verbose');tb() #dbg | |
|
625 | 625 | |
|
626 | 626 | # If completion fails, don't annoy the user. |
|
627 | 627 | return None |
@@ -1,6 +1,9 b'' | |||
|
1 | 1 | 2007-11-08 Ville Vainio <vivainio@gmail.com> |
|
2 | * ipy_completer.py (import completer): assume 'xml' module exists. | |
|
2 | * ipy_completers.py (import completer): assume 'xml' module exists. | |
|
3 | 3 | Do not add every module twice anymore. Closes #196. |
|
4 | ||
|
5 | * ipy_completers.py, ipy_app_completers.py: Add proper apt-get | |
|
6 | completer that uses apt-cache to search for existing packages. | |
|
4 | 7 | |
|
5 | 8 | 2007-11-06 Ville Vainio <vivainio@gmail.com> |
|
6 | 9 |
General Comments 0
You need to be logged in to leave comments.
Login now