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
.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 <martin.pitt@ubuntu.com>.

View File

@ -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}