Merge lp:~henninge/launchpad/devel-710591-sharing-info-groundwork-0 into lp:launchpad

Proposed by Henning Eggers
Status: Merged
Approved by: Henning Eggers
Approved revision: no longer in the source branch.
Merged at revision: 12320
Proposed branch: lp:~henninge/launchpad/devel-710591-sharing-info-groundwork-0
Merge into: lp:launchpad
Diff against target: 504 lines (+487/-0)
3 files modified
.bzrignore (+1/-0)
lib/lp/translations/utilities/tests/test_translation_sharing_info.py (+310/-0)
lib/lp/translations/utilities/translationsharinginfo.py (+176/-0)
To merge this branch: bzr merge lp:~henninge/launchpad/devel-710591-sharing-info-groundwork-0
Reviewer Review Type Date Requested Status
Deryck Hodge (community) code Approve
Review via email: mp+48416@code.launchpad.net

Commit message

[r=deryck][ui=none][no-qa] Provide translation sharing information.

Description of the change

= Summary =

For the current feature work but also to fix bug 710591, the information
about sharing template on the other side must be easily available. This
branch provides this informatioon through a couple of functions.

== Proposed fix ==

Provide functions that list information about the current sharing
information on the other side. "Other side" is an upstream product series
for a source package and an Ubuntu sourcepackage for a product series.

Translation sharing only happens when a template of the same name as the one
on this side exists but before that a packaging link is required. These
functions list both the content of the packaging link and any templates on
the other side, if any.

== Pre-implementation notes ==

I did not really consult anybody about this particular module although the
necessity for this functionality has been discussed.

== Implementation details ==

I had first considered creating an adapter on productseries and source
package but decided against it and chose the simpler approach. Since there
is no state information or anything, functions do the job just as well.

The find_* functions are meant to be internal functions that return Storm
ResultSets and the get_* and has_* functions make use of this. It may still
make sense to put the find_* functions into __all__, though.

== Tests ==

bin/test -vvcm lp.translations.utilities.tests.translationsharinginfo

== Demo and Q/A ==

None.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  .bzrignore
  lib/lp/translations/utilities/translationsharinginfo.py
  lib/lp/translations/utilities/tests/test_translation_sharing_info.py

To post a comment you must log in.
Revision history for this message
Deryck Hodge (deryck) wrote :

Henning,

This looks good. Thanks for taking the time to jump on Mumble and talk this over with me. I really like the test, and appreciate you being thorough in covering all the various cases.

Some minor cleanups/clarifications could help:

 * Remove the pylint disable-msg declaration
 * Be consistent about comments on the test methods
    (Just so it's easy to scan the test and work out
     what is being tested)
 * Add clarify comments to the main module (docstring perhaps?)

This last one is because it was not clear to me where I would use these methods, or why I should prefer one over the other. So some documentation to clarify would help. And also prevent people importing all these functions and doing:

    if has_upstream_template():
        info = get_upstream_sharing_info()

To help prevent people firing off more queries then they they realize.

Thanks, again!

review: Approve (code)
Revision history for this message
Henning Eggers (henninge) wrote :

Thanks for the review. Please find my added comments below.

=== modified file 'lib/lp/translations/utilities/tests/test_translation_sharing_info.py'
--- lib/lp/translations/utilities/tests/test_translation_sharing_info.py 2011-02-03 01:13:32 +0000
+++ lib/lp/translations/utilities/tests/test_translation_sharing_info.py 2011-02-03 18:18:29 +0000
@@ -1,8 +1,6 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4# pylint: disable-msg=C0102
5
6__metaclass__ = type4__metaclass__ = type
75
8from canonical.testing.layers import ZopelessDatabaseLayer6from canonical.testing.layers import ZopelessDatabaseLayer
@@ -219,6 +217,8 @@
219 templatename=different_templatename))217 templatename=different_templatename))
220218
221 def test_has_upstream_template_no_productseries(self):219 def test_has_upstream_template_no_productseries(self):
220 # Without an upstream project, no upstream templates won't be
221 # available either.
222 distroseries, sourcepackagename = self._makeSourcePackage()222 distroseries, sourcepackagename = self._makeSourcePackage()
223 templatename = self.factory.getUniqueString()223 templatename = self.factory.getUniqueString()
224224
@@ -227,6 +227,7 @@
227 distroseries, sourcepackagename, templatename))227 distroseries, sourcepackagename, templatename))
228228
229 def test_has_upstream_template_no_template(self):229 def test_has_upstream_template_no_template(self):
230 # No template exists on the upstream project.
230 distroseries, sourcepackagename = self._makeSourcePackage()231 distroseries, sourcepackagename = self._makeSourcePackage()
231 productseries = self._makeUpstreamProductSeries(232 productseries = self._makeUpstreamProductSeries(
232 distroseries, sourcepackagename)233 distroseries, sourcepackagename)
@@ -237,6 +238,8 @@
237 distroseries, sourcepackagename, templatename))238 distroseries, sourcepackagename, templatename))
238239
239 def test_has_upstream_template_one_template(self):240 def test_has_upstream_template_one_template(self):
241 # There is one template on the upstream project that matches the
242 # name.
240 distroseries, sourcepackagename = self._makeSourcePackage()243 distroseries, sourcepackagename = self._makeSourcePackage()
241 productseries = self._makeUpstreamProductSeries(244 productseries = self._makeUpstreamProductSeries(
242 distroseries, sourcepackagename)245 distroseries, sourcepackagename)
@@ -249,6 +252,8 @@
249 distroseries, sourcepackagename, templatename))252 distroseries, sourcepackagename, templatename))
250253
251 def test_has_upstream_template_one_template_wrong_name(self):254 def test_has_upstream_template_one_template_wrong_name(self):
255 # There is one template on the upstream project but it matches not
256 # the requested name.
252 distroseries, sourcepackagename = self._makeSourcePackage()257 distroseries, sourcepackagename = self._makeSourcePackage()
253 productseries = self._makeUpstreamProductSeries(258 productseries = self._makeUpstreamProductSeries(
254 distroseries, sourcepackagename)259 distroseries, sourcepackagename)
@@ -260,12 +265,15 @@
260 distroseries, sourcepackagename, different_templatename))265 distroseries, sourcepackagename, different_templatename))
261266
262 def test_has_ubuntu_template_no_sourcepackage(self):267 def test_has_ubuntu_template_no_sourcepackage(self):
268 # There is no Ubuntu source package, so no Ubuntu template can be
269 # found.
263 productseries = self.factory.makeProductSeries()270 productseries = self.factory.makeProductSeries()
264 templatename = self.factory.getUniqueString()271 templatename = self.factory.getUniqueString()
265272
266 self.assertFalse(has_ubuntu_template(productseries, templatename))273 self.assertFalse(has_ubuntu_template(productseries, templatename))
267274
268 def test_has_ubuntu_template_no_template(self):275 def test_has_ubuntu_template_no_template(self):
276 # The Ubuntu source package has no template.
269 distroseries, sourcepackagename = self._makeSourcePackage()277 distroseries, sourcepackagename = self._makeSourcePackage()
270 productseries = self._makeUpstreamProductSeries(278 productseries = self._makeUpstreamProductSeries(
271 distroseries, sourcepackagename)279 distroseries, sourcepackagename)
@@ -274,6 +282,8 @@
274 self.assertFalse(has_ubuntu_template(productseries, templatename))282 self.assertFalse(has_ubuntu_template(productseries, templatename))
275283
276 def test_has_ubuntu_template_one_template(self):284 def test_has_ubuntu_template_one_template(self):
285 # There is one template on the Ubuntu source package that matches
286 # the name.
277 distroseries, sourcepackagename = self._makeSourcePackage()287 distroseries, sourcepackagename = self._makeSourcePackage()
278 productseries = self._makeUpstreamProductSeries(288 productseries = self._makeUpstreamProductSeries(
279 distroseries, sourcepackagename)289 distroseries, sourcepackagename)
@@ -285,6 +295,8 @@
285 self.assertTrue(has_ubuntu_template(productseries, templatename))295 self.assertTrue(has_ubuntu_template(productseries, templatename))
286296
287 def test_has_ubuntu_template_one_template_wrong_name(self):297 def test_has_ubuntu_template_one_template_wrong_name(self):
298 # There is one template on the Ubuntu source package but it matches
299 # not the requested name.
288 distroseries, sourcepackagename = self._makeSourcePackage()300 distroseries, sourcepackagename = self._makeSourcePackage()
289 productseries = self._makeUpstreamProductSeries(301 productseries = self._makeUpstreamProductSeries(
290 distroseries, sourcepackagename)302 distroseries, sourcepackagename)
291303
=== modified file 'lib/lp/translations/utilities/translationsharinginfo.py'
--- lib/lp/translations/utilities/translationsharinginfo.py 2011-02-03 01:13:32 +0000
+++ lib/lp/translations/utilities/translationsharinginfo.py 2011-02-03 18:35:28 +0000
@@ -1,7 +1,23 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Provide sharing information."""4"""Provide sharing information.
5
6This module defines two different types of functions that provide
7information about what sharing options are available on the other side of a
8packaging link. Since they perform similar but slightly different complex
9database queries combining them in any way will usually be wrong.
10
11get_ubuntu_sharing_info and get_upstream_sharing_info will give you
12information about the source package or productseries respectively,
13combined with possibly available templates. You can restrict the search
14by specifying a template name.
15
16has_ubuntu_template and has_upstream_template make a direct search for a
17template of the given name on the other side. They do not search for
18source package or productseries but will only return True if an actual
19template exists. That is a significant difference to the get_* functions.
20"""
521
6__metaclass__ = type22__metaclass__ = type
7__all__ = [23__all__ = [

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2011-01-16 19:04:25 +0000
+++ .bzrignore 2011-02-03 18:46:24 +0000
@@ -76,3 +76,4 @@
76librarian.log76librarian.log
77configs/testrunner_*77configs/testrunner_*
78configs/testrunner-appserver_*78configs/testrunner-appserver_*
79.idea
7980
=== added file 'lib/lp/translations/utilities/tests/test_translation_sharing_info.py'
--- lib/lp/translations/utilities/tests/test_translation_sharing_info.py 1970-01-01 00:00:00 +0000
+++ lib/lp/translations/utilities/tests/test_translation_sharing_info.py 2011-02-03 18:46:24 +0000
@@ -0,0 +1,310 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4__metaclass__ = type
5
6from canonical.testing.layers import ZopelessDatabaseLayer
7from lp.testing import TestCaseWithFactory
8from lp.translations.utilities.translationsharinginfo import (
9 get_ubuntu_sharing_info,
10 get_upstream_sharing_info,
11 has_ubuntu_template,
12 has_upstream_template,
13 )
14
15
16class TestTranslationSharingInfo(TestCaseWithFactory):
17 """Tests for `get_upstream_sharing_info` and `get_ubuntu_sharing_info`"""
18
19 layer = ZopelessDatabaseLayer
20
21 def _makeSourcePackage(self):
22 """Create a distroseries and a sourcepackagename."""
23 distroseries = self.factory.makeUbuntuDistroSeries()
24 sourcepackagename = self.factory.makeSourcePackageName()
25 return (distroseries, sourcepackagename)
26
27 def _makeUpstreamProductSeries(self, distroseries, sourcepackagename):
28 """Create a product series and link it to the source package."""
29 productseries = self.factory.makeProductSeries()
30 sourcepackage = self.factory.makeSourcePackage(
31 sourcepackagename, distroseries)
32 owner = self.factory.makePerson()
33 sourcepackage.setPackaging(productseries, owner)
34 return productseries
35
36 def test_no_upstream(self):
37 # With no upstream the sharing information on a source package will
38 # be empty.
39 distroseries, sourcepackagename = self._makeSourcePackage()
40 self.assertEquals(
41 [],
42 get_upstream_sharing_info(
43 distroseries=distroseries,
44 sourcepackagename=sourcepackagename))
45
46 def test_no_upstream_with_name(self):
47 # With no upstream the sharing information on a source package will
48 # be empty, even when searching for a specific template name.
49 distroseries, sourcepackagename = self._makeSourcePackage()
50 templatename = self.factory.getUniqueString()
51 self.assertEquals(
52 [],
53 get_upstream_sharing_info(
54 distroseries=distroseries,
55 sourcepackagename=sourcepackagename,
56 templatename=templatename))
57
58 def test_upstream_no_template(self):
59 # With an upstream without a template the sharing information on a
60 # source package will be empty.
61 distroseries, sourcepackagename = self._makeSourcePackage()
62 productseries = self._makeUpstreamProductSeries(
63 distroseries, sourcepackagename)
64 self.assertEquals(
65 [(productseries, None)],
66 get_upstream_sharing_info(
67 distroseries=distroseries,
68 sourcepackagename=sourcepackagename))
69
70 def test_upstream_no_template_with_name(self):
71 # With an upstream without a template the sharing information on a
72 # source package will be empty, even when searching for a specific
73 # template name.
74 distroseries, sourcepackagename = self._makeSourcePackage()
75 productseries = self._makeUpstreamProductSeries(
76 distroseries, sourcepackagename)
77 templatename = self.factory.getUniqueString()
78 self.assertEquals(
79 [(productseries, None)],
80 get_upstream_sharing_info(
81 distroseries=distroseries,
82 sourcepackagename=sourcepackagename,
83 templatename=templatename))
84
85 def test_upstream_one_template(self):
86 # With an upstream template the sharing information on a
87 # source package will return that.
88 distroseries, sourcepackagename = self._makeSourcePackage()
89 productseries = self._makeUpstreamProductSeries(
90 distroseries, sourcepackagename)
91 potemplate = self.factory.makePOTemplate(productseries=productseries)
92 self.assertEquals(
93 [(productseries, potemplate)],
94 get_upstream_sharing_info(
95 distroseries=distroseries,
96 sourcepackagename=sourcepackagename))
97
98 def test_upstream_one_template_with_name(self):
99 # With an upstream template the sharing information on a
100 # source package will return that, even when searching for a
101 # specific template name.
102 distroseries, sourcepackagename = self._makeSourcePackage()
103 productseries = self._makeUpstreamProductSeries(
104 distroseries, sourcepackagename)
105 templatename = self.factory.getUniqueString()
106 potemplate = self.factory.makePOTemplate(
107 productseries=productseries, name=templatename)
108 self.assertEquals(
109 [(productseries, potemplate)],
110 get_upstream_sharing_info(
111 distroseries=distroseries,
112 sourcepackagename=sourcepackagename,
113 templatename=templatename))
114
115 def test_upstream_one_template_with_different_name(self):
116 # With an upstream template the sharing information on a
117 # source package will be empty if a different name is queried.
118 distroseries, sourcepackagename = self._makeSourcePackage()
119 productseries = self._makeUpstreamProductSeries(
120 distroseries, sourcepackagename)
121 templatename = self.factory.getUniqueString()
122 self.factory.makePOTemplate(
123 productseries=productseries, name=templatename)
124 different_templatename = self.factory.getUniqueString()
125 self.assertEquals(
126 [(productseries, None)],
127 get_upstream_sharing_info(
128 distroseries=distroseries,
129 sourcepackagename=sourcepackagename,
130 templatename=different_templatename))
131
132 def test_no_ubuntu(self):
133 # With no sourcepackage the sharing information on a source package
134 # will be empty.
135 productseries = self.factory.makeProductSeries()
136 self.assertEquals(
137 [],
138 get_ubuntu_sharing_info(productseries=productseries))
139
140 def test_no_ubuntu_with_name(self):
141 # With no sourcepackage the sharing information on a source package
142 # will be empty, even when searching for a specific template name.
143 productseries = self.factory.makeProductSeries()
144 templatename = self.factory.getUniqueString()
145 self.assertEquals(
146 [],
147 get_ubuntu_sharing_info(
148 productseries=productseries, templatename=templatename))
149
150 def test_ubuntu_no_template(self):
151 # With a sourcepackage without a template the sharing information
152 # on a productseries will be empty.
153 distroseries, sourcepackagename = self._makeSourcePackage()
154 productseries = self._makeUpstreamProductSeries(
155 distroseries, sourcepackagename)
156 self.assertEquals(
157 [(distroseries, sourcepackagename, None)],
158 get_ubuntu_sharing_info(productseries=productseries))
159
160 def test_ubuntu_no_template_with_name(self):
161 # With a sourcepackage without a template the sharing information
162 # on a productseries will be empty, even when searching for a
163 # specific template name.
164 distroseries, sourcepackagename = self._makeSourcePackage()
165 productseries = self._makeUpstreamProductSeries(
166 distroseries, sourcepackagename)
167 templatename = self.factory.getUniqueString()
168 self.assertEquals(
169 [(distroseries, sourcepackagename, None)],
170 get_ubuntu_sharing_info(
171 productseries=productseries, templatename=templatename))
172
173 def test_ubuntu_one_template(self):
174 # With a sourcepackage template the sharing information on a
175 # source package will return that.
176 distroseries, sourcepackagename = self._makeSourcePackage()
177 productseries = self._makeUpstreamProductSeries(
178 distroseries, sourcepackagename)
179 potemplate = self.factory.makePOTemplate(
180 distroseries=distroseries, sourcepackagename=sourcepackagename)
181 self.assertEquals(
182 [(distroseries, sourcepackagename, potemplate)],
183 get_ubuntu_sharing_info(
184 productseries=productseries))
185
186 def test_ubuntu_one_template_with_name(self):
187 # With a sourcepackage template the sharing information on a
188 # productseries will return that, even when searching for a
189 # specific template name.
190 distroseries, sourcepackagename = self._makeSourcePackage()
191 productseries = self._makeUpstreamProductSeries(
192 distroseries, sourcepackagename)
193 templatename = self.factory.getUniqueString()
194 potemplate = self.factory.makePOTemplate(
195 distroseries=distroseries, sourcepackagename=sourcepackagename,
196 name=templatename)
197 self.assertEquals(
198 [(distroseries, sourcepackagename, potemplate)],
199 get_ubuntu_sharing_info(
200 productseries=productseries, templatename=templatename))
201
202 def test_ubuntu_one_template_with_different_name(self):
203 # With a sourcepackage template the sharing information on a
204 # productseries will be empty if a different name is queried.
205 distroseries, sourcepackagename = self._makeSourcePackage()
206 productseries = self._makeUpstreamProductSeries(
207 distroseries, sourcepackagename)
208 templatename = self.factory.getUniqueString()
209 self.factory.makePOTemplate(
210 distroseries=distroseries, sourcepackagename=sourcepackagename,
211 name=templatename)
212 different_templatename = self.factory.getUniqueString()
213 self.assertEquals(
214 [(distroseries, sourcepackagename, None)],
215 get_ubuntu_sharing_info(
216 productseries=productseries,
217 templatename=different_templatename))
218
219 def test_has_upstream_template_no_productseries(self):
220 # Without an upstream project, no upstream templates won't be
221 # available either.
222 distroseries, sourcepackagename = self._makeSourcePackage()
223 templatename = self.factory.getUniqueString()
224
225 self.assertFalse(
226 has_upstream_template(
227 distroseries, sourcepackagename, templatename))
228
229 def test_has_upstream_template_no_template(self):
230 # No template exists on the upstream project.
231 distroseries, sourcepackagename = self._makeSourcePackage()
232 productseries = self._makeUpstreamProductSeries(
233 distroseries, sourcepackagename)
234 templatename = self.factory.getUniqueString()
235
236 self.assertFalse(
237 has_upstream_template(
238 distroseries, sourcepackagename, templatename))
239
240 def test_has_upstream_template_one_template(self):
241 # There is one template on the upstream project that matches the
242 # name.
243 distroseries, sourcepackagename = self._makeSourcePackage()
244 productseries = self._makeUpstreamProductSeries(
245 distroseries, sourcepackagename)
246 templatename = self.factory.getUniqueString()
247 self.factory.makePOTemplate(
248 productseries=productseries, name=templatename)
249
250 self.assertTrue(
251 has_upstream_template(
252 distroseries, sourcepackagename, templatename))
253
254 def test_has_upstream_template_one_template_wrong_name(self):
255 # There is one template on the upstream project but it matches not
256 # the requested name.
257 distroseries, sourcepackagename = self._makeSourcePackage()
258 productseries = self._makeUpstreamProductSeries(
259 distroseries, sourcepackagename)
260 self.factory.makePOTemplate(productseries=productseries)
261 different_templatename = self.factory.getUniqueString()
262
263 self.assertFalse(
264 has_upstream_template(
265 distroseries, sourcepackagename, different_templatename))
266
267 def test_has_ubuntu_template_no_sourcepackage(self):
268 # There is no Ubuntu source package, so no Ubuntu template can be
269 # found.
270 productseries = self.factory.makeProductSeries()
271 templatename = self.factory.getUniqueString()
272
273 self.assertFalse(has_ubuntu_template(productseries, templatename))
274
275 def test_has_ubuntu_template_no_template(self):
276 # The Ubuntu source package has no template.
277 distroseries, sourcepackagename = self._makeSourcePackage()
278 productseries = self._makeUpstreamProductSeries(
279 distroseries, sourcepackagename)
280 templatename = self.factory.getUniqueString()
281
282 self.assertFalse(has_ubuntu_template(productseries, templatename))
283
284 def test_has_ubuntu_template_one_template(self):
285 # There is one template on the Ubuntu source package that matches
286 # the name.
287 distroseries, sourcepackagename = self._makeSourcePackage()
288 productseries = self._makeUpstreamProductSeries(
289 distroseries, sourcepackagename)
290 templatename = self.factory.getUniqueString()
291 self.factory.makePOTemplate(
292 distroseries=distroseries, sourcepackagename=sourcepackagename,
293 name=templatename)
294
295 self.assertTrue(has_ubuntu_template(productseries, templatename))
296
297 def test_has_ubuntu_template_one_template_wrong_name(self):
298 # There is one template on the Ubuntu source package but it matches
299 # not the requested name.
300 distroseries, sourcepackagename = self._makeSourcePackage()
301 productseries = self._makeUpstreamProductSeries(
302 distroseries, sourcepackagename)
303 templatename = self.factory.getUniqueString()
304 self.factory.makePOTemplate(
305 distroseries=distroseries, sourcepackagename=sourcepackagename,
306 name=templatename)
307 different_templatename = self.factory.getUniqueString()
308
309 self.assertFalse(
310 has_ubuntu_template(productseries, different_templatename))
0311
=== added file 'lib/lp/translations/utilities/translationsharinginfo.py'
--- lib/lp/translations/utilities/translationsharinginfo.py 1970-01-01 00:00:00 +0000
+++ lib/lp/translations/utilities/translationsharinginfo.py 2011-02-03 18:46:24 +0000
@@ -0,0 +1,176 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Provide sharing information.
5
6This module defines two different types of functions that provide
7information about what sharing options are available on the other side of a
8packaging link. Since they perform similar but slightly different complex
9database queries combining them in any way will usually be wrong.
10
11get_ubuntu_sharing_info and get_upstream_sharing_info will give you
12information about the source package or productseries respectively,
13combined with possibly available templates. You can restrict the search
14by specifying a template name.
15
16has_ubuntu_template and has_upstream_template make a direct search for a
17template of the given name on the other side. They do not search for
18source package or productseries but will only return True if an actual
19template exists. That is a significant difference to the get_* functions.
20"""
21
22__metaclass__ = type
23__all__ = [
24 'get_ubuntu_sharing_info',
25 'get_upstream_sharing_info',
26 'has_ubuntu_template',
27 'has_upstream_template',
28 ]
29
30from storm.expr import (\
31 And,
32 Join,
33 LeftJoin,
34 )
35
36from canonical.launchpad.interfaces.lpstorm import IStore
37from lp.registry.model.distroseries import DistroSeries
38from lp.registry.model.packaging import Packaging
39from lp.registry.model.productseries import ProductSeries
40from lp.registry.model.sourcepackagename import SourcePackageName
41from lp.translations.model.potemplate import POTemplate
42
43
44def find_ubuntu_sharing_info(productseries, templatename=None,
45 template_only=False):
46 """Return a `ResultSet` of sharing information for this productseries.
47
48 Target is either a productseries or a source package.
49 :param productseries: The target productseries or None.
50 :param templatename: The name of the template to find information for or
51 None to get information about any sharing template in any series.
52 :param template_only: Return only `POTemplate` instances.
53 :returns: A result set of ('Distroseries', SourcePackageName, POTemplate)
54 tuples.
55 """
56
57 # SELECT *
58 # FROM Packaging
59 # JOIN Distroseries
60 # ON Packaging.distroseries = Distroseries.id
61 # JOIN SourcePackageName
62 # ON Packaging.sourcepackagename = SourcePackageName.id
63 # LEFT JOIN POTemplate
64 # ON Packaging.distroseries = POTemplate.distroseries AND
65 # Packaging.sourcepackagename = POTemplate.sourcepackagename AND
66 # POTemplate.name = templatename
67 # WHERE Packaging.productseries = productseries
68 #
69 if templatename is None:
70 potemplate_condition = And(
71 Packaging.distroseriesID == POTemplate.distroseriesID,
72 Packaging.sourcepackagenameID == POTemplate.sourcepackagenameID)
73 else:
74 potemplate_condition = And(
75 Packaging.distroseriesID == POTemplate.distroseriesID,
76 Packaging.sourcepackagenameID ==
77 POTemplate.sourcepackagenameID,
78 POTemplate.name == templatename)
79 if template_only:
80 prejoin = Join(
81 Packaging,
82 POTemplate,
83 potemplate_condition)
84 result_classes = POTemplate
85 else:
86 prejoin = LeftJoin(
87 Join(
88 Join(
89 Packaging, DistroSeries,
90 Packaging.distroseriesID == DistroSeries.id),
91 SourcePackageName,
92 Packaging.sourcepackagenameID == SourcePackageName.id),
93 POTemplate,
94 potemplate_condition)
95 result_classes = (DistroSeries, SourcePackageName, POTemplate)
96 conditions = [
97 Packaging.productseries == productseries,
98 ]
99 return IStore(Packaging).using(prejoin).find(
100 result_classes, *conditions)
101
102
103def find_upstream_sharing_info(distroseries, sourcepackagename,
104 templatename=None, template_only=False):
105 """Return a `ResultSet` of sharing information for this sourcepackage.
106
107 :param distroseries: The target distroseries or None.
108 :param sourcepackagename: The target sourcepackagename or None.
109 :param templatename: The name of the template to find information for or
110 None to get information about any sharing template in any series.
111 :param template_only: Return only `POTemplate` instances.
112 :returns: A ResultSet of (ProductSeries, POTemplate) tuples.
113 """
114 # SELECT *
115 # FROM Packaging
116 # JOIN ProductSeries
117 # ON Packaging.productseries = Productseris.id
118 # LEFT JOIN POTemplate
119 # ON Packaging.productseries = POTemplate.productseries AND
120 # POTemplate.name = templatename
121 # WHERE Packaging.distroseries = distroseries AND
122 # Packaging.sourcepackagename = sourcepackagename
123 #
124 if templatename is None:
125 potemplate_condition = (
126 Packaging.productseriesID == POTemplate.productseriesID)
127 else:
128 potemplate_condition = And(
129 Packaging.productseriesID == POTemplate.productseriesID,
130 POTemplate.name == templatename)
131 if template_only:
132 prejoin = Join(
133 Packaging, POTemplate, potemplate_condition)
134 result_classes = POTemplate
135 else:
136 prejoin = LeftJoin(
137 Join(
138 Packaging, ProductSeries,
139 Packaging.productseriesID == ProductSeries.id),
140 POTemplate,
141 potemplate_condition)
142 result_classes = (ProductSeries, POTemplate)
143 conditions = [
144 Packaging.distroseries == distroseries,
145 Packaging.sourcepackagename == sourcepackagename,
146 ]
147
148 return IStore(Packaging).using(prejoin).find(
149 result_classes, *conditions)
150
151
152def get_ubuntu_sharing_info(productseries, templatename=None):
153 """Return a list of sharing information for the given target."""
154 return list(find_ubuntu_sharing_info(productseries, templatename))
155
156
157def get_upstream_sharing_info(distroseries, sourcepackagename,
158 templatename=None):
159 """Return a list of sharing information for the given target."""
160 return list(find_upstream_sharing_info(
161 distroseries, sourcepackagename, templatename))
162
163
164def has_ubuntu_template(productseries, templatename):
165 """Check for existence of ubuntu template."""
166 result = find_ubuntu_sharing_info(
167 productseries, templatename, template_only=True)
168 return not result.is_empty()
169
170
171def has_upstream_template(distroseries, sourcepackagename, templatename):
172 """Check for existence of upstream template."""
173 result = find_upstream_sharing_info(
174 distroseries, sourcepackagename, templatename,
175 template_only=True)
176 return not result.is_empty()