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-soappy,
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
This is a collection of useful tools that Ubuntu developers use to make their
packaging work a lot easier.

View File

@ -63,24 +63,35 @@ def main():
banner += '\nNote: LP can be accessed through the "lp" object.'
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")
try:
try: # ipython >= 0.11
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmbed(banner2=banner, user_ns={'lp': launchpad})
except ImportError: # ipython < 0.11
from IPython.Shell import IPShellEmbed
sh = IPShellEmbed(user_ns={'lp': launchpad})
sh.set_banner(sh.IP.BANNER + '\n' + banner)
sh.excepthook = sys.__excepthook__
sh()
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
# and thus exceptions often bubble up to the top level.
sys.excepthook = sys.__excepthook__
# Disable default apport hook, as lp-shell is intended for interactive use
# and thus exceptions often bubble up to the top level.
sys.excepthook = sys.__excepthook__
console = CompleterConsole()
console.interact(banner)
console = CompleterConsole()
console.interact(banner)
if __name__ == '__main__':
main()