diff --git a/debian/changelog b/debian/changelog index 08ab4c4..516ac3c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,12 @@ ubuntu-dev-tools (0.128) UNRELEASED; urgency=low + [ Stefano Rivera ] * ubuntutools.builder: Detect missing builder and fail early. - -- Stefano Rivera Mon, 25 Jul 2011 19:36:41 +0200 + [ Julian Taylor ] + * lp-shell: use ipython shell if available + + -- Julian Taylor Sun, 14 Aug 2011 18:56:52 +0200 ubuntu-dev-tools (0.127) unstable; urgency=low diff --git a/debian/control b/debian/control index 2217684..c9225d8 100644 --- a/debian/control +++ b/debian/control @@ -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. diff --git a/doc/lp-shell.1 b/doc/lp-shell.1 index 5aefea0..12a4d2d 100644 --- a/doc/lp-shell.1 +++ b/doc/lp-shell.1 @@ -5,6 +5,8 @@ lp\-shell \- Open an interactive launchpadlib shell. .SH SYNOPSIS .B lp\-shell .RB [ \-a ] +.RB [ \-\-python ] +.RB [ \-\-ipython ] .RI [ service ] .RI [ "LP API version" ] @@ -34,6 +36,14 @@ the third argument. Current supported are: "beta", "1.0" and "devel". .B \-a Login anonymously into Launchpad. +.TP +.B \-\-ipython +Use an ipython shell if available (default). + +.TP +.B \-\-python +Use a regular python shell. + .SH AUTHORS .B lp\-shell was written by Martin Pitt . diff --git a/lp-shell b/lp-shell index bd8c61f..83c715c 100755 --- a/lp-shell +++ b/lp-shell @@ -33,6 +33,13 @@ def main(): opt_parser.add_option('-a', action='store_true', dest='anonymous', default=False, help='Login anonymously into LP.') + opt_parser.add_option('--ipython',action='store_const', + dest='shell',const='ipython', default="ipython", + help='Use ipython shell (default).') + opt_parser.add_option('--python',action='store_const', + dest='shell',const='python', + help='Use python shell.') + (options, args) = opt_parser.parse_args() @@ -63,24 +70,43 @@ 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") + sh = None + if options.shell == "ipython": + 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 + # pylint does not handle nested try-except, disable import error + # pylint: disable-msg=E0611 + from IPython.Shell import IPShellEmbed + sh = IPShellEmbed(argv=[], user_ns={'lp': launchpad}) + sh.set_banner(sh.IP.BANNER + '\n' + banner) + sh.excepthook = sys.__excepthook__ + except ImportError: + print "E: ipython not available. Using normal python shell." - # 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__ + if sh: + sh() + else: + 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") - console = CompleterConsole() - console.interact(banner) + # 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) if __name__ == '__main__': main()