From e8722696bff8a9765fb46156b0a776dd46b6bf8c Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Sat, 27 Mar 2010 20:19:58 +0100 Subject: [PATCH] lp-shell: + Add support for using different LP API versions. + Add option to login anonymously into LP. doc/lp-shell.1: Update the documentation. --- debian/changelog | 8 ++++--- doc/lp-shell.1 | 27 +++++++++++++++------ lp-shell | 62 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 79 insertions(+), 18 deletions(-) diff --git a/debian/changelog b/debian/changelog index b29ea81..4df03f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,10 @@ ubuntu-dev-tools (0.97) UNRELEASED; urgency=low [ Michael Bienia ] - * lp-shell: Support all to the launchpadlib Python module known service - names. + * lp-shell: + + 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 for different LP API versions. * 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 (Closes: #572091) - -- Michael Bienia Thu, 25 Mar 2010 21:58:47 +0100 + -- Michael Bienia Sat, 27 Mar 2010 20:14:24 +0100 ubuntu-dev-tools (0.96) lucid; urgency=low diff --git a/doc/lp-shell.1 b/doc/lp-shell.1 index d2abf72..611bf21 100644 --- a/doc/lp-shell.1 +++ b/doc/lp-shell.1 @@ -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 lp\-shell \- Open an interactive launchpadlib shell. .SH SYNOPSIS .B lp\-shell -[service] +.RB [ \-a ] +.RI [ service ] +.RI [ "LP API version" ] .SH DESCRIPTION .B lp\-shell opens an interactive Python shell with a launchpadlib.Launchpad object "lp" 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. -If you want to connect to an other Launchpad service, call -.B lp\-shell -with the service name as the second argument. lp-shell supports all services +By default \fBlp\-shell\fR connects to the "\fIedge\fR" Launchpad service +using the "\fI1.0\fR" LP API version. + +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. Currently known are (list can be incomplete or outdated): "production", "edge", "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 .B lp\-shell was written by Martin Pitt . diff --git a/lp-shell b/lp-shell index 391e315..5cdda73 100755 --- a/lp-shell +++ b/lp-shell @@ -1,7 +1,8 @@ -#!/usr/bin/python -i +#!/usr/bin/python -# open an interactive launchpadlib Python shell. If the first command line -# argument is "staging", this will be on staging instead of production. +# Open an interactive launchpadlib Python shell. +# It supports all known LP service instances and API versions. The login +# can optionally happen anonymously. # Author: Martin Pitt # Copyright: (C) 2010 Canonical Ltd. @@ -15,21 +16,66 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 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.uris import lookup_service_root 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: - instance = lookup_service_root(sys.argv[1]) + instance = lookup_service_root(args[0]) except ValueError, 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 # and thus exceptions often bubble up to the top level. sys.excepthook = sys.__excepthook__ + +console = CompleterConsole() +console.interact(banner)