From 5f374b192bb7596b82db20e2759b03962333c23a Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 14 Aug 2011 17:40:28 +0200 Subject: [PATCH] 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}