Merge lp:~cjwatson/launchpad/ppa-archive-reference-alias into lp:launchpad

Proposed by Colin Watson on 2015-03-12
Status: Merged
Approved by: Colin Watson on 2015-03-13
Approved revision: no longer in the source branch.
Merged at revision: 17391
Proposed branch: lp:~cjwatson/launchpad/ppa-archive-reference-alias
Merge into: lp:launchpad
Diff against target: 54 lines (+19/-5)
2 files modified
lib/lp/soyuz/model/archive.py (+9/-4)
lib/lp/soyuz/tests/test_archive.py (+10/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/ppa-archive-reference-alias
Reviewer Review Type Date Requested Status
William Grant code 2015-03-12 Approve on 2015-03-12
Review via email: mp+252753@code.launchpad.net

Commit Message

Accept ppa:OWNER/DISTRO/ARCHIVE as a more shell-friendly alias for ~OWNER/DISTRO/ARCHIVE references.

Description of the Change

The ~OWNER/DISTRO/ARCHIVE reference syntax requires a little care in shells sometimes to avoid tripping over tilde expansion. We can unambiguously accept ppa:OWNER/DISTRO/ARCHIVE as a more shell-friendly alias, with the advantage that it matches up with a form that's valid for add-apt-repository as of last year, so let's do that.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/model/archive.py'
2--- lib/lp/soyuz/model/archive.py 2014-11-07 12:00:32 +0000
3+++ lib/lp/soyuz/model/archive.py 2015-03-12 14:05:25 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Database class for table Archive."""
10@@ -2229,11 +2229,16 @@
11 bits = reference.split(u'/')
12 if len(bits) < 1:
13 return None
14- if bits[0].startswith(u'~'):
15- # PPA reference (~OWNER/DISTRO/ARCHIVE)
16+ if bits[0].startswith(u'~') or bits[0].startswith(u'ppa:'):
17+ # PPA reference (~OWNER/DISTRO/ARCHIVE or ppa:OWNER/DISTRO/ARCHIVE)
18 if len(bits) != 3:
19 return None
20- person = getUtility(IPersonSet).getByName(bits[0][1:])
21+ if bits[0].startswith(u'~'):
22+ first_bit = bits[0][1:]
23+ else:
24+ # ppa:OWNER
25+ first_bit = bits[0][4:]
26+ person = getUtility(IPersonSet).getByName(first_bit)
27 if person is None:
28 return None
29 distro = getUtility(IDistributionSet).getByName(bits[1])
30
31=== modified file 'lib/lp/soyuz/tests/test_archive.py'
32--- lib/lp/soyuz/tests/test_archive.py 2014-12-11 22:36:36 +0000
33+++ lib/lp/soyuz/tests/test_archive.py 2015-03-12 14:05:25 +0000
34@@ -1,4 +1,4 @@
35-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
36+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
37 # GNU Affero General Public License version 3 (see the file LICENSE).
38
39 """Test Archive features."""
40@@ -3099,6 +3099,15 @@
41 archive.owner.name, archive.distribution.name, archive.name),
42 archive)
43
44+ def test_ppa_alias(self):
45+ # ppa:OWNER/DISTRO/ARCHIVE is accepted as a convenience to make it
46+ # easier to avoid tilde-expansion in shells.
47+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
48+ reference = 'ppa:%s/%s/%s' % (
49+ archive.owner.name, archive.distribution.name, archive.name)
50+ self.assertEqual(
51+ archive, getUtility(IArchiveSet).getByReference(reference))
52+
53
54 class TestArchiveSetGetByReference(TestCaseWithFactory):
55