Rev 2935: (James Henstridge) add a command for managing the Launchpad user ID in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Oct 24 10:06:33 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2935
revision-id: pqm at pqm.ubuntu.com-20071024090631-gwml8hkp57feuoy3
parent: pqm at pqm.ubuntu.com-20071024072800-p2qtv2632xrbrs02
parent: ian.clatworthy at internode.on.net-20071024081218-8hmyh67lkiz22exo
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-10-24 10:06:31 +0100
message:
(James Henstridge) add a command for managing the Launchpad user ID
added:
bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
bzrlib/plugins/launchpad/test_account.py test_account.py-20071011033320-50y6vfftywf4yllw-2
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/test_register.py test_register.py-20060315182712-40f5dda945c829a8
------------------------------------------------------------
revno: 2934.1.1
merged: ian.clatworthy at internode.on.net-20071024081218-8hmyh67lkiz22exo
parent: pqm at pqm.ubuntu.com-20071024072800-p2qtv2632xrbrs02
parent: james at jamesh.id.au-20071018085819-zv64jvki41van9fq
committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
branch nick: ianc-integration
timestamp: Wed 2007-10-24 18:12:18 +1000
message:
(James Henstridge) add a command for managing the Launchpad user ID
------------------------------------------------------------
revno: 2898.3.10
merged: james at jamesh.id.au-20071018085819-zv64jvki41van9fq
parent: james at jamesh.id.au-20071012044216-1aystcylm32fjb67
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Thu 2007-10-18 21:58:19 +1300
message:
Make LaunchpadAccountTests a TestCaseInTempDir so that config changes
don't leak through to subsequent tests.
------------------------------------------------------------
revno: 2898.3.9
merged: james at jamesh.id.au-20071012044216-1aystcylm32fjb67
parent: james at jamesh.id.au-20071012031830-wjdzorg06j4nidpr
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Fri 2007-10-12 17:42:16 +1300
message:
* Add a simple NEWS item for the command.
* May launchpad-login return an error if no user is configured.
------------------------------------------------------------
revno: 2898.3.8
merged: james at jamesh.id.au-20071012031830-wjdzorg06j4nidpr
parent: james at jamesh.id.au-20071012025418-14tofx4n8d69uxsh
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Fri 2007-10-12 16:18:30 +1300
message:
Get rid of relative imports in Launchpad plugin.
------------------------------------------------------------
revno: 2898.3.7
merged: james at jamesh.id.au-20071012025418-14tofx4n8d69uxsh
parent: james at jamesh.id.au-20071012015858-5ryp4uy3sxviwztl
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Fri 2007-10-12 15:54:18 +1300
message:
* Add tests for account.py exception messages.
* Fix docstring on set_lp_login()
* use False as default value for no_check option to plugin.
------------------------------------------------------------
revno: 2898.3.6
merged: james at jamesh.id.au-20071012015858-5ryp4uy3sxviwztl
parent: james at jamesh.id.au-20071011231604-lturuvqizllfab3f
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Fri 2007-10-12 14:58:58 +1300
message:
Rename function arguments that are only intended for use by the tests.
------------------------------------------------------------
revno: 2898.3.5
merged: james at jamesh.id.au-20071011231604-lturuvqizllfab3f
parent: james at jamesh.id.au-20071011205810-gduc1htgwr7dzasi
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Fri 2007-10-12 12:16:04 +1300
message:
Add copyright headers to new files
------------------------------------------------------------
revno: 2898.3.4
merged: james at jamesh.id.au-20071011205810-gduc1htgwr7dzasi
parent: james at jamesh.id.au-20071011043626-qb6kk43qy12201x9
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Fri 2007-10-12 09:58:10 +1300
message:
Cleanups from mini-review by Tim.
------------------------------------------------------------
revno: 2898.3.3
merged: james at jamesh.id.au-20071011043626-qb6kk43qy12201x9
parent: james at jamesh.id.au-20071011043518-hh6wp24w2oc3c73v
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Thu 2007-10-11 17:36:26 +1300
message:
Add launchpad-login command.
------------------------------------------------------------
revno: 2898.3.2
merged: james at jamesh.id.au-20071011043518-hh6wp24w2oc3c73v
parent: james at jamesh.id.au-20071011033403-m8gfas0yzbe5a7a0
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Thu 2007-10-11 17:35:18 +1300
message:
Rename functions.
------------------------------------------------------------
revno: 2898.3.1
merged: james at jamesh.id.au-20071011033403-m8gfas0yzbe5a7a0
parent: pqm at pqm.ubuntu.com-20071009044446-uliu5z9a52bzmps8
committer: James Henstridge <james at jamesh.id.au>
branch nick: bzr.lp-whoami
timestamp: Thu 2007-10-11 16:34:03 +1300
message:
API for storing and retrieving the Launchpad user ID that will be used
by other Bazaar functions.
=== added file 'bzrlib/plugins/launchpad/account.py'
--- a/bzrlib/plugins/launchpad/account.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/plugins/launchpad/account.py 2007-10-24 08:12:18 +0000
@@ -0,0 +1,70 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Functions to manage the user's Launchpad user ID.
+
+This allows the user to configure their Launchpad user ID once, rather
+than once for each place that needs to take it into account.
+"""
+
+from bzrlib import errors
+from bzrlib.config import GlobalConfig
+from bzrlib.transport import get_transport
+
+
+LAUNCHPAD_BASE = 'https://launchpad.net/'
+
+
+class UnknownLaunchpadUsername(errors.BzrError):
+ _fmt = "The user name %(user)s is not registered on Launchpad."
+
+
+class NoRegisteredSSHKeys(errors.BzrError):
+ _fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
+
+
+def get_lp_login(_config=None):
+ """Return the user's Launchpad username"""
+ if _config is None:
+ _config = GlobalConfig()
+
+ return _config.get_user_option('launchpad_username')
+
+
+def set_lp_login(username, _config=None):
+ """Set the user's Launchpad username"""
+ if _config is None:
+ _config = GlobalConfig()
+
+ _config.set_user_option('launchpad_username', username)
+
+
+def check_lp_login(username, _transport=None):
+ """Check whether the given Launchpad username is okay.
+
+ This will check for both existence and whether the user has
+ uploaded SSH keys.
+ """
+ if _transport is None:
+ _transport = get_transport(LAUNCHPAD_BASE)
+
+ try:
+ data = _transport.get_bytes('~%s/+sshkeys' % username)
+ except errors.NoSuchFile:
+ raise UnknownLaunchpadUsername(user=username)
+
+ if not data:
+ raise NoRegisteredSSHKeys(user=username)
=== added file 'bzrlib/plugins/launchpad/test_account.py'
--- a/bzrlib/plugins/launchpad/test_account.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/plugins/launchpad/test_account.py 2007-10-18 08:58:19 +0000
@@ -0,0 +1,85 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for Launchpad user ID management functions."""
+
+from cStringIO import StringIO
+
+from bzrlib import config
+from bzrlib.tests import TestCaseInTempDir, TestCaseWithMemoryTransport
+from bzrlib.plugins.launchpad import account
+
+
+class LaunchpadAccountTests(TestCaseInTempDir):
+
+ def setup_config(self, text):
+ my_config = config.GlobalConfig()
+ config_file = StringIO(text)
+ my_config._get_parser(config_file)
+ return my_config
+
+ def test_get_lp_login_unconfigured(self):
+ # Test that get_lp_login() returns None if no username has
+ # been configured.
+ my_config = self.setup_config('')
+ self.assertEqual(None, account.get_lp_login(my_config))
+
+ def test_get_lp_login(self):
+ # Test that get_lp_login() returns the configured username
+ my_config = self.setup_config(
+ '[DEFAULT]\nlaunchpad_username=test-user\n')
+ self.assertEqual('test-user', account.get_lp_login(my_config))
+
+ def test_set_lp_login(self):
+ # Test that set_lp_login() updates the config file.
+ my_config = self.setup_config('')
+ self.assertEqual(None, my_config.get_user_option('launchpad_username'))
+ account.set_lp_login('test-user', my_config)
+ self.assertEqual(
+ 'test-user', my_config.get_user_option('launchpad_username'))
+
+ def test_unknown_launchpad_username(self):
+ # Test formatting of UnknownLaunchpadUsername exception
+ error = account.UnknownLaunchpadUsername(user='test-user')
+ self.assertEqualDiff('The user name test-user is not registered '
+ 'on Launchpad.', str(error))
+
+ def test_no_registered_ssh_keys(self):
+ # Test formatting of NoRegisteredSSHKeys exception
+ error = account.NoRegisteredSSHKeys(user='test-user')
+ self.assertEqualDiff('The user test-user has not registered any '
+ 'SSH keys with Launchpad.', str(error))
+
+
+class CheckAccountTests(TestCaseWithMemoryTransport):
+
+ def test_check_lp_login_valid_user(self):
+ transport = self.get_transport()
+ transport.mkdir('~test-user')
+ transport.put_bytes('~test-user/+sshkeys', 'some keys here')
+ account.check_lp_login('test-user', transport)
+
+ def test_check_lp_login_no_user(self):
+ transport = self.get_transport()
+ self.assertRaises(account.UnknownLaunchpadUsername,
+ account.check_lp_login, 'test-user', transport)
+
+ def test_check_lp_login_no_ssh_keys(self):
+ transport = self.get_transport()
+ transport.mkdir('~test-user')
+ transport.put_bytes('~test-user/+sshkeys', '')
+ self.assertRaises(account.NoRegisteredSSHKeys,
+ account.check_lp_login, 'test-user', transport)
=== modified file 'NEWS'
--- a/NEWS 2007-10-24 06:48:13 +0000
+++ b/NEWS 2007-10-24 08:12:18 +0000
@@ -39,6 +39,10 @@
remote bzr locations than BZR_REMOTE_PATH environment variable.
(Aaron Bentley)
+ * New ``launchpad-login`` command to tell Bazaar your Launchpad
+ user ID. This can then be used by other functions of the
+ Launchpad plugin. (James Henstridge)
+
PERFORMANCE:
* Commit in quiet mode is now slightly faster as the information to
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2007-07-11 03:20:03 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2007-10-24 08:12:18 +0000
@@ -14,11 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Launchpad.net integration plugin for Bazaar
-
-To install this file, put the 'bzr_lp' directory, or a symlink to it,
-in your ~/.bazaar/plugins/ directory.
-"""
+"""Launchpad.net integration plugin for Bazaar."""
# The XMLRPC server address can be overridden by setting the environment
# variable $BZR_LP_XMLRPL_URL
@@ -84,7 +80,7 @@
author='',
link_bug=None,
dry_run=False):
- from lp_registration import (
+ from bzrlib.plugins.launchpad.lp_registration import (
LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
DryRunLaunchpadService)
rego = BranchRegistrationRequest(branch_url=branch_url,
@@ -114,6 +110,51 @@
register_command(cmd_register_branch)
+
+class cmd_launchpad_login(Command):
+ """Show or set the Launchpad user ID.
+
+ When communicating with Launchpad, some commands need to know your
+ Launchpad user ID. This command can be used to set or show the
+ user ID that Bazaar will use for such communication.
+
+ :Examples:
+ Show the Launchpad ID of the current user::
+
+ bzr launchpad-login
+
+ Set the Launchpad ID of the current user to 'bob'::
+
+ bzr launchpad-login bob
+ """
+ aliases = ['lp-login']
+ takes_args = ['name?']
+ takes_options = [
+ Option('no-check',
+ "Don't check that the user name is valid."),
+ ]
+
+ def run(self, name=None, no_check=False):
+ from bzrlib.plugins.launchpad import account
+ check_account = not no_check
+
+ if name is None:
+ username = account.get_lp_login()
+ if username:
+ if check_account:
+ account.check_lp_login(username)
+ self.outf.write(username + '\n')
+ else:
+ self.outf.write('No Launchpad user ID configured.\n')
+ return 1
+ else:
+ if check_account:
+ account.check_lp_login(name)
+ account.set_lp_login(name)
+
+register_command(cmd_launchpad_login)
+
+
register_lazy_transport(
'lp:',
'bzrlib.plugins.launchpad.lp_indirect',
@@ -127,12 +168,12 @@
def test_suite():
"""Called by bzrlib to fetch tests for this plugin"""
from unittest import TestSuite, TestLoader
- import test_register
- import test_lp_indirect
+ from bzrlib.plugins.launchpad import (
+ test_register, test_lp_indirect, test_account)
loader = TestLoader()
suite = TestSuite()
- for m in [test_register, test_lp_indirect]:
+ for m in [test_register, test_lp_indirect, test_account]:
suite.addTests(loader.loadTestsFromModule(m))
return suite
=== modified file 'bzrlib/plugins/launchpad/test_register.py'
--- a/bzrlib/plugins/launchpad/test_register.py 2007-07-04 09:27:22 +0000
+++ b/bzrlib/plugins/launchpad/test_register.py 2007-10-12 03:18:30 +0000
@@ -22,7 +22,7 @@
from bzrlib.tests import TestCase, TestSkipped
# local import
-from lp_registration import (
+from bzrlib.plugins.launchpad.lp_registration import (
BaseRequest,
BranchBugLinkRequest,
BranchRegistrationRequest,
More information about the bazaar-commits
mailing list