lp-shell: use ipython shell if available

suggest ipython and when available use it instead of the regular python shell
This commit is contained in:
Julian Taylor 2011-08-14 17:07:42 +02:00
parent 5762512710
commit 3449fc6a64
2 changed files with 28 additions and 17 deletions

2
debian/control vendored
View File

@ -57,7 +57,7 @@ Recommends: bzr,
python-gnupginterface, python-gnupginterface,
python-soappy, python-soappy,
reportbug (>= 3.39ubuntu1) reportbug (>= 3.39ubuntu1)
Suggests: python-simplejson | python (>= 2.7), qemu-user-static Suggests: ipython, python-simplejson | python (>= 2.7), qemu-user-static
Description: useful tools for Ubuntu developers Description: useful tools for Ubuntu developers
This is a collection of useful tools that Ubuntu developers use to make their This is a collection of useful tools that Ubuntu developers use to make their
packaging work a lot easier. packaging work a lot easier.

View File

@ -63,24 +63,35 @@ def main():
banner += '\nNote: LP can be accessed through the "lp" object.' banner += '\nNote: LP can be accessed through the "lp" object.'
class CompleterConsole(code.InteractiveConsole): try:
def __init__(self): try: # ipython >= 0.11
local = {'lp': launchpad} from IPython.frontend.terminal.embed import InteractiveShellEmbed
code.InteractiveConsole.__init__(self, locals=local) sh = InteractiveShellEmbed(banner2=banner, user_ns={'lp': launchpad})
try: except ImportError: # ipython < 0.11
import readline from IPython.Shell import IPShellEmbed
except ImportError: sh = IPShellEmbed(user_ns={'lp': launchpad})
print 'I: readline module not available.' sh.set_banner(sh.IP.BANNER + '\n' + banner)
else: sh.excepthook = sys.__excepthook__
import rlcompleter sh()
readline.parse_and_bind("tab: complete") except ImportError:
class CompleterConsole(code.InteractiveConsole):
def __init__(self):
local = {'lp': launchpad}
code.InteractiveConsole.__init__(self, locals=local)
try:
import readline
except ImportError:
print 'I: readline module not available.'
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
# Disable default apport hook, as lp-shell is intended for interactive use # Disable default apport hook, as lp-shell is intended for interactive use
# and thus exceptions often bubble up to the top level. # and thus exceptions often bubble up to the top level.
sys.excepthook = sys.__excepthook__ sys.excepthook = sys.__excepthook__
console = CompleterConsole() console = CompleterConsole()
console.interact(banner) console.interact(banner)
if __name__ == '__main__': if __name__ == '__main__':
main() main()