← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/shift-get_distroseries_pofiles into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/shift-get_distroseries_pofiles into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #401598 in Launchpad itself: "More VPOExport cleanup"
  https://bugs.launchpad.net/launchpad/+bug/401598

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/shift-get_distroseries_pofiles/+merge/121751

Remove some tech-debt, in the form of IVPOExportSet. I have shifted its two methods to be under IDistroSeries and changed all callsites.

I have also cleaned up a few other IDistroSeries methods.
-- 
https://code.launchpad.net/~stevenk/launchpad/shift-get_distroseries_pofiles/+merge/121751
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/shift-get_distroseries_pofiles into lp:launchpad.
=== modified file 'lib/lp/registry/interfaces/distroseries.py'
--- lib/lp/registry/interfaces/distroseries.py	2012-07-03 08:04:35 +0000
+++ lib/lp/registry/interfaces/distroseries.py	2012-08-29 05:39:32 +0000
@@ -923,6 +923,25 @@
             comment.
         """
 
+    def getPofiles(date=None, component=None, languagepack=None):
+        """Get a list of PO files which would be contained in an export of a
+        distribution series.
+
+        The filtering is done based on the 'series', last modified 'date',
+        archive 'component' and if it belongs to a 'languagepack'
+
+        Results are grouped by `POTemplate` to allow for caching of
+        information related to the template.
+        """
+
+    def getPofilesCount(date=None, component=None, languagepack=None):
+        """Return the number of PO files which would be contained in an export
+        of a distribution series.
+
+        The filtering is done based on the 'series', last modified 'date',
+        archive 'component' and if it belongs to a 'languagepack'
+        """
+
 
 class IDistroSeriesEditRestricted(Interface):
     """IDistroSeries properties which require launchpad.Edit."""

=== modified file 'lib/lp/registry/model/distroseries.py'
--- lib/lp/registry/model/distroseries.py	2012-08-08 05:36:44 +0000
+++ lib/lp/registry/model/distroseries.py	2012-08-29 05:39:32 +0000
@@ -30,6 +30,7 @@
     And,
     Desc,
     Join,
+    Or,
     SQL,
     )
 from storm.store import (
@@ -370,12 +371,11 @@
 
     @property
     def enabled_architectures(self):
-        store = Store.of(self)
-        results = store.find(
+        return Store.of(self).find(
             DistroArchSeries,
             DistroArchSeries.distroseries == self,
-            DistroArchSeries.enabled == True)
-        return results.order_by(DistroArchSeries.architecturetag)
+            DistroArchSeries.enabled == True).order_by(
+                DistroArchSeries.architecturetag)
 
     @property
     def buildable_architectures(self):
@@ -394,12 +394,11 @@
 
     @property
     def virtualized_architectures(self):
-        store = Store.of(self)
-        results = store.find(
+        return Store.of(self).find(
             DistroArchSeries,
             DistroArchSeries.distroseries == self,
-            DistroArchSeries.supports_virtualized == True)
-        return results.order_by(DistroArchSeries.architecturetag)
+            DistroArchSeries.supports_virtualized == True).order_by(
+                DistroArchSeries.architecturetag)
     # End of DistroArchSeries lookup methods
 
     @property
@@ -675,15 +674,10 @@
 
     @property
     def distroserieslanguages(self):
-        result = DistroSeriesLanguage.select(
-            "DistroSeriesLanguage.language = Language.id AND "
-            "DistroSeriesLanguage.distroseries = %d AND "
-            "Language.visible = TRUE" % self.id,
-            prejoinClauseTables=["Language"],
-            clauseTables=["Language"],
-            prejoins=["distroseries"],
-            orderBy=["Language.englishname"])
-        return result
+        return Store.of(self).find(
+            DistroSeriesLanguage.distroseriesID == self.id,
+            DistroSeriesLanguage.languageID == Language.id,
+            Language.visible == True).order_by(Language.englishname)
 
     def priorReleasedSeries(self):
         """See `IDistroSeries`."""
@@ -1698,6 +1692,58 @@
         return comment_source.getForDistroSeries(
             self, since=since, source_package_name=source_package_name)
 
+    def getPofiles(self, date=None, component=None, languagepack=None):
+        """See `IDistroSeries`."""
+        tables = [
+            POFile,
+            POTemplate,
+            ]
+
+        conditions = [
+            POTemplate.distroseries == self,
+            POTemplate.iscurrent == True,
+            POFile.potemplate == POTemplate.id,
+            ]
+
+        if date is not None:
+            conditions.append(Or(
+                POTemplate.date_last_updated > date,
+                POFile.date_changed > date))
+
+        if component is not None:
+            tables.extend([
+                SourcePackagePublishingHistory,
+                Component,
+                ])
+            conditions.extend([
+                SourcePackagePublishingHistory.distroseries == self,
+                SourcePackagePublishingHistory.component == Component.id,
+                POTemplate.sourcepackagename ==
+                    SourcePackagePublishingHistory.sourcepackagenameID,
+                Component.name == component,
+                SourcePackagePublishingHistory.dateremoved == None,
+                SourcePackagePublishingHistory.archive == self.main_archive,
+                ])
+
+        if languagepack:
+            conditions.append(POTemplate.languagepack == True)
+
+        # Use the slave store.  We may want to write to the distroseries
+        # to register a language pack, but not to the translation data
+        # we retrieve for it.
+        store = getUtility(IStoreSelector).get(MAIN_STORE, SLAVE_FLAVOR)
+        query = store.using(*tables).find(POFile, And(*conditions))
+
+        # Order by POTemplate.  Caching in the export scripts can be
+        # much more effective when consecutive POFiles belong to the
+        # same POTemplate, e.g. they'll have the same POTMsgSets.
+        sort_list = [POFile.potemplateID, POFile.languageID]
+        return query.order_by(sort_list).config(distinct=True)
+
+    def getPofilesCount(self, date=None, component=None, languagepack=None):
+        """See `IDistroSeries`."""
+        return self.getPofiles(date, component, languagepack).count()
+
 
 class DistroSeriesSet:
     implements(IDistroSeriesSet)

=== modified file 'lib/lp/translations/configure.zcml'
--- lib/lp/translations/configure.zcml	2012-02-15 21:14:05 +0000
+++ lib/lp/translations/configure.zcml	2012-08-29 05:39:32 +0000
@@ -35,12 +35,6 @@
         <allow
             interface="lp.translations.interfaces.potranslation.IPOTranslation"/>
     </class>
-    <securedutility
-        class="lp.translations.model.vpoexport.VPOExportSet"
-        provides="lp.translations.interfaces.vpoexport.IVPOExportSet">
-        <allow
-            interface="lp.translations.interfaces.vpoexport.IVPOExportSet"/>
-    </securedutility>
     <class
         class="lp.translations.model.vpoexport.VPOExport">
         <allow

=== modified file 'lib/lp/translations/doc/vpoexport.txt'
--- lib/lp/translations/doc/vpoexport.txt	2011-02-24 14:31:46 +0000
+++ lib/lp/translations/doc/vpoexport.txt	2012-08-29 05:39:32 +0000
@@ -1,14 +1,12 @@
-VPOExport and VPOExportSet
-=========================
+VPOExport
+=========
 
-The VPOExport and VPOExportSet classes retrieve and format data for
-exports in a more efficient way than fetching the entire objects.
+The VPOExport class retrieves and formats data for exports in a more efficient
+way than fetching the entire objects.
 
     >>> from zope.component import getUtility
     >>> from lp.registry.interfaces.distribution import IDistributionSet
-    >>> from lp.translations.interfaces.vpoexport import IVPOExportSet
 
-    >>> vpoexportset = getUtility(IVPOExportSet)
     >>> hoary = getUtility(IDistributionSet)['ubuntu']['hoary']
 
     >>> def describe_pofile(pofile):
@@ -16,12 +14,12 @@
     ...         pofile.potemplate.sourcepackagename.name,
     ...         pofile.potemplate.name, pofile.language.code)
 
-To facilitate language pack exports, IVPOExportSet can enumerate all
-current POFiles in a given distro series.
+To facilitate language pack exports, IDistroSeries.getPofiles() can enumerate
+all current POFiles in a given distro series.
 
     >>> pofiles = sorted([
     ...     describe_pofile(pofile)
-    ...     for pofile in vpoexportset.get_distroseries_pofiles(hoary)])
+    ...     for pofile in hoary.getPofiles()])
     >>> for pofile in pofiles:
     ...     print pofile
     evolution evolution-2.2 es
@@ -54,7 +52,7 @@
 
     >>> print len(pofiles)
     27
-    >>> print vpoexportset.get_distroseries_pofiles_count(hoary)
+    >>> print hoary.getPofilesCount()
     27
 
 The getTranslationRows method lists all translations found in the

=== modified file 'lib/lp/translations/interfaces/vpoexport.py'
--- lib/lp/translations/interfaces/vpoexport.py	2011-12-24 16:54:44 +0000
+++ lib/lp/translations/interfaces/vpoexport.py	2012-08-29 05:39:32 +0000
@@ -1,13 +1,11 @@
 # Copyright 2009 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
-# pylint: disable-msg=E0211,E0213
 
 """Interfaces for efficient translation file exports."""
 
 __metaclass__ = type
 
 __all__ = [
-    'IVPOExportSet',
     'IVPOExport',
     ]
 
@@ -25,31 +23,6 @@
 from lp.translations.interfaces.translations import TranslationConstants
 
 
-class IVPOExportSet(Interface):
-    """A collection of IVPOExport-providing rows."""
-
-    def get_distroseries_pofiles(series, date=None, component=None,
-        languagepack=None):
-        """Get a list of PO files which would be contained in an export of a
-        distribution series.
-
-        The filtering is done based on the 'series', last modified 'date',
-        archive 'component' and if it belongs to a 'languagepack'
-
-        Results are grouped by `POTemplate` to allow for caching of
-        information related to the template.
-        """
-
-    def get_distroseries_pofiles_count(series, date=None, component=None,
-        languagepack=None):
-        """Return the number of PO files which would be contained in an export
-        of a distribution series.
-
-        The filtering is done based on the 'series', last modified 'date',
-        archive 'component' and if it belongs to a 'languagepack'
-        """
-
-
 class IVPOExport(Interface):
     """Shorthand of translation messages for efficient exports."""
 

=== modified file 'lib/lp/translations/model/vpoexport.py'
--- lib/lp/translations/model/vpoexport.py	2012-05-14 01:29:38 +0000
+++ lib/lp/translations/model/vpoexport.py	2012-08-29 05:39:32 +0000
@@ -1,102 +1,17 @@
 # Copyright 2009 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-# pylint: disable-msg=E0611,W0212
-
 """Database class to handle translation export view."""
 
 __metaclass__ = type
 
 __all__ = [
-    'VPOExportSet',
     'VPOExport'
     ]
 
-from storm.expr import (
-    And,
-    Or,
-    )
-from zope.component import getUtility
 from zope.interface import implements
 
-from lp.services.webapp.interfaces import (
-    IStoreSelector,
-    MAIN_STORE,
-    SLAVE_FLAVOR,
-    )
-from lp.soyuz.model.component import Component
-from lp.soyuz.model.publishing import SourcePackagePublishingHistory
-from lp.translations.interfaces.vpoexport import (
-    IVPOExport,
-    IVPOExportSet,
-    )
-from lp.translations.model.pofile import POFile
-from lp.translations.model.potemplate import POTemplate
-
-
-class VPOExportSet:
-    """Retrieve collections of `VPOExport` objects."""
-
-    implements(IVPOExportSet)
-
-    def get_distroseries_pofiles(self, series, date=None, component=None,
-                                 languagepack=None):
-        """See `IVPOExport`.
-
-        Selects `POFiles` based on the 'series', last modified 'date',
-        archive 'component', and whether it belongs to a 'languagepack'
-        """
-        tables = [
-            POFile,
-            POTemplate,
-            ]
-
-        conditions = [
-            POTemplate.distroseries == series,
-            POTemplate.iscurrent == True,
-            POFile.potemplate == POTemplate.id,
-            ]
-
-        if date is not None:
-            conditions.append(Or(
-                POTemplate.date_last_updated > date,
-                POFile.date_changed > date))
-
-        if component is not None:
-            tables.extend([
-                SourcePackagePublishingHistory,
-                Component,
-                ])
-            conditions.extend([
-                SourcePackagePublishingHistory.distroseries == series,
-                SourcePackagePublishingHistory.component == Component.id,
-                POTemplate.sourcepackagename ==
-                    SourcePackagePublishingHistory.sourcepackagenameID,
-                Component.name == component,
-                SourcePackagePublishingHistory.dateremoved == None,
-                SourcePackagePublishingHistory.archive == series.main_archive,
-                ])
-
-        if languagepack:
-            conditions.append(POTemplate.languagepack == True)
-
-        # Use the slave store.  We may want to write to the distroseries
-        # to register a language pack, but not to the translation data
-        # we retrieve for it.
-        store = getUtility(IStoreSelector).get(MAIN_STORE, SLAVE_FLAVOR)
-        query = store.using(*tables).find(POFile, And(*conditions))
-
-        # Order by POTemplate.  Caching in the export scripts can be
-        # much more effective when consecutive POFiles belong to the
-        # same POTemplate, e.g. they'll have the same POTMsgSets.
-        sort_list = [POFile.potemplateID, POFile.languageID]
-        return query.order_by(sort_list).config(distinct=True)
-
-    def get_distroseries_pofiles_count(self, series, date=None,
-                                        component=None, languagepack=None):
-        """See `IVPOExport`."""
-        return self.get_distroseries_pofiles(
-            series, date, component, languagepack).count()
+from lp.translations.interfaces.vpoexport import IVPOExport
 
 
 class VPOExport:

=== modified file 'lib/lp/translations/scripts/language_pack.py'
--- lib/lp/translations/scripts/language_pack.py	2012-06-29 08:40:05 +0000
+++ lib/lp/translations/scripts/language_pack.py	2012-08-29 05:39:32 +0000
@@ -1,8 +1,6 @@
 # Copyright 2009 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-# pylint: disable-msg=W0702
-
 """Functions for language pack creation script."""
 
 __metaclass__ = type
@@ -37,7 +35,6 @@
 from lp.translations.interfaces.translationfileformat import (
     TranslationFileFormat,
     )
-from lp.translations.interfaces.vpoexport import IVPOExportSet
 
 
 def iter_sourcepackage_translationdomain_mapping(series):
@@ -77,7 +74,6 @@
     # We will need when the export started later to add the timestamp for this
     # export inside the exported tarball.
     start_date = datetime.datetime.utcnow().strftime('%Y%m%d')
-    export_set = getUtility(IVPOExportSet)
 
     logger.debug("Selecting PO files for export")
 
@@ -86,8 +82,8 @@
         # Get the export date for the current base language pack.
         date = distroseries.language_pack_base.date_exported
 
-    pofile_count = export_set.get_distroseries_pofiles_count(
-        distroseries, date, component, languagepack=True)
+    pofile_count = distroseries.getPofilesCount(
+        date, component, languagepack=True)
     logger.info("Number of PO files to export: %d" % pofile_count)
 
     filehandle = tempfile.TemporaryFile()
@@ -98,8 +94,7 @@
     xpi_templates_to_export = set()
     path_prefix = 'rosetta-%s' % distroseries.name
 
-    pofiles = export_set.get_distroseries_pofiles(
-        distroseries, date, component, languagepack=True)
+    pofiles = distroseries.getPofiles(date, component, languagepack=True)
 
     # Manual caching.  Fetch POTMsgSets in bulk per template, and cache
     # them across POFiles if subsequent POFiles belong to the same