From 3449fc6a640c4ce36b1fe8647690f69696071e01 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 17:07:42 +0200 Subject: [PATCH 1/8] lp-shell: use ipython shell if available suggest ipython and when available use it instead of the regular python shell --- debian/control | 2 +- lp-shell | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-) 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/lp-shell b/lp-shell index bd8c61f..009e637 100755 --- a/lp-shell +++ b/lp-shell @@ -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() From d0afcbd295ae26f0b8404a06e8e51e872f1b40b9 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 17:40:10 +0200 Subject: [PATCH 2/8] lp-shell: use ipython shell if available --- debian/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/changelog b/debian/changelog index 08ab4c4..8e7b151 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ ubuntu-dev-tools (0.128) UNRELEASED; urgency=low * ubuntutools.builder: Detect missing builder and fail early. + * lp-shell: use ipython shell if available -- Stefano Rivera Mon, 25 Jul 2011 19:36:41 +0200 From 5f374b192bb7596b82db20e2759b03962333c23a Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 17:40:28 +0200 Subject: [PATCH 3/8] lp-shell: add cmd-line options to set used shell --- doc/lp-shell.1 | 10 ++++++++++ lp-shell | 33 +++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/doc/lp-shell.1 b/doc/lp-shell.1 index 5aefea0..36cc7f2 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 a 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 009e637..211fbff 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='mode',const='ipython', default="ipython", + help='Use ipython shell (default).') + opt_parser.add_option('--python',action='store_const', + dest='mode',const='python', + help='Use python shell.') + (options, args) = opt_parser.parse_args() @@ -63,17 +70,23 @@ def main(): banner += '\nNote: LP can be accessed through the "lp" object.' - 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 = None + if options.mode == "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 + from IPython.Shell import IPShellEmbed + sh = IPShellEmbed(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." + + if sh: sh() - except ImportError: + else: class CompleterConsole(code.InteractiveConsole): def __init__(self): local = {'lp': launchpad} From a8965d486d2f1ffd1ec162627b611e738473ebf8 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 18:03:09 +0200 Subject: [PATCH 4/8] lp-shell: disable import error pylint error on nested try-except --- lp-shell | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lp-shell b/lp-shell index 211fbff..7f5851c 100755 --- a/lp-shell +++ b/lp-shell @@ -77,6 +77,8 @@ def main(): 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(user_ns={'lp': launchpad}) sh.set_banner(sh.IP.BANNER + '\n' + banner) From 8e8a5d7e52b5e9ec106fa9db4ec565cde1fa4257 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 18:03:47 +0200 Subject: [PATCH 5/8] lp-shell: clear argv for ipython < 0.11 --- lp-shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lp-shell b/lp-shell index 7f5851c..aa1d515 100755 --- a/lp-shell +++ b/lp-shell @@ -80,7 +80,7 @@ def main(): # pylint does not handle nested try-except, disable import error # pylint: disable-msg=E0611 from IPython.Shell import IPShellEmbed - sh = IPShellEmbed(user_ns={'lp': launchpad}) + sh = IPShellEmbed(argv=[], user_ns={'lp': launchpad}) sh.set_banner(sh.IP.BANNER + '\n' + banner) sh.excepthook = sys.__excepthook__ except ImportError: From 04d4e0f3d94fd63e465ff697f60519966ec5441a Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 18:54:53 +0200 Subject: [PATCH 6/8] doc/lp-shell.1: fix typo --- doc/lp-shell.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/lp-shell.1 b/doc/lp-shell.1 index 36cc7f2..12a4d2d 100644 --- a/doc/lp-shell.1 +++ b/doc/lp-shell.1 @@ -38,7 +38,7 @@ Login anonymously into Launchpad. .TP .B \-\-ipython -Use a ipython shell if available (default). +Use an ipython shell if available (default). .TP .B \-\-python From 405141964e29c00a4015fac1249818f575a0b3f8 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 18:56:31 +0200 Subject: [PATCH 7/8] lp-shell: rename options.mode to options.shell --- lp-shell | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lp-shell b/lp-shell index aa1d515..83c715c 100755 --- a/lp-shell +++ b/lp-shell @@ -34,10 +34,10 @@ def main(): dest='anonymous', default=False, help='Login anonymously into LP.') opt_parser.add_option('--ipython',action='store_const', - dest='mode',const='ipython', default="ipython", + dest='shell',const='ipython', default="ipython", help='Use ipython shell (default).') opt_parser.add_option('--python',action='store_const', - dest='mode',const='python', + dest='shell',const='python', help='Use python shell.') @@ -71,7 +71,7 @@ def main(): banner += '\nNote: LP can be accessed through the "lp" object.' sh = None - if options.mode == "ipython": + if options.shell == "ipython": try: try: # ipython >= 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed From e124934502916c25d6a7358a680268a29b760c6c Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 18:57:09 +0200 Subject: [PATCH 8/8] fix changelog --- debian/changelog | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 8e7b151..516ac3c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,12 @@ ubuntu-dev-tools (0.128) UNRELEASED; urgency=low + [ Stefano Rivera ] * ubuntutools.builder: Detect missing builder and fail early. + + [ Julian Taylor ] * lp-shell: use ipython shell if available - -- Stefano Rivera Mon, 25 Jul 2011 19:36:41 +0200 + -- Julian Taylor Sun, 14 Aug 2011 18:56:52 +0200 ubuntu-dev-tools (0.127) unstable; urgency=low