← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/distribution-getFileByName-die into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/distribution-getFileByName-die into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/distribution-getFileByName-die/+merge/72838

Distribution.getFileByName is basically Archive.getFileByName, except with the ability to filter to only source or binary files. Given that a file's type is determined by its extension, this ability is of severely limited utility.

This branch moves the two production callsites and a few tests to use Archive.getFileByName instead, allowing the method to be dropped.

Also fixed a bit of lint that turned up.
-- 
https://code.launchpad.net/~wgrant/launchpad/distribution-getFileByName-die/+merge/72838
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/distribution-getFileByName-die into lp:launchpad.
=== modified file 'lib/lp/archiveuploader/tests/nascentupload-publishing-accepted-sources.txt'
--- lib/lp/archiveuploader/tests/nascentupload-publishing-accepted-sources.txt	2009-05-13 14:05:27 +0000
+++ lib/lp/archiveuploader/tests/nascentupload-publishing-accepted-sources.txt	2011-08-25 08:35:32 +0000
@@ -1,4 +1,5 @@
-= Publishing ACCEPTED Sources =
+Publishing ACCEPTED Sources
+===========================
 
 As recently requested in bug #77853, successfully source-only uploads,
 i.e, those uploads that only include a source package and were
@@ -51,7 +52,7 @@
 Also check if the Soyuz archive file lookup can reach one of the
 just-published file:
 
-    >>> ubuntu.getFileByName('ed_0.2.orig.tar.gz', source=True, binary=False)
+    >>> ubuntu.main_archive.getFileByName('ed_0.2.orig.tar.gz')
     <LibraryFileAlias...>
 
 We have to commit in order to have new Librarian files available to
@@ -102,6 +103,6 @@
 
 Same happens for the archive file lookup:
 
-    >>> ubuntu.getFileByName('ed_0.2-21.dsc', source=True, binary=False)
+    >>> ubuntu.main_archive.getFileByName('ed_0.2-21.dsc')
     <LibraryFileAlias...>
 

=== modified file 'lib/lp/archiveuploader/tests/test_ppauploadprocessor.py'
--- lib/lp/archiveuploader/tests/test_ppauploadprocessor.py	2011-08-18 09:26:46 +0000
+++ lib/lp/archiveuploader/tests/test_ppauploadprocessor.py	2011-08-25 08:35:32 +0000
@@ -892,8 +892,7 @@
         system.
         """
         try:
-            self.ubuntu.getFileByName(
-                'bar_1.0.orig.tar.gz', source=True, binary=False)
+            self.ubuntu.main_archive.getFileByName('bar_1.0.orig.tar.gz')
         except NotFoundError:
             self.fail('bar_1.0.orig.tar.gz is not yet published.')
 

=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
--- lib/lp/archiveuploader/tests/test_uploadprocessor.py	2011-08-17 14:44:07 +0000
+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py	2011-08-25 08:35:32 +0000
@@ -981,9 +981,7 @@
         archive = getUtility(IArchiveSet).getByDistroPurpose(
             distribution=self.ubuntu, purpose=ArchivePurpose.PARTNER)
         try:
-            self.ubuntu.getFileByName(
-                'foocomm_1.0.orig.tar.gz', archive=archive, source=True,
-                binary=False)
+            archive.getFileByName('foocomm_1.0.orig.tar.gz')
         except NotFoundError:
             self.fail('foocomm_1.0.orig.tar.gz is not yet published.')
 

=== modified file 'lib/lp/registry/doc/distribution.txt'
--- lib/lp/registry/doc/distribution.txt	2011-08-23 07:05:30 +0000
+++ lib/lp/registry/doc/distribution.txt	2011-08-25 08:35:32 +0000
@@ -70,8 +70,10 @@
 
     >>> from lp.registry.model.sourcepackagename import (
     ...                                          SourcePackageName)
-    >>> from lp.registry.interfaces.distributionsourcepackage import IDistributionSourcePackage
-    >>> from lp.soyuz.interfaces.distributionsourcepackagerelease import IDistributionSourcePackageRelease
+    >>> from lp.registry.interfaces.distributionsourcepackage import (
+    ...     IDistributionSourcePackage)
+    >>> from lp.soyuz.interfaces.distributionsourcepackagerelease import (
+    ...     IDistributionSourcePackageRelease)
 
     >>> evo = SourcePackageName.byName("evolution")
     >>> evo_ubuntu = ubuntu.getSourcePackage(evo)
@@ -359,23 +361,6 @@
     partner
     Canonical Partner Developers
 
-When processing an upload we may want to find a file (E.g. if an
-incomplete source is uploaded).
-
-    >>> ubuntu.getFileByName('mozilla-firefox_0.9_i386.deb').getURL()
-    'http://localhost:58000/40/mozilla-firefox_0.9_i386.deb'
-    >>> ubuntu.getFileByName(
-    ...     'mozilla-firefox_0.9_i386.deb', source=False).getURL()
-    'http://localhost:58000/40/mozilla-firefox_0.9_i386.deb'
-    >>> ubuntu.getFileByName('mozilla-firefox_0.9_i386.deb', binary=False)
-    Traceback (most recent call last):
-    ...
-    NotFoundError: 'mozilla-firefox_0.9_i386.deb'
-    >>> ubuntu.getFileByName('', source=False, binary=False)
-    Traceback (most recent call last):
-    ...
-    AssertionError: searching in an explicitly empty space is pointless
-
 
 Launchpad Usage
 ...............
@@ -575,9 +560,11 @@
     ...     # raised.
     ...     owner = spec.owner
     ...     if spec.name in ['cluster-installation', 'revu']:
-    ...         spec.definition_status = SpecificationDefinitionStatus.OBSOLETE
+    ...         spec.definition_status = (
+    ...             SpecificationDefinitionStatus.OBSOLETE)
     ...     if spec.name in ['krunch-desktop-plan']:
-    ...         spec.definition_status = SpecificationDefinitionStatus.SUPERSEDED
+    ...         spec.definition_status = (
+    ...             SpecificationDefinitionStatus.SUPERSEDED)
     ...     shim = spec.updateLifecycleStatus(owner)
     >>> for spec in kubuntu.valid_specifications:
     ...     print spec.name

=== modified file 'lib/lp/registry/interfaces/distribution.py'
--- lib/lp/registry/interfaces/distribution.py	2011-08-24 06:18:11 +0000
+++ lib/lp/registry/interfaces/distribution.py	2011-08-25 08:35:32 +0000
@@ -538,21 +538,6 @@
         (a substring of) their binary package names.
         """
 
-    def getFileByName(filename, archive=None, source=True, binary=True):
-        """Find and return a LibraryFileAlias for the filename supplied.
-
-        The file returned will be one of those published in the distribution.
-
-        If searching both source and binary, and the file is found in the
-        binary packages it'll return that over a file for a source package.
-
-        If 'archive' is not passed the distribution.main_archive is assumed.
-
-        At least one of source and binary must be true.
-
-        Raises NotFoundError if it fails to find the named file.
-        """
-
     def guessPublishedSourcePackageName(pkgname):
         """Return the "published" SourcePackageName related to pkgname.
 

=== modified file 'lib/lp/registry/model/distribution.py'
--- lib/lp/registry/model/distribution.py	2011-08-25 06:23:33 +0000
+++ lib/lp/registry/model/distribution.py	2011-08-25 08:35:32 +0000
@@ -53,7 +53,6 @@
 from canonical.launchpad.components.decoratedresultset import (
     DecoratedResultSet,
     )
-from canonical.launchpad.database.librarian import LibraryFileAlias
 from canonical.launchpad.helpers import shortlist
 from canonical.launchpad.interfaces.launchpad import (
     IHasIcon,
@@ -188,10 +187,8 @@
     DistroArchSeries,
     DistroArchSeriesSet,
     )
-from lp.soyuz.model.files import BinaryPackageFile
 from lp.soyuz.model.publishing import (
     BinaryPackagePublishingHistory,
-    SourcePackageFilePublishing,
     SourcePackagePublishingHistory,
     )
 from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
@@ -1070,49 +1067,6 @@
             DistroSeries.distribution == self,
             DistroSeries.status == status)
 
-    def _findPublishedBinaryFile(self, filename, archive):
-        """Find binary package file of the given name and archive.
-
-        :return: A `LibraryFileAlias`, or None.
-        """
-        search = Store.of(self).find(
-            LibraryFileAlias,
-            BinaryPackageFile.libraryfileID == LibraryFileAlias.id,
-            BinaryPackagePublishingHistory.binarypackagereleaseID ==
-                BinaryPackageFile.binarypackagereleaseID,
-            DistroArchSeries.id ==
-                BinaryPackagePublishingHistory.distroarchseriesID,
-            DistroSeries.id == DistroArchSeries.distroseriesID,
-            BinaryPackagePublishingHistory.dateremoved == None,
-            DistroSeries.distribution == self,
-            BinaryPackagePublishingHistory.archiveID == archive.id,
-            LibraryFileAlias.filename == filename)
-        return search.order_by(Desc(LibraryFileAlias.id)).first()
-
-    def getFileByName(self, filename, archive=None, source=True, binary=True):
-        """See `IDistribution`."""
-        assert (source or binary), "searching in an explicitly empty " \
-               "space is pointless"
-        if archive is None:
-            archive = self.main_archive
-
-        if binary:
-            candidate = self._findPublishedBinaryFile(filename, archive)
-        else:
-            candidate = None
-
-        if source and candidate is None:
-            spfp = SourcePackageFilePublishing.selectFirstBy(
-                distribution=self, libraryfilealiasfilename=filename,
-                archive=archive, orderBy=['id'])
-            if spfp is not None:
-                candidate = spfp.libraryfilealias
-
-        if candidate is None:
-            raise NotFoundError(filename)
-        else:
-            return candidate
-
     def getBuildRecords(self, build_state=None, name=None, pocket=None,
                         arch_tag=None, user=None, binary_only=True):
         """See `IHasBuildRecords`"""

=== modified file 'lib/lp/soyuz/model/queue.py'
--- lib/lp/soyuz/model/queue.py	2011-08-22 10:58:41 +0000
+++ lib/lp/soyuz/model/queue.py	2011-08-25 08:35:32 +0000
@@ -1121,13 +1121,11 @@
 
     def verifyBeforePublish(self):
         """See `IPackageUploadSource`."""
-        distribution = self.packageupload.distroseries.distribution
         # Check for duplicate filenames currently present in the archive.
         for source_file in self.sourcepackagerelease.files:
             try:
-                published_file = distribution.getFileByName(
-                    source_file.libraryfile.filename, binary=False,
-                    archive=self.packageupload.archive)
+                published_file = self.packageupload.archive.getFileByName(
+                    source_file.libraryfile.filename)
             except NotFoundError:
                 # NEW files are *OK*.
                 continue

=== modified file 'lib/lp/soyuz/scripts/ftpmaster.py'
--- lib/lp/soyuz/scripts/ftpmaster.py	2011-06-09 10:50:25 +0000
+++ lib/lp/soyuz/scripts/ftpmaster.py	2011-08-25 08:35:32 +0000
@@ -198,7 +198,6 @@
                 while parsed_sources.Step():
                     source = parsed_sources.Section.Find("Package")
                     source_version = parsed_sources.Section.Find("Version")
-                    architecture = parsed_sources.Section.Find("Architecture")
                     binaries = parsed_sources.Section.Find("Binary")
                     for binary in [
                         item.strip() for item in binaries.split(',')]:
@@ -868,8 +867,8 @@
         if it wasn't.
         """
         try:
-            libraryfilealias = self.todistro.getFileByName(
-                filename, source=True, binary=False)
+            libraryfilealias = self.todistro.main_archive.getFileByName(
+                filename)
         except NotFoundError:
             return None
 
@@ -896,10 +895,13 @@
             file_type = determine_source_file_type(filename)
             # set the return code if an orig was, in fact,
             # fetched from Librarian
-            if not file_type in (SourcePackageFileType.ORIG_TARBALL,
-                                 SourcePackageFileType.COMPONENT_ORIG_TARBALL):
+            orig_types = (
+                SourcePackageFileType.ORIG_TARBALL,
+                SourcePackageFileType.COMPONENT_ORIG_TARBALL)
+            if file_type not in orig_types:
                 raise SyncSourceError(
-                    'Oops, only orig tarball can be retrieved from librarian.')
+                    'Oops, only orig tarball can be retrieved from '
+                    'librarian.')
             retrieved.append(filename)
 
         return retrieved
@@ -1385,7 +1387,6 @@
 
         [action] = self.args
 
-        distribution = self.location.distribution
         series = self.location.distroseries
 
         try: