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

Proposed by Barry Warsaw
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 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

Typo: forgot to return something ;)

482. By Barry Warsaw

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
1=== modified file '__init__.py'
2--- __init__.py 2010-09-10 02:46:41 +0000
3+++ __init__.py 2010-09-27 20:42:39 +0000
4@@ -174,5 +174,9 @@
5 SPEC_TYPES.append(RevisionSpec_package)
6
7
8+from bzrlib.plugins.builddeb.urls import register_schemes
9+register_schemes()
10+
11+
12 def load_tests(standard_tests, module, loader):
13 return loader.loadTestsFromModuleNames(['bzrlib.plugins.builddeb.tests'])
14
15=== modified file 'tests/__init__.py'
16--- tests/__init__.py 2010-09-10 02:37:09 +0000
17+++ tests/__init__.py 2010-09-27 20:42:39 +0000
18@@ -128,9 +128,10 @@
19 'test_repack_tarball_extra',
20 'test_revspec',
21 'test_source_distiller',
22+ 'test_tagging',
23 'test_upstream',
24+ 'test_urls',
25 'test_util',
26- 'test_tagging',
27 ]
28 suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i)
29 for i in testmod_names]))
30
31=== added file 'tests/test_urls.py'
32--- tests/test_urls.py 1970-01-01 00:00:00 +0000
33+++ tests/test_urls.py 2010-09-27 20:42:39 +0000
34@@ -0,0 +1,216 @@
35+# test_urls.py -- Test url shortcuts for Ubuntu and Debian source branches
36+# Copyright (C) 2010 Canonical Ltd.
37+#
38+# This file is part of bzr-builddeb.
39+#
40+# bzr-builddeb is free software; you can redistribute it and/or modify
41+# it under the terms of the GNU General Public License as published by
42+# the Free Software Foundation; either version 2 of the License, or
43+# (at your option) any later version.
44+#
45+# bzr-builddeb is distributed in the hope that it will be useful,
46+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+# GNU General Public License for more details.
49+#
50+# You should have received a copy of the GNU General Public License
51+# along with bzr-builddeb; if not, write to the Free Software
52+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
53+
54+from bzrlib import errors
55+from bzrlib.tests import TestCase
56+from bzrlib.plugins.builddeb import urls
57+
58+
59+class TestExpansion(TestCase):
60+ """Test expansions for debuntu schemes."""
61+
62+ def setUp(self):
63+ TestCase.setUp(self)
64+ self.directory = urls.DebuntuDirectory()
65+
66+ # Bogus distro.
67+
68+ def test_bogus_distro(self):
69+ self.assertRaises(errors.InvalidURL,
70+ self.directory._expand, 'gentoo:foo')
71+
72+ def test_trick_bogus_distro_u(self):
73+ self.assertRaises(errors.InvalidURL,
74+ self.directory._expand, 'utube:foo')
75+
76+ def test_trick_bogus_distro_d(self):
77+ self.assertRaises(errors.InvalidURL,
78+ self.directory._expand, 'debuntu:foo')
79+
80+ def test_missing_ubuntu_distroseries(self):
81+ # Launchpad does not hold source packages for Intrepid. Missing or
82+ # bogus distroseries is treated like a project.
83+ self.assertEqual(self.directory._expand('ubuntu:intrepid'),
84+ 'lp:ubuntu/intrepid')
85+
86+ def test_missing_debian_distroseries(self):
87+ # Launchpad does not hold source packages for unstable. Missing or
88+ # bogus distroseries is treated like a project.
89+ self.assertEqual(self.directory._expand('debian:sid'), 'lp:debian/sid')
90+
91+ # Ubuntu Default distro series.
92+
93+ def test_ubuntu_default_distroseries_expansion(self):
94+ self.assertEqual(self.directory._expand('ubuntu:foo'), 'lp:ubuntu/foo')
95+
96+ def test_u_default_distroseries_expansion(self):
97+ self.assertEqual(self.directory._expand('u:foo'), 'lp:ubuntu/foo')
98+
99+ # Maverick
100+
101+ def test_ubuntu_maverick_distroseries_expansion(self):
102+ self.assertEqual(self.directory._expand('ubuntu:maverick/foo'),
103+ 'lp:ubuntu/maverick/foo')
104+
105+ def test_ubuntu_m_distroseries_expansion(self):
106+ self.assertEqual(self.directory._expand('ubuntu:m/foo'),
107+ 'lp:ubuntu/maverick/foo')
108+
109+ def test_u_maverick_distroseries_expansion(self):
110+ self.assertEqual(self.directory._expand('u:maverick/foo'),
111+ 'lp:ubuntu/maverick/foo')
112+
113+ def test_u_m_distroseries_expansion(self):
114+ self.assertEqual(self.directory._expand('u:m/foo'),
115+ 'lp:ubuntu/maverick/foo')
116+
117+ # Lucid
118+
119+ def test_ubuntu_lucid_distroseries_expansion(self):
120+ self.assertEqual(self.directory._expand('ubuntu:lucid/foo'),
121+ 'lp:ubuntu/lucid/foo')
122+
123+ def test_ubuntu_l_distroseries_expansion(self):
124+ self.assertEqual(self.directory._expand('ubuntu:l/foo'),
125+ 'lp:ubuntu/lucid/foo')
126+
127+ def test_u_lucid_distroseries_expansion(self):
128+ self.assertEqual(self.directory._expand('u:lucid/foo'),
129+ 'lp:ubuntu/lucid/foo')
130+
131+ def test_u_l_distroseries_expansion(self):
132+ self.assertEqual(self.directory._expand('u:l/foo'),
133+ 'lp:ubuntu/lucid/foo')
134+
135+ # Karmic
136+
137+ def test_ubuntu_karmic_distroseries_expansion(self):
138+ self.assertEqual(self.directory._expand('ubuntu:karmic/foo'),
139+ 'lp:ubuntu/karmic/foo')
140+
141+ def test_ubuntu_k_distroseries_expansion(self):
142+ self.assertEqual(self.directory._expand('ubuntu:k/foo'),
143+ 'lp:ubuntu/karmic/foo')
144+
145+ def test_u_karmic_distroseries_expansion(self):
146+ self.assertEqual(self.directory._expand('u:karmic/foo'),
147+ 'lp:ubuntu/karmic/foo')
148+
149+ def test_u_k_distroseries_expansion(self):
150+ self.assertEqual(self.directory._expand('u:k/foo'),
151+ 'lp:ubuntu/karmic/foo')
152+
153+ # Jaunty
154+
155+ def test_ubuntu_jaunty_distroseries_expansion(self):
156+ self.assertEqual(self.directory._expand('ubuntu:jaunty/foo'),
157+ 'lp:ubuntu/jaunty/foo')
158+
159+ def test_ubuntu_j_distroseries_expansion(self):
160+ self.assertEqual(self.directory._expand('ubuntu:j/foo'),
161+ 'lp:ubuntu/jaunty/foo')
162+
163+ def test_u_jaunty_distroseries_expansion(self):
164+ self.assertEqual(self.directory._expand('u:jaunty/foo'),
165+ 'lp:ubuntu/jaunty/foo')
166+
167+ def test_u_j_distroseries_expansion(self):
168+ self.assertEqual(self.directory._expand('u:j/foo'),
169+ 'lp:ubuntu/jaunty/foo')
170+
171+ # Hardy
172+
173+ def test_ubuntu_hardy_distroseries_expansion(self):
174+ self.assertEqual(self.directory._expand('ubuntu:hardy/foo'),
175+ 'lp:ubuntu/hardy/foo')
176+
177+ def test_ubuntu_h_distroseries_expansion(self):
178+ self.assertEqual(self.directory._expand('ubuntu:h/foo'),
179+ 'lp:ubuntu/hardy/foo')
180+
181+ def test_u_hardy_distroseries_expansion(self):
182+ self.assertEqual(self.directory._expand('u:hardy/foo'),
183+ 'lp:ubuntu/hardy/foo')
184+
185+ def test_u_h_distroseries_expansion(self):
186+ self.assertEqual(self.directory._expand('u:h/foo'),
187+ 'lp:ubuntu/hardy/foo')
188+
189+ # Dapper
190+
191+ def test_ubuntu_dapper_distroseries_expansion(self):
192+ self.assertEqual(self.directory._expand('ubuntu:dapper/foo'),
193+ 'lp:ubuntu/dapper/foo')
194+
195+ def test_ubuntu_d_distroseries_expansion(self):
196+ self.assertEqual(self.directory._expand('ubuntu:d/foo'),
197+ 'lp:ubuntu/dapper/foo')
198+
199+ def test_u_dapper_distroseries_expansion(self):
200+ self.assertEqual(self.directory._expand('u:dapper/foo'),
201+ 'lp:ubuntu/dapper/foo')
202+
203+ def test_u_d_distroseries_expansion(self):
204+ self.assertEqual(self.directory._expand('u:d/foo'),
205+ 'lp:ubuntu/dapper/foo')
206+
207+ # Debian default distro series.
208+
209+ def test_debian_default_distroseries_expansion(self):
210+ self.assertEqual(self.directory._expand('debian:foo'), 'lp:debian/foo')
211+
212+ def test_d_default_distroseries_expansion(self):
213+ self.assertEqual(self.directory._expand('d:foo'), 'lp:debian/foo')
214+
215+ # Squeeze
216+
217+ def test_debian_squeeze_distroseries_expansion(self):
218+ self.assertEqual(self.directory._expand('debian:squeeze/foo'),
219+ 'lp:debian/squeeze/foo')
220+
221+ def test_debian_s_distroseries_expansion(self):
222+ self.assertEqual(self.directory._expand('debian:s/foo'),
223+ 'lp:debian/squeeze/foo')
224+
225+ def test_d_squeeze_distroseries_expansion(self):
226+ self.assertEqual(self.directory._expand('d:squeeze/foo'),
227+ 'lp:debian/squeeze/foo')
228+
229+ def test_d_s_distroseries_expansion(self):
230+ self.assertEqual(self.directory._expand('d:s/foo'),
231+ 'lp:debian/squeeze/foo')
232+
233+ # Lenny
234+
235+ def test_debian_lenny_distroseries_expansion(self):
236+ self.assertEqual(self.directory._expand('debian:lenny/foo'),
237+ 'lp:debian/lenny/foo')
238+
239+ def test_debian_l_distroseries_expansion(self):
240+ self.assertEqual(self.directory._expand('debian:l/foo'),
241+ 'lp:debian/lenny/foo')
242+
243+ def test_d_lenny_distroseries_expansion(self):
244+ self.assertEqual(self.directory._expand('d:lenny/foo'),
245+ 'lp:debian/lenny/foo')
246+
247+ def test_d_l_distroseries_expansion(self):
248+ self.assertEqual(self.directory._expand('d:l/foo'),
249+ 'lp:debian/lenny/foo')
250+
251
252=== added file 'urls.py'
253--- urls.py 1970-01-01 00:00:00 +0000
254+++ urls.py 2010-09-27 20:42:39 +0000
255@@ -0,0 +1,127 @@
256+# urls.py -- url shortcuts for Ubuntu and Debian source branches
257+# Copyright (C) 2010 Canonical Ltd.
258+#
259+# This file is part of bzr-builddeb.
260+#
261+# bzr-builddeb is free software; you can redistribute it and/or modify
262+# it under the terms of the GNU General Public License as published by
263+# the Free Software Foundation; either version 2 of the License, or
264+# (at your option) any later version.
265+#
266+# bzr-builddeb is distributed in the hope that it will be useful,
267+# but WITHOUT ANY WARRANTY; without even the implied warranty of
268+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
269+# GNU General Public License for more details.
270+#
271+# You should have received a copy of the GNU General Public License
272+# along with bzr-builddeb; if not, write to the Free Software
273+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
274+
275+"""ubuntu: and debian: prefixes for Launchpad lookup.
276+
277+Mappings:
278+
279+ ubuntu:foo -> lp:ubuntu/foo
280+ ubuntu:maverick/foo -> lp:ubuntu/maverick/foo
281+ ubuntu:m/foo -> lp:ubuntu/maverick/foo
282+ u:foo -> lp:ubuntu/foo
283+ u:maverick/foo -> lp:ubuntu/maverick/foo
284+ u:m/foo -> lp:ubuntu/maverick/foo
285+ debian:foo -> lp:debian/foo
286+ debian:squeeze/foo -> lp:debian/squeeze/foo
287+ debian:s/foo -> lp:debian/squeeze/foo
288+ d:foo -> lp:debian/foo
289+ d:squeeze/foo -> lp:debian/squeeze/foo
290+ d:s/foo -> lp:debian/squeeze/foo
291+"""
292+
293+# XXX 2010-09-27 barry: This must remain compatible with the same versions of
294+# Python that Bazaar is compatible with, which at the time of this writing is
295+# 2.4. Which means we cannot use str.format().
296+
297+from urlparse import urlsplit
298+
299+from bzrlib import errors
300+from bzrlib.directory_service import directories
301+from bzrlib.plugins.launchpad.account import get_lp_login
302+from bzrlib.plugins.launchpad.lp_directory import LaunchpadDirectory
303+
304+
305+_ubuntu_series = {
306+ 'maverick': 'maverick',
307+ 'lucid': 'lucid',
308+ 'karmic': 'karmic',
309+ 'jaunty': 'jaunty',
310+ 'hardy': 'hardy',
311+ 'dapper': 'dapper',
312+ 'm': 'maverick',
313+ 'l': 'lucid',
314+ 'k': 'karmic',
315+ 'j': 'jaunty',
316+ 'h': 'hardy',
317+ 'd': 'dapper',
318+ }
319+
320+
321+_debian_series = {
322+ 'lenny': 'lenny',
323+ 'squeeze': 'squeeze',
324+ 'l': 'lenny',
325+ 's': 'squeeze',
326+ }
327+
328+
329+def register_schemes():
330+ directories.register_lazy(
331+ 'ubuntu:', 'plugins.builddeb.urls',
332+ 'DebuntuDirectory',
333+ 'ubuntu: and debian: shortcuts')
334+ directories.register_lazy(
335+ 'u:', 'plugins.builddeb.urls',
336+ 'DebuntuDirectory',
337+ 'ubuntu: and debian: shortcuts')
338+ directories.register_lazy(
339+ 'debian:', 'plugins.builddeb.urls',
340+ 'DebuntuDirectory',
341+ 'ubuntu: and debian: shortcuts')
342+ directories.register_lazy(
343+ 'd:', 'plugins.builddeb.urls',
344+ 'DebuntuDirectory',
345+ 'ubuntu: and debian: shortcuts')
346+
347+
348+class DebuntuDirectory(object):
349+ def _expand(self, url):
350+ parts = urlsplit(url)
351+ if parts.scheme in ('ubuntu', 'u'):
352+ distro = 'ubuntu'
353+ distro_series = _ubuntu_series
354+ elif parts.scheme in ('debian', 'd'):
355+ distro = 'debian'
356+ distro_series = _debian_series
357+ else:
358+ raise errors.InvalidURL(path=url)
359+ # Check first part of path to see if it's a known series. We should
360+ # probably ask Launchpad instead of hard-coding these here.
361+ path_parts = parts.path.split('/')
362+ series = distro_series.get(path_parts[0])
363+ # If there's a series, then the project name is the second part of the
364+ # path. Otherwise, it's the latest series, whatever that is.
365+ #
366+ # XXX 2010-09-27 barry: use str.format() when Python 2.6 is the
367+ # minimum compatible version.
368+ if series is None:
369+ lp_url_template = 'lp:%(distro)s/%(project)s'
370+ project = path_parts[0]
371+ else:
372+ lp_url_template = 'lp:%(distro)s/%(series)s/%(project)s'
373+ project = path_parts[1]
374+ return lp_url_template % dict(
375+ distro=distro,
376+ series=series,
377+ project=project)
378+
379+ def look_up(self, name, url):
380+ """See DirectoryService.look_up"""
381+ lp_url = self._expand(url)
382+ return LaunchpadDirectory().look_up(name, lp_url)

Subscribers

People subscribed via source and target branches