← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/ppa-archive-reference-alias into lp:launchpad.

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/ppa-archive-reference-alias/+merge/252753

The ~OWNER/DISTRO/ARCHIVE alias 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.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/ppa-archive-reference-alias into lp:launchpad.
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2014-11-07 12:00:32 +0000
+++ lib/lp/soyuz/model/archive.py	2015-03-12 14:05:25 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2014 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Database class for table Archive."""
@@ -2229,11 +2229,16 @@
         bits = reference.split(u'/')
         if len(bits) < 1:
             return None
-        if bits[0].startswith(u'~'):
-            # PPA reference (~OWNER/DISTRO/ARCHIVE)
+        if bits[0].startswith(u'~') or bits[0].startswith(u'ppa:'):
+            # PPA reference (~OWNER/DISTRO/ARCHIVE or ppa:OWNER/DISTRO/ARCHIVE)
             if len(bits) != 3:
                 return None
-            person = getUtility(IPersonSet).getByName(bits[0][1:])
+            if bits[0].startswith(u'~'):
+                first_bit = bits[0][1:]
+            else:
+                # ppa:OWNER
+                first_bit = bits[0][4:]
+            person = getUtility(IPersonSet).getByName(first_bit)
             if person is None:
                 return None
             distro = getUtility(IDistributionSet).getByName(bits[1])

=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py	2014-12-11 22:36:36 +0000
+++ lib/lp/soyuz/tests/test_archive.py	2015-03-12 14:05:25 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2014 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test Archive features."""
@@ -3099,6 +3099,15 @@
                 archive.owner.name, archive.distribution.name, archive.name),
             archive)
 
+    def test_ppa_alias(self):
+        # ppa:OWNER/DISTRO/ARCHIVE is accepted as a convenience to make it
+        # easier to avoid tilde-expansion in shells.
+        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
+        reference = 'ppa:%s/%s/%s' % (
+            archive.owner.name, archive.distribution.name, archive.name)
+        self.assertEqual(
+            archive, getUtility(IArchiveSet).getByReference(reference))
+
 
 class TestArchiveSetGetByReference(TestCaseWithFactory):
 


Follow ups