Merge lp:~barry/bzr-builddeb/609186-urls into lp:bzr-builddeb

Proposed by Barry Warsaw on 2010-09-27
Status: Work in progress
Proposed branch: lp:~barry/bzr-builddeb/609186-urls
Merge into: lp:bzr-builddeb
Diff against target: 382 lines (+349/-1)
4 files modified
__init__.py (+4/-0)
tests/__init__.py (+2/-1)
tests/test_urls.py (+216/-0)
urls.py (+127/-0)
To merge this branch: bzr merge lp:~barry/bzr-builddeb/609186-urls
Reviewer Review Type Date Requested Status
Bzr-builddeb-hackers 2010-09-27 Pending
Review via email: mp+36787@code.launchpad.net

Description of the change

This branch implements the easy part of bug 609186. It provides ubuntu: and debian: url schemes (and u: and d: shortcuts) for getting at source branches in Launchpad. It doesn't do the fancier stuff suggested in the bug - that's for another time.

To post a comment you must log in.

Unmerged revisions

483. By Barry Warsaw on 2010-09-27

Typo: forgot to return something ;)

482. By Barry Warsaw on 2010-09-27

LP: #609186

Add ubuntu: u: debian: and d: schemes, along with distroseries support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '__init__.py'
--- __init__.py 2010-09-10 02:46:41 +0000
+++ __init__.py 2010-09-27 20:42:39 +0000
@@ -174,5 +174,9 @@
174 SPEC_TYPES.append(RevisionSpec_package)174 SPEC_TYPES.append(RevisionSpec_package)
175175
176176
177from bzrlib.plugins.builddeb.urls import register_schemes
178register_schemes()
179
180
177def load_tests(standard_tests, module, loader):181def load_tests(standard_tests, module, loader):
178 return loader.loadTestsFromModuleNames(['bzrlib.plugins.builddeb.tests'])182 return loader.loadTestsFromModuleNames(['bzrlib.plugins.builddeb.tests'])
179183
=== modified file 'tests/__init__.py'
--- tests/__init__.py 2010-09-10 02:37:09 +0000
+++ tests/__init__.py 2010-09-27 20:42:39 +0000
@@ -128,9 +128,10 @@
128 'test_repack_tarball_extra',128 'test_repack_tarball_extra',
129 'test_revspec',129 'test_revspec',
130 'test_source_distiller',130 'test_source_distiller',
131 'test_tagging',
131 'test_upstream',132 'test_upstream',
133 'test_urls',
132 'test_util',134 'test_util',
133 'test_tagging',
134 ]135 ]
135 suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i)136 suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i)
136 for i in testmod_names]))137 for i in testmod_names]))
137138
=== added file 'tests/test_urls.py'
--- tests/test_urls.py 1970-01-01 00:00:00 +0000
+++ tests/test_urls.py 2010-09-27 20:42:39 +0000
@@ -0,0 +1,216 @@
1# test_urls.py -- Test url shortcuts for Ubuntu and Debian source branches
2# Copyright (C) 2010 Canonical Ltd.
3#
4# This file is part of bzr-builddeb.
5#
6# bzr-builddeb is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# bzr-builddeb is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with bzr-builddeb; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20from bzrlib import errors
21from bzrlib.tests import TestCase
22from bzrlib.plugins.builddeb import urls
23
24
25class TestExpansion(TestCase):
26 """Test expansions for debuntu schemes."""
27
28 def setUp(self):
29 TestCase.setUp(self)
30 self.directory = urls.DebuntuDirectory()
31
32 # Bogus distro.
33
34 def test_bogus_distro(self):
35 self.assertRaises(errors.InvalidURL,
36 self.directory._expand, 'gentoo:foo')
37
38 def test_trick_bogus_distro_u(self):
39 self.assertRaises(errors.InvalidURL,
40 self.directory._expand, 'utube:foo')
41
42 def test_trick_bogus_distro_d(self):
43 self.assertRaises(errors.InvalidURL,
44 self.directory._expand, 'debuntu:foo')
45
46 def test_missing_ubuntu_distroseries(self):
47 # Launchpad does not hold source packages for Intrepid. Missing or
48 # bogus distroseries is treated like a project.
49 self.assertEqual(self.directory._expand('ubuntu:intrepid'),
50 'lp:ubuntu/intrepid')
51
52 def test_missing_debian_distroseries(self):
53 # Launchpad does not hold source packages for unstable. Missing or
54 # bogus distroseries is treated like a project.
55 self.assertEqual(self.directory._expand('debian:sid'), 'lp:debian/sid')
56
57 # Ubuntu Default distro series.
58
59 def test_ubuntu_default_distroseries_expansion(self):
60 self.assertEqual(self.directory._expand('ubuntu:foo'), 'lp:ubuntu/foo')
61
62 def test_u_default_distroseries_expansion(self):
63 self.assertEqual(self.directory._expand('u:foo'), 'lp:ubuntu/foo')
64
65 # Maverick
66
67 def test_ubuntu_maverick_distroseries_expansion(self):
68 self.assertEqual(self.directory._expand('ubuntu:maverick/foo'),
69 'lp:ubuntu/maverick/foo')
70
71 def test_ubuntu_m_distroseries_expansion(self):
72 self.assertEqual(self.directory._expand('ubuntu:m/foo'),
73 'lp:ubuntu/maverick/foo')
74
75 def test_u_maverick_distroseries_expansion(self):
76 self.assertEqual(self.directory._expand('u:maverick/foo'),
77 'lp:ubuntu/maverick/foo')
78
79 def test_u_m_distroseries_expansion(self):
80 self.assertEqual(self.directory._expand('u:m/foo'),
81 'lp:ubuntu/maverick/foo')
82
83 # Lucid
84
85 def test_ubuntu_lucid_distroseries_expansion(self):
86 self.assertEqual(self.directory._expand('ubuntu:lucid/foo'),
87 'lp:ubuntu/lucid/foo')
88
89 def test_ubuntu_l_distroseries_expansion(self):
90 self.assertEqual(self.directory._expand('ubuntu:l/foo'),
91 'lp:ubuntu/lucid/foo')
92
93 def test_u_lucid_distroseries_expansion(self):
94 self.assertEqual(self.directory._expand('u:lucid/foo'),
95 'lp:ubuntu/lucid/foo')
96
97 def test_u_l_distroseries_expansion(self):
98 self.assertEqual(self.directory._expand('u:l/foo'),
99 'lp:ubuntu/lucid/foo')
100
101 # Karmic
102
103 def test_ubuntu_karmic_distroseries_expansion(self):
104 self.assertEqual(self.directory._expand('ubuntu:karmic/foo'),
105 'lp:ubuntu/karmic/foo')
106
107 def test_ubuntu_k_distroseries_expansion(self):
108 self.assertEqual(self.directory._expand('ubuntu:k/foo'),
109 'lp:ubuntu/karmic/foo')
110
111 def test_u_karmic_distroseries_expansion(self):
112 self.assertEqual(self.directory._expand('u:karmic/foo'),
113 'lp:ubuntu/karmic/foo')
114
115 def test_u_k_distroseries_expansion(self):
116 self.assertEqual(self.directory._expand('u:k/foo'),
117 'lp:ubuntu/karmic/foo')
118
119 # Jaunty
120
121 def test_ubuntu_jaunty_distroseries_expansion(self):
122 self.assertEqual(self.directory._expand('ubuntu:jaunty/foo'),
123 'lp:ubuntu/jaunty/foo')
124
125 def test_ubuntu_j_distroseries_expansion(self):
126 self.assertEqual(self.directory._expand('ubuntu:j/foo'),
127 'lp:ubuntu/jaunty/foo')
128
129 def test_u_jaunty_distroseries_expansion(self):
130 self.assertEqual(self.directory._expand('u:jaunty/foo'),
131 'lp:ubuntu/jaunty/foo')
132
133 def test_u_j_distroseries_expansion(self):
134 self.assertEqual(self.directory._expand('u:j/foo'),
135 'lp:ubuntu/jaunty/foo')
136
137 # Hardy
138
139 def test_ubuntu_hardy_distroseries_expansion(self):
140 self.assertEqual(self.directory._expand('ubuntu:hardy/foo'),
141 'lp:ubuntu/hardy/foo')
142
143 def test_ubuntu_h_distroseries_expansion(self):
144 self.assertEqual(self.directory._expand('ubuntu:h/foo'),
145 'lp:ubuntu/hardy/foo')
146
147 def test_u_hardy_distroseries_expansion(self):
148 self.assertEqual(self.directory._expand('u:hardy/foo'),
149 'lp:ubuntu/hardy/foo')
150
151 def test_u_h_distroseries_expansion(self):
152 self.assertEqual(self.directory._expand('u:h/foo'),
153 'lp:ubuntu/hardy/foo')
154
155 # Dapper
156
157 def test_ubuntu_dapper_distroseries_expansion(self):
158 self.assertEqual(self.directory._expand('ubuntu:dapper/foo'),
159 'lp:ubuntu/dapper/foo')
160
161 def test_ubuntu_d_distroseries_expansion(self):
162 self.assertEqual(self.directory._expand('ubuntu:d/foo'),
163 'lp:ubuntu/dapper/foo')
164
165 def test_u_dapper_distroseries_expansion(self):
166 self.assertEqual(self.directory._expand('u:dapper/foo'),
167 'lp:ubuntu/dapper/foo')
168
169 def test_u_d_distroseries_expansion(self):
170 self.assertEqual(self.directory._expand('u:d/foo'),
171 'lp:ubuntu/dapper/foo')
172
173 # Debian default distro series.
174
175 def test_debian_default_distroseries_expansion(self):
176 self.assertEqual(self.directory._expand('debian:foo'), 'lp:debian/foo')
177
178 def test_d_default_distroseries_expansion(self):
179 self.assertEqual(self.directory._expand('d:foo'), 'lp:debian/foo')
180
181 # Squeeze
182
183 def test_debian_squeeze_distroseries_expansion(self):
184 self.assertEqual(self.directory._expand('debian:squeeze/foo'),
185 'lp:debian/squeeze/foo')
186
187 def test_debian_s_distroseries_expansion(self):
188 self.assertEqual(self.directory._expand('debian:s/foo'),
189 'lp:debian/squeeze/foo')
190
191 def test_d_squeeze_distroseries_expansion(self):
192 self.assertEqual(self.directory._expand('d:squeeze/foo'),
193 'lp:debian/squeeze/foo')
194
195 def test_d_s_distroseries_expansion(self):
196 self.assertEqual(self.directory._expand('d:s/foo'),
197 'lp:debian/squeeze/foo')
198
199 # Lenny
200
201 def test_debian_lenny_distroseries_expansion(self):
202 self.assertEqual(self.directory._expand('debian:lenny/foo'),
203 'lp:debian/lenny/foo')
204
205 def test_debian_l_distroseries_expansion(self):
206 self.assertEqual(self.directory._expand('debian:l/foo'),
207 'lp:debian/lenny/foo')
208
209 def test_d_lenny_distroseries_expansion(self):
210 self.assertEqual(self.directory._expand('d:lenny/foo'),
211 'lp:debian/lenny/foo')
212
213 def test_d_l_distroseries_expansion(self):
214 self.assertEqual(self.directory._expand('d:l/foo'),
215 'lp:debian/lenny/foo')
216
0217
=== added file 'urls.py'
--- urls.py 1970-01-01 00:00:00 +0000
+++ urls.py 2010-09-27 20:42:39 +0000
@@ -0,0 +1,127 @@
1# urls.py -- url shortcuts for Ubuntu and Debian source branches
2# Copyright (C) 2010 Canonical Ltd.
3#
4# This file is part of bzr-builddeb.
5#
6# bzr-builddeb is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# bzr-builddeb is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with bzr-builddeb; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20"""ubuntu: and debian: prefixes for Launchpad lookup.
21
22Mappings:
23
24 ubuntu:foo -> lp:ubuntu/foo
25 ubuntu:maverick/foo -> lp:ubuntu/maverick/foo
26 ubuntu:m/foo -> lp:ubuntu/maverick/foo
27 u:foo -> lp:ubuntu/foo
28 u:maverick/foo -> lp:ubuntu/maverick/foo
29 u:m/foo -> lp:ubuntu/maverick/foo
30 debian:foo -> lp:debian/foo
31 debian:squeeze/foo -> lp:debian/squeeze/foo
32 debian:s/foo -> lp:debian/squeeze/foo
33 d:foo -> lp:debian/foo
34 d:squeeze/foo -> lp:debian/squeeze/foo
35 d:s/foo -> lp:debian/squeeze/foo
36"""
37
38# XXX 2010-09-27 barry: This must remain compatible with the same versions of
39# Python that Bazaar is compatible with, which at the time of this writing is
40# 2.4. Which means we cannot use str.format().
41
42from urlparse import urlsplit
43
44from bzrlib import errors
45from bzrlib.directory_service import directories
46from bzrlib.plugins.launchpad.account import get_lp_login
47from bzrlib.plugins.launchpad.lp_directory import LaunchpadDirectory
48
49
50_ubuntu_series = {
51 'maverick': 'maverick',
52 'lucid': 'lucid',
53 'karmic': 'karmic',
54 'jaunty': 'jaunty',
55 'hardy': 'hardy',
56 'dapper': 'dapper',
57 'm': 'maverick',
58 'l': 'lucid',
59 'k': 'karmic',
60 'j': 'jaunty',
61 'h': 'hardy',
62 'd': 'dapper',
63 }
64
65
66_debian_series = {
67 'lenny': 'lenny',
68 'squeeze': 'squeeze',
69 'l': 'lenny',
70 's': 'squeeze',
71 }
72
73
74def register_schemes():
75 directories.register_lazy(
76 'ubuntu:', 'plugins.builddeb.urls',
77 'DebuntuDirectory',
78 'ubuntu: and debian: shortcuts')
79 directories.register_lazy(
80 'u:', 'plugins.builddeb.urls',
81 'DebuntuDirectory',
82 'ubuntu: and debian: shortcuts')
83 directories.register_lazy(
84 'debian:', 'plugins.builddeb.urls',
85 'DebuntuDirectory',
86 'ubuntu: and debian: shortcuts')
87 directories.register_lazy(
88 'd:', 'plugins.builddeb.urls',
89 'DebuntuDirectory',
90 'ubuntu: and debian: shortcuts')
91
92
93class DebuntuDirectory(object):
94 def _expand(self, url):
95 parts = urlsplit(url)
96 if parts.scheme in ('ubuntu', 'u'):
97 distro = 'ubuntu'
98 distro_series = _ubuntu_series
99 elif parts.scheme in ('debian', 'd'):
100 distro = 'debian'
101 distro_series = _debian_series
102 else:
103 raise errors.InvalidURL(path=url)
104 # Check first part of path to see if it's a known series. We should
105 # probably ask Launchpad instead of hard-coding these here.
106 path_parts = parts.path.split('/')
107 series = distro_series.get(path_parts[0])
108 # If there's a series, then the project name is the second part of the
109 # path. Otherwise, it's the latest series, whatever that is.
110 #
111 # XXX 2010-09-27 barry: use str.format() when Python 2.6 is the
112 # minimum compatible version.
113 if series is None:
114 lp_url_template = 'lp:%(distro)s/%(project)s'
115 project = path_parts[0]
116 else:
117 lp_url_template = 'lp:%(distro)s/%(series)s/%(project)s'
118 project = path_parts[1]
119 return lp_url_template % dict(
120 distro=distro,
121 series=series,
122 project=project)
123
124 def look_up(self, name, url):
125 """See DirectoryService.look_up"""
126 lp_url = self._expand(url)
127 return LaunchpadDirectory().look_up(name, lp_url)

Subscribers

People subscribed via source and target branches