lp-shell:

+ Add support for using different LP API versions.
+ Add option to login anonymously into LP.
doc/lp-shell.1: Update the documentation.
This commit is contained in:
Michael Bienia 2010-03-27 20:19:58 +01:00
parent 28f7abc2d4
commit e8722696bf
3 changed files with 79 additions and 18 deletions

8
debian/changelog vendored
View File

@ -1,8 +1,10 @@
ubuntu-dev-tools (0.97) UNRELEASED; urgency=low ubuntu-dev-tools (0.97) UNRELEASED; urgency=low
[ Michael Bienia ] [ Michael Bienia ]
* lp-shell: Support all to the launchpadlib Python module known service * lp-shell:
names. + Support all known LP service names.
+ Add support for using different LP API versions.
+ Add option to login anonymously into LP.
* ubuntutools/lp/lpapicache.py, ubuntutools/lp/libsupport.py: Add support * ubuntutools/lp/lpapicache.py, ubuntutools/lp/libsupport.py: Add support
for different LP API versions. for different LP API versions.
* ubuntutools/lp/__init__.py: Set the '1.0' LP API version as default. * ubuntutools/lp/__init__.py: Set the '1.0' LP API version as default.
@ -13,7 +15,7 @@ ubuntu-dev-tools (0.97) UNRELEASED; urgency=low
* Apply patch from Julian Andres Klode for the python-apt 0.8 API transition * Apply patch from Julian Andres Klode for the python-apt 0.8 API transition
(Closes: #572091) (Closes: #572091)
-- Michael Bienia <geser@ubuntu.com> Thu, 25 Mar 2010 21:58:47 +0100 -- Michael Bienia <geser@ubuntu.com> Sat, 27 Mar 2010 20:14:24 +0100
ubuntu-dev-tools (0.96) lucid; urgency=low ubuntu-dev-tools (0.96) lucid; urgency=low

View File

@ -1,26 +1,39 @@
.TH lp-shell "1" "13 January 2010" "ubuntu-dev-tools" .TH lp-shell "1" "27 March 2010" "ubuntu-dev-tools"
.SH NAME .SH NAME
lp\-shell \- Open an interactive launchpadlib shell. lp\-shell \- Open an interactive launchpadlib shell.
.SH SYNOPSIS .SH SYNOPSIS
.B lp\-shell .B lp\-shell
[service] .RB [ \-a ]
.RI [ service ]
.RI [ "LP API version" ]
.SH DESCRIPTION .SH DESCRIPTION
.B lp\-shell .B lp\-shell
opens an interactive Python shell with a launchpadlib.Launchpad object "lp" opens an interactive Python shell with a launchpadlib.Launchpad object "lp"
which is ready for use. which is ready for use.
It authenticates against Launchpad with the consumer name "test". It authenticates against Launchpad with the consumer name "test". When using
\fBlp\-shell\fR with the \fB\-a\fR option it will use the anonymous login
from launchpadlib.Launchpad.
It uses by default the "edge" Launchpad service and the default API version. By default \fBlp\-shell\fR connects to the "\fIedge\fR" Launchpad service
If you want to connect to an other Launchpad service, call using the "\fI1.0\fR" LP API version.
.B lp\-shell
with the service name as the second argument. lp-shell supports all services If you want to connect to an other Launchpad service, call \fBlp\-shell\fR with
the service name as the second argument. \fBlp\-shell\fR supports all services
known by launchpadlib Python module. known by launchpadlib Python module.
Currently known are (list can be incomplete or outdated): "production", "edge", Currently known are (list can be incomplete or outdated): "production", "edge",
"staging", "dogfood". "staging", "dogfood".
A different LP API version can be selected by passing the API version to use as
the third argument. Current supported are: "beta", "1.0" and "devel".
.SH OPTIONS
.TP
.B \-a
Login anonymously into Launchpad.
.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

@ -1,7 +1,8 @@
#!/usr/bin/python -i #!/usr/bin/python
# open an interactive launchpadlib Python shell. If the first command line # Open an interactive launchpadlib Python shell.
# argument is "staging", this will be on staging instead of production. # It supports all known LP service instances and API versions. The login
# can optionally happen anonymously.
# Author: Martin Pitt <martin.pitt@ubuntu.com> # Author: Martin Pitt <martin.pitt@ubuntu.com>
# Copyright: (C) 2010 Canonical Ltd. # Copyright: (C) 2010 Canonical Ltd.
@ -15,21 +16,66 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
import code, os, sys import sys
import code
from optparse import OptionParser
from launchpadlib.launchpad import Launchpad from launchpadlib.launchpad import Launchpad
from launchpadlib.uris import lookup_service_root from launchpadlib.uris import lookup_service_root
instance = 'edge' instance = 'edge'
if len(sys.argv) >= 2: valid_api_versions = ('beta', '1.0', 'devel')
api_version = '1.0'
usage = 'Usage: %prog [-a] [instance] [LP API version]'
optParser = OptionParser(usage)
optParser.add_option('-a', action='store_true',
dest='anonymous', default=False,
help='Login anonymously into LP.')
(options, args) = optParser.parse_args()
if len(args) >= 1:
try: try:
instance = lookup_service_root(sys.argv[1]) instance = lookup_service_root(args[0])
except ValueError, err: except ValueError, err:
print 'E: %s' % (err) print 'E: %s' % (err)
print 'W: Falling back to "edge"' print 'I: Falling back to "edge".'
lp = Launchpad.login_with('test', instance) if len(args) >= 2:
if args[1] in valid_api_versions:
api_version = args[1]
else:
print 'E: "%s" is not a valid LP API version.' % (args[1])
print 'I: Falling back to "1.0".'
if options.anonymous:
lp = Launchpad.login_anonymously('test', instance, version=api_version)
banner = 'Connected anonymously to LP service "%s" with API version "%s":' % (
instance, api_version)
else:
lp = Launchpad.login_with('test', instance, version=api_version)
banner = 'Connected to LP service "%s" with API version "%s":' % (
instance, api_version)
banner += '\nNote: LP can be accessed through the "lp" object.'
class CompleterConsole(code.InteractiveConsole):
def __init__(self):
local = {'lp': lp}
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 # Disable default apport hook, as lp-shell is intended for interactive use
# and thus exceptions often bubble up to the top level. # and thus exceptions often bubble up to the top level.
sys.excepthook = sys.__excepthook__ sys.excepthook = sys.__excepthook__
console = CompleterConsole()
console.interact(banner)