Rev 4070: (jml) Updates to the launchpad plugin, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Mar 2 15:54:15 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4070
revision-id: pqm at pqm.ubuntu.com-20090302155409-89pygn9tisbc0lir
parent: pqm at pqm.ubuntu.com-20090302085957-qvafywhoynyrgxhb
parent: john at arbash-meinel.com-20090302151137-49g5p30mndfxxtv0
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-03-02 15:54:09 +0000
message:
(jml) Updates to the launchpad plugin,
make lp-open work under more circumstances.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/lp_registration.py lp_registration.py-20060315190948-daa617eafe3a8d48
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
bzrlib/plugins/launchpad/test_lp_service.py test_lp_service.py-20080213034527-drf0ucr2x1js3onb-1
------------------------------------------------------------
revno: 4031.2.11
revision-id: john at arbash-meinel.com-20090302151137-49g5p30mndfxxtv0
parent: jml at canonical.com-20090224041922-54j5zkxiyim5pz4r
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Mon 2009-03-02 09:11:37 -0600
message:
Turn a bunch of imports into lazy imports.
Fix a failing test due to a new error message.
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/test_lp_service.py test_lp_service.py-20080213034527-drf0ucr2x1js3onb-1
------------------------------------------------------------
revno: 4031.2.10
revision-id: jml at canonical.com-20090224041922-54j5zkxiyim5pz4r
parent: jml at canonical.com-20090224041559-83yxxb88oa94g4px
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Tue 2009-02-24 15:19:22 +1100
message:
Add one precedence test.
modified:
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.9
revision-id: jml at canonical.com-20090224041559-83yxxb88oa94g4px
parent: jml at canonical.com-20090224040721-xgfzu721jb40q2yg
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Tue 2009-02-24 15:15:59 +1100
message:
Remove unused import.
modified:
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.8
revision-id: jml at canonical.com-20090224040721-xgfzu721jb40q2yg
parent: jml at canonical.com-20090224040353-tk6an68nluxfqs3c
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Tue 2009-02-24 15:07:21 +1100
message:
Say "registered on", not "hosted on".
modified:
bzrlib/plugins/launchpad/lp_registration.py lp_registration.py-20060315190948-daa617eafe3a8d48
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.7
revision-id: jml at canonical.com-20090224040353-tk6an68nluxfqs3c
parent: jml at canonical.com-20090223014807-2ipj1r4opicxfbix
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Tue 2009-02-24 15:03:53 +1100
message:
Move the imports to the top of the module.
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
------------------------------------------------------------
revno: 4031.2.6
revision-id: jml at canonical.com-20090223014807-2ipj1r4opicxfbix
parent: jml at canonical.com-20090223013358-1lilr9qywak27ar6
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Mon 2009-02-23 12:48:07 +1100
message:
Add NEWS about bug fixes.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
------------------------------------------------------------
revno: 4031.2.5
revision-id: jml at canonical.com-20090223013358-1lilr9qywak27ar6
parent: jml at canonical.com-20090223011820-1s0i1qqmrfugcxir
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Mon 2009-02-23 12:33:58 +1100
message:
Refactor the code so we don't do too many remote requests.
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.4
revision-id: jml at canonical.com-20090223011820-1s0i1qqmrfugcxir
parent: jml at canonical.com-20090223011546-948lo3hnnuujlqxw
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Mon 2009-02-23 12:18:20 +1100
message:
Improve some comments.
modified:
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.3
revision-id: jml at canonical.com-20090223011546-948lo3hnnuujlqxw
parent: jml at canonical.com-20090223010957-vjpdum9zqxcujhxt
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Mon 2009-02-23 12:15:46 +1100
message:
Try to open the page for the branch location on the command line if
nothing else works.
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.2
revision-id: jml at canonical.com-20090223010957-vjpdum9zqxcujhxt
parent: jml at canonical.com-20090223010400-q0i9eyojllkm8e86
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Mon 2009-02-23 12:09:57 +1100
message:
Fall-back to push location.
modified:
bzrlib/plugins/launchpad/__init__.py __init__.py-20060315182712-2d5feebd2a1032dc
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
------------------------------------------------------------
revno: 4031.2.1
revision-id: jml at canonical.com-20090223010400-q0i9eyojllkm8e86
parent: pqm at pqm.ubuntu.com-20090221224705-4xupqzb93hneubus
committer: Jonathan Lange <jml at canonical.com>
branch nick: lp-open-fallback
timestamp: Mon 2009-02-23 12:04:00 +1100
message:
Rename tests in anticipation of adding more.
modified:
bzrlib/plugins/launchpad/test_lp_open.py test_lp_open.py-20090125174355-hxrsxh3sj84225qu-1
=== modified file 'NEWS'
--- a/NEWS 2009-03-02 07:20:02 +0000
+++ b/NEWS 2009-03-02 15:54:09 +0000
@@ -62,6 +62,13 @@
* The ``bzr shelve`` prompt now includes a '?' help option to explain the
short options better. (Daniel Watkins, #327429)
+ * ``bzr lp-open`` now falls back to the push location if it cannot find a
+ public location. (Jonathan Lange, #332372)
+
+ * ``bzr lp-open`` will try to find the Launchpad URL for the location
+ passed on the command line. This makes ``bzr lp-open lp:foo`` work as
+ expected. (Jonathan Lange, #332705)
+
BUG FIXES:
* ``bzr missing`` now uses ``Repository.get_revision_delta()`` rather
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2009-02-23 15:29:35 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2009-03-02 15:54:09 +0000
@@ -21,11 +21,29 @@
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
-from bzrlib.branch import Branch
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+import webbrowser
+
+from bzrlib import (
+ branch as _mod_branch,
+ trace,
+ )
+""")
+
from bzrlib.commands import Command, Option, register_command
from bzrlib.directory_service import directories
-from bzrlib.errors import BzrCommandError, NoPublicBranch, NotBranchError
+from bzrlib.errors import (
+ BzrCommandError,
+ InvalidURL,
+ NoPublicBranch,
+ NotBranchError,
+ )
from bzrlib.help_topics import topic_registry
+from bzrlib.plugins.launchpad.lp_registration import (
+ LaunchpadService,
+ NotLaunchpadBranch,
+ )
class cmd_register_branch(Command):
@@ -91,7 +109,7 @@
DryRunLaunchpadService)
if public_url is None:
try:
- b = Branch.open_containing('.')[0]
+ b = _mod_branch.Branch.open_containing('.')[0]
except NotBranchError:
raise BzrCommandError('register-branch requires a public '
'branch url - see bzr help register-branch.')
@@ -127,7 +145,6 @@
register_command(cmd_register_branch)
-# XXX: Make notes to test this.
class cmd_launchpad_open(Command):
"""Open a Launchpad branch page in your web browser."""
@@ -139,19 +156,33 @@
]
takes_args = ['location?']
+ def _possible_locations(self, location):
+ """Yield possible external locations for the branch at 'location'."""
+ yield location
+ try:
+ branch = _mod_branch.Branch.open(location)
+ except NotBranchError:
+ return
+ branch_url = branch.get_public_branch()
+ if branch_url is not None:
+ yield branch_url
+ branch_url = branch.get_push_location()
+ if branch_url is not None:
+ yield branch_url
+
+ def _get_web_url(self, service, location):
+ for branch_url in self._possible_locations(location):
+ try:
+ return service.get_web_url_from_branch_url(branch_url)
+ except (NotLaunchpadBranch, InvalidURL):
+ pass
+ raise NotLaunchpadBranch(branch_url)
+
def run(self, location=None, dry_run=False):
- from bzrlib.plugins.launchpad.lp_registration import LaunchpadService
- from bzrlib.trace import note
- import webbrowser
if location is None:
location = u'.'
- branch = Branch.open(location)
- branch_url = branch.get_public_branch()
- if branch_url is None:
- raise NoPublicBranch(branch)
- service = LaunchpadService()
- web_url = service.get_web_url_from_branch_url(branch_url)
- note('Opening %s in web browser' % web_url)
+ web_url = self._get_web_url(LaunchpadService(), location)
+ trace.note('Opening %s in web browser' % web_url)
if not dry_run:
webbrowser.open(web_url)
=== modified file 'bzrlib/plugins/launchpad/lp_registration.py'
--- a/bzrlib/plugins/launchpad/lp_registration.py 2009-02-23 15:29:35 +0000
+++ b/bzrlib/plugins/launchpad/lp_registration.py 2009-03-02 15:54:09 +0000
@@ -47,7 +47,7 @@
class NotLaunchpadBranch(errors.BzrError):
- _fmt = "%(url)s is not hosted on Launchpad."
+ _fmt = "%(url)s is not registered on Launchpad."
def __init__(self, url):
errors.BzrError.__init__(self, url=url)
=== modified file 'bzrlib/plugins/launchpad/test_lp_open.py'
--- a/bzrlib/plugins/launchpad/test_lp_open.py 2009-01-25 17:44:01 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_open.py 2009-02-24 04:19:22 +0000
@@ -16,8 +16,6 @@
"""Tests for the launchpad-open command."""
-from bzrlib.osutils import abspath
-
from bzrlib.tests import TestCaseWithTransport
@@ -29,16 +27,17 @@
return err.splitlines()
def test_non_branch(self):
- # Running lp-open on a non-branch prints a simple error.
+ # If given a branch with no public or push locations, lp-open will try
+ # to guess the Launchpad page for the given URL / path. If it cannot
+ # find one, it will raise an error.
self.assertEqual(
- ['bzr: ERROR: Not a branch: "%s/".' % abspath('.')],
+ ['bzr: ERROR: . is not registered on Launchpad.'],
self.run_open('.', retcode=3))
- def test_no_public_location(self):
+ def test_no_public_location_no_push_location(self):
self.make_branch('not-public')
self.assertEqual(
- ['bzr: ERROR: There is no public branch set for "%s/".'
- % abspath('not-public')],
+ ['bzr: ERROR: not-public is not registered on Launchpad.'],
self.run_open('not-public', retcode=3))
def test_non_launchpad_branch(self):
@@ -46,14 +45,45 @@
url = 'http://example.com/non-lp'
branch.set_public_branch(url)
self.assertEqual(
- ['bzr: ERROR: %s is not hosted on Launchpad.' % url],
+ ['bzr: ERROR: %s is not registered on Launchpad.' % url],
self.run_open('non-lp', retcode=3))
- def test_launchpad_branch(self):
- branch = self.make_branch('lp')
- branch.set_public_branch(
- 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
- self.assertEqual(
- ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
- 'browser'],
- self.run_open('lp'))
+ def test_launchpad_branch_with_public_location(self):
+ branch = self.make_branch('lp')
+ branch.set_public_branch(
+ 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
+ self.assertEqual(
+ ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
+ 'browser'],
+ self.run_open('lp'))
+
+ def test_launchpad_branch_with_public_and_push_location(self):
+ branch = self.make_branch('lp')
+ branch.set_public_branch(
+ 'bzr+ssh://bazaar.launchpad.net/~foo/bar/public')
+ branch.set_push_location(
+ 'bzr+ssh://bazaar.launchpad.net/~foo/bar/push')
+ self.assertEqual(
+ ['Opening https://code.edge.launchpad.net/~foo/bar/public in web '
+ 'browser'],
+ self.run_open('lp'))
+
+ def test_launchpad_branch_with_no_public_but_with_push(self):
+ # lp-open falls back to the push location if it cannot find a public
+ # location.
+ branch = self.make_branch('lp')
+ branch.set_push_location(
+ 'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
+ self.assertEqual(
+ ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
+ 'browser'],
+ self.run_open('lp'))
+
+ def test_launchpad_branch_with_no_public_no_push(self):
+ # If lp-open is given a branch URL and that branch has no public
+ # location and no push location, then just try to look up the
+ # Launchpad page for that URL.
+ self.assertEqual(
+ ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
+ 'browser'],
+ self.run_open('bzr+ssh://bazaar.launchpad.net/~foo/bar/baz'))
=== modified file 'bzrlib/plugins/launchpad/test_lp_service.py'
--- a/bzrlib/plugins/launchpad/test_lp_service.py 2009-01-25 17:43:47 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_service.py 2009-03-02 15:11:37 +0000
@@ -126,7 +126,7 @@
NotLaunchpadBranch, service.get_web_url_from_branch_url,
'bzr+ssh://example.com/~foo/bar/baz')
self.assertEqual(
- 'bzr+ssh://example.com/~foo/bar/baz is not hosted on Launchpad.',
+ 'bzr+ssh://example.com/~foo/bar/baz is not registered on Launchpad.',
str(error))
def test_dodgy_launchpad_url(self):
More information about the bazaar-commits
mailing list