[ Stefano Rivera ]

[ Julian Taylor ]
lp-shell: use ipython shell if available
This commit is contained in:
Julian Taylor 2011-08-14 21:00:11 +02:00 committed by Stefano Rivera
commit 7acdaaf977
4 changed files with 58 additions and 18 deletions

6
debian/changelog vendored
View File

@ -1,8 +1,12 @@
ubuntu-dev-tools (0.128) UNRELEASED; urgency=low
[ Stefano Rivera ]
* ubuntutools.builder: Detect missing builder and fail early.
-- Stefano Rivera <stefanor@debian.org> Mon, 25 Jul 2011 19:36:41 +0200
[ Julian Taylor ]
* lp-shell: use ipython shell if available
-- Julian Taylor <jtaylor.debian@googlemail.com> Sun, 14 Aug 2011 18:56:52 +0200
ubuntu-dev-tools (0.127) unstable; urgency=low

2
debian/control vendored
View File

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

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 an 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='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()