lp-shell: add cmd-line options to set used shell

This commit is contained in:
Julian Taylor 2011-08-14 17:40:28 +02:00
parent d0afcbd295
commit 5f374b192b
2 changed files with 33 additions and 10 deletions

View File

@ -5,6 +5,8 @@ lp\-shell \- Open an interactive launchpadlib shell.
.SH SYNOPSIS .SH SYNOPSIS
.B lp\-shell .B lp\-shell
.RB [ \-a ] .RB [ \-a ]
.RB [ \-\-python ]
.RB [ \-\-ipython ]
.RI [ service ] .RI [ service ]
.RI [ "LP API version" ] .RI [ "LP API version" ]
@ -34,6 +36,14 @@ the third argument. Current supported are: "beta", "1.0" and "devel".
.B \-a .B \-a
Login anonymously into Launchpad. Login anonymously into Launchpad.
.TP
.B \-\-ipython
Use a ipython shell if available (default).
.TP
.B \-\-python
Use a regular python shell.
.SH AUTHORS .SH AUTHORS
.B lp\-shell .B lp\-shell
was written by Martin Pitt <martin.pitt@ubuntu.com>. was written by Martin Pitt <martin.pitt@ubuntu.com>.

View File

@ -33,6 +33,13 @@ def main():
opt_parser.add_option('-a', action='store_true', opt_parser.add_option('-a', action='store_true',
dest='anonymous', default=False, dest='anonymous', default=False,
help='Login anonymously into LP.') 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() (options, args) = opt_parser.parse_args()
@ -63,17 +70,23 @@ def main():
banner += '\nNote: LP can be accessed through the "lp" object.' banner += '\nNote: LP can be accessed through the "lp" object.'
try: sh = None
try: # ipython >= 0.11 if options.mode == "ipython":
from IPython.frontend.terminal.embed import InteractiveShellEmbed try:
sh = InteractiveShellEmbed(banner2=banner, user_ns={'lp': launchpad}) try: # ipython >= 0.11
except ImportError: # ipython < 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed
from IPython.Shell import IPShellEmbed sh = InteractiveShellEmbed(banner2=banner, user_ns={'lp': launchpad})
sh = IPShellEmbed(user_ns={'lp': launchpad}) except ImportError: # ipython < 0.11
sh.set_banner(sh.IP.BANNER + '\n' + banner) from IPython.Shell import IPShellEmbed
sh.excepthook = sys.__excepthook__ 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() sh()
except ImportError: else:
class CompleterConsole(code.InteractiveConsole): class CompleterConsole(code.InteractiveConsole):
def __init__(self): def __init__(self):
local = {'lp': launchpad} local = {'lp': launchpad}