Merge lp:~jtv/launchpad/get_derived_distros into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 13495
Proposed branch: lp:~jtv/launchpad/get_derived_distros
Merge into: lp:launchpad
Diff against target: 230 lines (+68/-47)
5 files modified
lib/lp/registry/interfaces/distribution.py (+8/-1)
lib/lp/registry/model/distribution.py (+11/-1)
lib/lp/registry/tests/test_distribution.py (+47/-1)
lib/lp/soyuz/scripts/processaccepted.py (+1/-16)
lib/lp/soyuz/tests/test_processaccepted.py (+1/-28)
To merge this branch: bzr merge lp:~jtv/launchpad/get_derived_distros
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+68675@code.launchpad.net

Commit message

Move finding of derived distros into IDistributionSet.

Description of the change

= Summary =

I recently added an option to process-accepted: "process all derived distributions (not counting Ubuntu, even if it is technically derived from Ubuntu)."

Now I'm adding a similar option to publish-distro, so the ability to find all derived distributions should be in a reusable place.

== Proposed fix ==

IDistributionSet.getDerivedDistributions().

== Pre-implementation notes ==

The notion "derived distributions" is a bit vague in this case. It doesn't matter for the foreseeable future; we're currently thinking "Ubuntu-derived distros" but we're not planning to set up any other derived distros (except perhaps Ubuntu as a derivative of Debian).

It's important that Ubuntu not be included in the list of "derived distributions" because it's large and needs to be processed separately. That's the whole point.

== Implementation details ==

I was unable to find any unit tests for DistributionSet, so I added one.

== Tests ==

{{{
./bin/test -vvc lp.registry.tests.test_distribution -t DistributionSet
./bin/test -vvc lp.soyuz.tests.test_processaccepted
}}}

== Demo and Q/A ==

There isn't much to demo or Q/A, really; existing code has moved a bit. Just so long as "process-accepted --derived" still runs.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/soyuz/scripts/processaccepted.py
  lib/lp/soyuz/tests/test_processaccepted.py
  lib/lp/registry/interfaces/distribution.py
  lib/lp/registry/tests/test_distribution.py
  lib/lp/registry/model/distribution.py

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Looks like a sensible move of the code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/interfaces/distribution.py'
2--- lib/lp/registry/interfaces/distribution.py 2011-07-13 18:18:42 +0000
3+++ lib/lp/registry/interfaces/distribution.py 2011-07-21 12:46:33 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 # pylint: disable-msg=E0211,E0213
10@@ -750,6 +750,13 @@
11 :return: A dict as per `IDistribution.getCurrentSourceReleases`
12 """
13
14+ def getDerivedDistributions():
15+ """Find derived distributions.
16+
17+ :return: An iterable of all derived distributions (not including
18+ Ubuntu, even if it is technically derived from Debian).
19+ """
20+
21
22 class NoSuchDistribution(NameLookupFailed):
23 """Raised when we try to find a distribution that doesn't exist."""
24
25=== modified file 'lib/lp/registry/model/distribution.py'
26--- lib/lp/registry/model/distribution.py 2011-07-14 14:08:04 +0000
27+++ lib/lp/registry/model/distribution.py 2011-07-21 12:46:33 +0000
28@@ -1,4 +1,4 @@
29-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
30+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
31 # GNU Affero General Public License version 3 (see the file LICENSE).
32
33 # pylint: disable-msg=E0611,W0212
34@@ -157,6 +157,7 @@
35 DistributionSourcePackage,
36 )
37 from lp.registry.model.distroseries import DistroSeries
38+from lp.registry.model.distroseriesparent import DistroSeriesParent
39 from lp.registry.model.hasdrivers import HasDriversMixin
40 from lp.registry.model.karma import KarmaContextMixin
41 from lp.registry.model.milestone import (
42@@ -1993,3 +1994,12 @@
43 result[sourcepackage] = DistributionSourcePackageRelease(
44 distro, sp_release)
45 return result
46+
47+ def getDerivedDistributions(self):
48+ """See `IDistributionSet`."""
49+ ubuntu_id = getUtility(ILaunchpadCelebrities).ubuntu.id
50+ return IStore(DistroSeries).find(
51+ Distribution,
52+ Distribution.id == DistroSeries.distributionID,
53+ DistroSeries.id == DistroSeriesParent.derived_series_id,
54+ DistroSeries.distributionID != ubuntu_id).config(distinct=True)
55
56=== modified file 'lib/lp/registry/tests/test_distribution.py'
57--- lib/lp/registry/tests/test_distribution.py 2011-06-17 19:47:36 +0000
58+++ lib/lp/registry/tests/test_distribution.py 2011-07-21 12:46:33 +0000
59@@ -20,10 +20,15 @@
60 from canonical.testing.layers import (
61 DatabaseFunctionalLayer,
62 LaunchpadFunctionalLayer,
63+ ZopelessDatabaseLayer,
64 )
65 from lp.app.errors import NotFoundError
66+from lp.app.interfaces.launchpad import ILaunchpadCelebrities
67 from lp.registry.errors import NoSuchDistroSeries
68-from lp.registry.interfaces.distribution import IDistribution
69+from lp.registry.interfaces.distribution import (
70+ IDistribution,
71+ IDistributionSet,
72+ )
73 from lp.registry.interfaces.person import IPersonSet
74 from lp.registry.interfaces.series import SeriesStatus
75 from lp.registry.tests.test_distroseries import (
76@@ -37,6 +42,7 @@
77 login_person,
78 TestCaseWithFactory,
79 )
80+from lp.testing.matchers import Provides
81 from lp.testing.views import create_initialized_view
82
83
84@@ -421,3 +427,43 @@
85 self.assertNotEqual(distribution.owner, distribution.registrant)
86 self.assertEqual(distribution.owner, self.owner)
87 self.assertEqual(distribution.registrant, self.registrant)
88+
89+
90+class DistributionSet(TestCaseWithFactory):
91+ """Test case for `IDistributionSet`."""
92+
93+ layer = ZopelessDatabaseLayer
94+
95+ def test_implements_interface(self):
96+ self.assertThat(
97+ getUtility(IDistributionSet), Provides(IDistributionSet))
98+
99+ def test_getDerivedDistributions_finds_derived_distro(self):
100+ dsp = self.factory.makeDistroSeriesParent()
101+ derived_distro = dsp.derived_series.distribution
102+ distroset = getUtility(IDistributionSet)
103+ self.assertIn(derived_distro, distroset.getDerivedDistributions())
104+
105+ def test_getDerivedDistributions_ignores_nonderived_distros(self):
106+ distroset = getUtility(IDistributionSet)
107+ nonderived_distro = self.factory.makeDistribution()
108+ self.assertNotIn(
109+ nonderived_distro, distroset.getDerivedDistributions())
110+
111+ def test_getDerivedDistributions_ignores_ubuntu_even_if_derived(self):
112+ ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
113+ self.factory.makeDistroSeriesParent(
114+ derived_series=ubuntu.currentseries)
115+ distroset = getUtility(IDistributionSet)
116+ self.assertNotIn(ubuntu, distroset.getDerivedDistributions())
117+
118+ def test_getDerivedDistribution_finds_each_distro_just_once(self):
119+ # Derived distros are not duplicated in the output of
120+ # getDerivedDistributions, even if they have multiple parents and
121+ # multiple derived series.
122+ dsp = self.factory.makeDistroSeriesParent()
123+ distro = dsp.derived_series.distribution
124+ other_series = self.factory.makeDistroSeries(distribution=distro)
125+ self.factory.makeDistroSeriesParent(derived_series=other_series)
126+ distroset = getUtility(IDistributionSet)
127+ self.assertEqual(1, len(list(distroset.getDerivedDistributions())))
128
129=== modified file 'lib/lp/soyuz/scripts/processaccepted.py'
130--- lib/lp/soyuz/scripts/processaccepted.py 2011-07-14 16:51:59 +0000
131+++ lib/lp/soyuz/scripts/processaccepted.py 2011-07-21 12:46:33 +0000
132@@ -19,7 +19,6 @@
133 from zope.component import getUtility
134 from zope.security.proxy import removeSecurityProxy
135
136-from canonical.launchpad.interfaces.lpstorm import IStore
137 from canonical.launchpad.webapp.errorlog import (
138 ErrorReportingUtility,
139 ScriptRequest,
140@@ -31,7 +30,6 @@
141 from lp.bugs.interfaces.bugtask import BugTaskStatus
142 from lp.registry.interfaces.distribution import IDistributionSet
143 from lp.registry.interfaces.pocket import PackagePublishingPocket
144-from lp.registry.model.distroseriesparent import DistroSeriesParent
145 from lp.services.scripts.base import (
146 LaunchpadCronScript,
147 LaunchpadScriptFailure,
148@@ -287,19 +285,6 @@
149 else:
150 self.txn.commit()
151
152- def findDerivedDistros(self):
153- """Find Ubuntu-derived distributions."""
154- # Avoid circular imports.
155- from lp.registry.model.distribution import Distribution
156- from lp.registry.model.distroseries import DistroSeries
157-
158- ubuntu_id = getUtility(ILaunchpadCelebrities).ubuntu.id
159- return IStore(DistroSeries).find(
160- Distribution,
161- Distribution.id == DistroSeries.distributionID,
162- DistroSeries.id == DistroSeriesParent.derived_series_id,
163- DistroSeries.distributionID != ubuntu_id).config(distinct=True)
164-
165 def findNamedDistro(self, distro_name):
166 """Find the `Distribution` called `distro_name`."""
167 self.logger.debug("Finding distribution %s.", distro_name)
168@@ -312,7 +297,7 @@
169 def findTargetDistros(self):
170 """Find the distribution(s) to process, based on arguments."""
171 if self.options.derived:
172- return self.findDerivedDistros()
173+ return getUtility(IDistributionSet).getDerivedDistributions()
174 else:
175 return [self.findNamedDistro(self.args[0])]
176
177
178=== modified file 'lib/lp/soyuz/tests/test_processaccepted.py'
179--- lib/lp/soyuz/tests/test_processaccepted.py 2011-07-14 16:54:41 +0000
180+++ lib/lp/soyuz/tests/test_processaccepted.py 2011-07-21 12:46:33 +0000
181@@ -4,7 +4,6 @@
182 """Test process-accepted.py"""
183
184 from cStringIO import StringIO
185-from zope.component import getUtility
186
187 from canonical.launchpad.interfaces.lpstorm import IStore
188 from debian.deb822 import Changes
189@@ -14,7 +13,6 @@
190 from canonical.config import config
191 from canonical.launchpad.webapp.errorlog import ErrorReportingUtility
192 from canonical.testing.layers import LaunchpadZopelessLayer
193-from lp.app.interfaces.launchpad import ILaunchpadCelebrities
194 from lp.registry.interfaces.series import SeriesStatus
195 from lp.services.log.logger import BufferLogger
196 from lp.services.scripts.base import LaunchpadScriptFailure
197@@ -223,32 +221,7 @@
198 dsp = self.factory.makeDistroSeriesParent()
199 script = ProcessAccepted(test_args=['--derived'])
200 self.assertIn(
201- dsp.derived_series.distribution, script.findDerivedDistros())
202-
203- def test_findDerivedDistros_for_derived_ignores_non_derived_distros(self):
204- distro = self.factory.makeDistribution()
205- script = ProcessAccepted(test_args=['--derived'])
206- self.assertNotIn(distro, script.findDerivedDistros())
207-
208- def test_findDerivedDistros_ignores_ubuntu_even_if_derived(self):
209- ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
210- self.factory.makeDistroSeriesParent(
211- derived_series=ubuntu.currentseries)
212- script = ProcessAccepted(test_args=['--derived'])
213- self.assertNotIn(ubuntu, script.findDerivedDistros())
214-
215- def test_findDerivedDistros_finds_each_distro_just_once(self):
216- # Derived distros are not duplicated in the output of
217- # findDerivedDistros, even if they have multiple parents and
218- # multiple derived series.
219- dsp = self.factory.makeDistroSeriesParent()
220- distro = dsp.derived_series.distribution
221- other_series = self.factory.makeDistroSeries(distribution=distro)
222- self.factory.makeDistroSeriesParent(derived_series=other_series)
223- script = ProcessAccepted(test_args=['--derived'])
224- derived_distros = list(script.findDerivedDistros())
225- self.assertEqual(
226- 1, derived_distros.count(dsp.derived_series.distribution))
227+ dsp.derived_series.distribution, script.findTargetDistros())
228
229
230 class TestBugsFromChangesFile(TestCaseWithFactory):