Merge lp:~henninge/launchpad/devel-741571-filter-templates-in-upload into lp:launchpad

Proposed by Henning Eggers
Status: Merged
Approved by: Henning Eggers
Approved revision: no longer in the source branch.
Merged at revision: 12659
Proposed branch: lp:~henninge/launchpad/devel-741571-filter-templates-in-upload
Merge into: lp:launchpad
Prerequisite: lp:~henninge/launchpad/devel-605924-hastranslationtemplates
Diff against target: 620 lines (+173/-76)
16 files modified
lib/lp/registry/model/distribution.py (+2/-5)
lib/lp/registry/model/distroseries.py (+14/-8)
lib/lp/registry/model/product.py (+2/-1)
lib/lp/registry/model/productseries.py (+4/-0)
lib/lp/registry/model/sourcepackage.py (+4/-0)
lib/lp/soyuz/model/sourcepackagerelease.py (+7/-14)
lib/lp/soyuz/tests/test_sourcepackagerelease.py (+10/-14)
lib/lp/translations/browser/productseries.py (+1/-4)
lib/lp/translations/browser/sourcepackage.py (+2/-8)
lib/lp/translations/doc/translationimportqueue.txt (+28/-3)
lib/lp/translations/interfaces/hastranslationtemplates.py (+11/-4)
lib/lp/translations/interfaces/translationimportqueue.py (+4/-1)
lib/lp/translations/model/hastranslationtemplates.py (+16/-0)
lib/lp/translations/model/translationimportqueue.py (+7/-3)
lib/lp/translations/tests/test_hastranslationtemplates.py (+60/-7)
lib/lp/translations/utilities/translation_import.py (+1/-4)
To merge this branch: bzr merge lp:~henninge/launchpad/devel-741571-filter-templates-in-upload
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+54688@code.launchpad.net

Commit message

[r=adeuring][bug=732612,741571] Always upload translation templates from soyuz builds.

Description of the change

= Summary =

Apart from fixing bug 741571 as described in the bug, this branch also
addresses a left-over issue from the previous branch. It implements
has_sharing_translation_templates which encapsualates a pattern that
appeared in many places. This makes the code shorter and much better to
read.

I also removed some lint that was already there.

== Implementation details ==

I find this a very straight forward branch and enjoyed coding it. I
hope you can follow along just as easily.

== Tests ==

Lot of stuff has been touched so I'd advise a full test run.

== Demo and Q/A ==

I am not sure how to QA soyuz stuff but you should see only templates
appear in the import queue of a sourcepackage that has upstream
templates.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/tests/test_potemplate.py
  lib/lp/registry/tests/test_productseries.py
  lib/lp/translations/templates/distroseries-translations.pt
  lib/lp/translations/tests/test_hastranslationtemplates.py
  lib/lp/translations/interfaces/potemplate.py
  lib/lp/registry/model/productseries.py
  lib/lp/translations/model/translationimportqueue.py
  lib/lp/soyuz/tests/test_sourcepackagerelease.py
  lib/lp/translations/browser/pofile.py
  lib/lp/translations/model/pofile.py
  lib/lp/soyuz/model/sourcepackagerelease.py
  lib/lp/translations/templates/productseries-translations.pt
  lib/lp/translations/doc/translationimportqueue.txt
  lib/lp/registry/interfaces/productseries.py
  lib/lp/registry/model/sourcepackage.py
  lib/lp/translations/browser/productseries.py
  lib/lp/registry/model/product.py
  lib/lp/translations/model/hastranslationtemplates.py
  lib/lp/registry/model/distroseries.py
  lib/lp/translations/utilities/translation_import.py
  lib/lp/translations/interfaces/hastranslationtemplates.py
  lib/lp/translations/model/potemplate.py
  lib/lp/registry/model/distribution.py
  lib/lp/translations/browser/sourcepackage.py
  lib/lp/translations/browser/potemplate.py
  lib/lp/translations/tests/test_translationtemplatescollection.py
  lib/lp/translations/interfaces/translationimportqueue.py
  lib/lp/translations/doc/distroseries-language.txt

./lib/lp/translations/browser/pofile.py
     788: E301 expected 1 blank line, found 2
     904: E301 expected 1 blank line, found 2
./lib/lp/soyuz/model/sourcepackagerelease.py
     201: redefinition of function 'copyright' from line 192
./lib/lp/registry/model/distroseries.py
     392: E301 expected 1 blank line, found 2

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

thanks for this fast buf fix!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/distribution.py'
2--- lib/lp/registry/model/distribution.py 2011-03-24 12:04:21 +0000
3+++ lib/lp/registry/model/distribution.py 2011-03-24 12:04:23 +0000
4@@ -1822,11 +1822,7 @@
5 assert sourcepackage is not None, (
6 "Translations sharing policy requires a SourcePackage.")
7
8- productseries = sourcepackage.productseries
9- has_upstream_translations = (
10- productseries is not None and
11- productseries.has_current_translation_templates)
12- if not has_upstream_translations:
13+ if not sourcepackage.has_sharing_translation_templates:
14 # There is no known upstream template or series. Take the
15 # uploader's word for whether these are upstream translations
16 # (in which case they're shared) or not.
17@@ -1841,6 +1837,7 @@
18 # translations for upstream.
19 return purportedly_upstream
20
21+ productseries = sourcepackage.productseries
22 return productseries.product.invitesTranslationEdits(person, language)
23
24
25
26=== modified file 'lib/lp/registry/model/distroseries.py'
27--- lib/lp/registry/model/distroseries.py 2011-03-24 12:04:21 +0000
28+++ lib/lp/registry/model/distroseries.py 2011-03-24 12:04:23 +0000
29@@ -463,17 +463,18 @@
30 translatable messages, and the source package release's component.
31 """
32 find_spec = (
33- SQL("DISTINCT ON (score, sourcepackagename.name) TRUE as _ignored"),
34+ SQL("DISTINCT ON (score, sourcepackagename.name) "
35+ "TRUE as _ignored"),
36 SourcePackageName,
37 SQL("""
38 coalesce(total_bug_heat, 0) + coalesce(po_messages, 0) +
39 CASE WHEN component = 1 THEN 1000 ELSE 0 END AS score"""),
40 SQL("coalesce(bug_count, 0) AS bug_count"),
41 SQL("coalesce(total_messages, 0) AS total_messages"))
42- # This does not use _current_sourcepackage_joins_and_conditions because
43- # the two queries are working on different data sets - +needs-packaging
44- # was timing out and +packaging wasn't, and destabilising things
45- # unnecessarily is not good.
46+ # This does not use _current_sourcepackage_joins_and_conditions
47+ # because the two queries are working on different data sets -
48+ # +needs-packaging was timing out and +packaging wasn't, and
49+ # destabilising things unnecessarily is not good.
50 origin = SQL("""
51 SourcePackageName, (SELECT
52 spr.sourcepackagename,
53@@ -515,7 +516,7 @@
54 distroseries=self,
55 active_status=active_publishing_status,
56 primary=ArchivePurpose.PRIMARY))
57- condition = SQL("""sourcepackagename.id = spn_info.sourcepackagename""")
58+ condition = SQL("sourcepackagename.id = spn_info.sourcepackagename")
59 results = IStore(self).using(origin).find(find_spec, condition)
60 results = results.order_by('score DESC', SourcePackageName.name)
61
62@@ -571,7 +572,7 @@
63
64 @property
65 def _current_sourcepackage_po_weight(self):
66- """See getPrioritized*."""
67+ """See getPrioritized*."""
68 # Bugs and PO messages are heuristically scored. These queries
69 # can easily timeout so filters and weights are used to create
70 # an acceptable prioritization of packages that is fast to excecute.
71@@ -580,7 +581,7 @@
72 @property
73 def _current_sourcepackage_joins_and_conditions(self):
74 """The SQL joins and conditions to prioritize source packages.
75-
76+
77 Used for getPrioritizedPackagings only.
78 """
79 # Bugs and PO messages are heuristically scored. These queries
80@@ -1907,6 +1908,11 @@
81 """See `IHasTranslationTemplates`."""
82 return TranslationTemplatesCollection().restrictDistroSeries(self)
83
84+ def getSharingPartner(self):
85+ """See `IHasTranslationTemplates`."""
86+ # No sharing partner is defined for DistroSeries.
87+ return None
88+
89 def getSuite(self, pocket):
90 """See `IDistroSeries`."""
91 if pocket == PackagePublishingPocket.RELEASE:
92
93=== modified file 'lib/lp/registry/model/product.py'
94--- lib/lp/registry/model/product.py 2011-03-24 12:04:21 +0000
95+++ lib/lp/registry/model/product.py 2011-03-24 12:04:23 +0000
96@@ -1588,6 +1588,7 @@
97 conditions.append(
98 SQL("Product.fti @@ ftq(%s) " % sqlvalues(text)))
99 result = IStore(Product).find(Product, *conditions)
100+
101 def eager_load(rows):
102 product_ids = set(obj.id for obj in rows)
103 if not product_ids:
104@@ -1601,7 +1602,7 @@
105 if not safe_hasattr(cache, '_cached_licenses'):
106 cache._cached_licenses = []
107 for subscription in IStore(CommercialSubscription).find(
108- CommercialSubscription,
109+ CommercialSubscription,
110 CommercialSubscription.productID.is_in(product_ids)):
111 cache = caches[subscription.productID]
112 cache.commercial_subscription = subscription
113
114=== modified file 'lib/lp/registry/model/productseries.py'
115--- lib/lp/registry/model/productseries.py 2011-03-24 12:04:21 +0000
116+++ lib/lp/registry/model/productseries.py 2011-03-24 12:04:23 +0000
117@@ -537,6 +537,10 @@
118 """See `IHasTranslationTemplates`."""
119 return TranslationTemplatesCollection().restrictProductSeries(self)
120
121+ def getSharingPartner(self):
122+ """See `IHasTranslationTemplates`."""
123+ return self.getUbuntuTranslationFocusPackage()
124+
125 @property
126 def potemplate_count(self):
127 """See `IProductSeries`."""
128
129=== modified file 'lib/lp/registry/model/sourcepackage.py'
130--- lib/lp/registry/model/sourcepackage.py 2011-03-04 21:15:00 +0000
131+++ lib/lp/registry/model/sourcepackage.py 2011-03-24 12:04:23 +0000
132@@ -676,6 +676,10 @@
133 collection = collection.restrictDistroSeries(self.distroseries)
134 return collection.restrictSourcePackageName(self.sourcepackagename)
135
136+ def getSharingPartner(self):
137+ """See `IHasTranslationTemplates`."""
138+ return self.productseries
139+
140 def getBranch(self, pocket):
141 """See `ISourcePackage`."""
142 store = Store.of(self.sourcepackagename)
143
144=== modified file 'lib/lp/soyuz/model/sourcepackagerelease.py'
145--- lib/lp/soyuz/model/sourcepackagerelease.py 2011-03-24 12:04:21 +0000
146+++ lib/lp/soyuz/model/sourcepackagerelease.py 2011-03-24 12:04:23 +0000
147@@ -623,20 +623,13 @@
148
149 queue = getUtility(ITranslationImportQueue)
150
151- # We do not want to override upstream translations, if
152- # translation sharing is enabled.
153- # Avoid circular imports.
154- productseries = self.sourcepackage.productseries
155- has_upstream_templates = (
156- productseries is not None and
157- productseries.has_translation_templates
158- )
159- if not has_upstream_templates:
160- queue.addOrUpdateEntriesFromTarball(
161- tarball, by_maintainer, importer,
162- sourcepackagename=self.sourcepackagename,
163- distroseries=self.upload_distroseries,
164- filename_filter=_filter_ubuntu_translation_file)
165+ only_templates=self.sourcepackage.has_sharing_translation_templates
166+ queue.addOrUpdateEntriesFromTarball(
167+ tarball, by_maintainer, importer,
168+ sourcepackagename=self.sourcepackagename,
169+ distroseries=self.upload_distroseries,
170+ filename_filter=_filter_ubuntu_translation_file,
171+ only_templates=only_templates)
172
173 def getDiffTo(self, to_sourcepackagerelease):
174 """See ISourcePackageRelease."""
175
176=== modified file 'lib/lp/soyuz/tests/test_sourcepackagerelease.py'
177--- lib/lp/soyuz/tests/test_sourcepackagerelease.py 2011-03-24 12:04:21 +0000
178+++ lib/lp/soyuz/tests/test_sourcepackagerelease.py 2011-03-24 12:04:23 +0000
179@@ -19,13 +19,6 @@
180 )
181
182
183-def has_upstream_template(sourcepackage):
184- productseries = sourcepackage.productseries
185- if productseries is None:
186- return False
187- return productseries.has_translation_templates
188-
189-
190 class TestSourcePackageRelease(TestCaseWithFactory):
191
192 layer = LaunchpadFunctionalLayer
193@@ -76,6 +69,7 @@
194 """Create an LibraryFileAlias containing dummy translation data."""
195 test_tar_content = {
196 'source/po/foo.pot': 'Foo template',
197+ 'source/po/eo.po': 'Foo translation',
198 }
199 tarfile_content = LaunchpadWriteTarFile.files_to_string(
200 test_tar_content)
201@@ -86,18 +80,19 @@
202 # SourcePackageRelease.attachTranslationFiles() creates a job
203 # in the translation import queue.
204 spr = self.factory.makeSourcePackageRelease()
205- self.assertFalse(has_upstream_template(spr.sourcepackage))
206+ self.assertFalse(spr.sourcepackage.has_sharing_translation_templates)
207 lfa = self.makeTranslationsLFA()
208 transaction.commit()
209 spr.attachTranslationFiles(lfa, True, spr.maintainer)
210 translation_import_queue = getUtility(ITranslationImportQueue)
211 entries_in_queue = translation_import_queue.getAllEntries(
212 target=spr.sourcepackage).count()
213- self.assertEqual(1, entries_in_queue)
214+ self.assertEqual(2, entries_in_queue)
215
216 def test_attachTranslationFiles__translation_sharing(self):
217 # If translation sharing is enabled,
218- # SourcePackageRelease.attachTranslationFiles() does nothing.
219+ # SourcePackageRelease.attachTranslationFiles() only attaches
220+ # templates.
221 spr = self.factory.makeSourcePackageRelease()
222 sourcepackage = spr.sourcepackage
223 productseries = self.factory.makeProductSeries()
224@@ -105,11 +100,12 @@
225 with person_logged_in(sourcepackage.distroseries.owner):
226 sourcepackage.setPackaging(
227 productseries, sourcepackage.distroseries.owner)
228- self.assertTrue(has_upstream_template(sourcepackage))
229+ self.assertTrue(sourcepackage.has_sharing_translation_templates)
230 lfa = self.makeTranslationsLFA()
231 transaction.commit()
232 spr.attachTranslationFiles(lfa, True, spr.maintainer)
233 translation_import_queue = getUtility(ITranslationImportQueue)
234- entries_in_queue = translation_import_queue.getAllEntries(
235- target=sourcepackage).count()
236- self.assertEqual(0, entries_in_queue)
237+ entries = translation_import_queue.getAllEntries(
238+ target=sourcepackage)
239+ self.assertEqual(1, entries.count())
240+ self.assertTrue(entries[0].path.endswith('.pot'))
241
242=== modified file 'lib/lp/translations/browser/productseries.py'
243--- lib/lp/translations/browser/productseries.py 2011-03-24 12:04:21 +0000
244+++ lib/lp/translations/browser/productseries.py 2011-03-24 12:04:23 +0000
245@@ -456,10 +456,7 @@
246 return check_permission("launchpad.TranslationsAdmin", self.context)
247
248 def is_sharing(self):
249- sourcepackage = self.context.getUbuntuTranslationFocusPackage()
250- if sourcepackage is None:
251- return False
252- return sourcepackage.has_current_translation_templates
253+ return self.context.has_sharing_translation_templates
254
255 @property
256 def sharing_sourcepackage(self):
257
258=== modified file 'lib/lp/translations/browser/sourcepackage.py'
259--- lib/lp/translations/browser/sourcepackage.py 2011-03-24 12:04:21 +0000
260+++ lib/lp/translations/browser/sourcepackage.py 2011-03-24 12:04:23 +0000
261@@ -55,10 +55,7 @@
262 return "Translations for %s" % self.context.displayname
263
264 def is_sharing(self):
265- productseries = self.context.productseries
266- if productseries is None:
267- return False
268- return productseries.has_current_translation_templates
269+ return self.context.has_sharing_translation_templates
270
271 @property
272 def sharing_productseries(self):
273@@ -119,10 +116,7 @@
274 page_title = "Sharing details"
275
276 def is_sharing(self):
277- productseries = self.context.productseries
278- if productseries is None:
279- return False
280- return productseries.has_current_translation_templates
281+ return self.context.has_sharing_translation_templates
282
283 def initialize(self):
284 if not getFeatureFlag('translations.sharing_information.enabled'):
285
286=== modified file 'lib/lp/translations/doc/translationimportqueue.txt'
287--- lib/lp/translations/doc/translationimportqueue.txt 2010-12-23 10:21:21 +0000
288+++ lib/lp/translations/doc/translationimportqueue.txt 2011-03-24 12:04:23 +0000
289@@ -1151,7 +1151,32 @@
290 warty evolution | None | po/sr.po
291
292 Attach the sample tarball to the 'evolution-2.2-test' template in evolution
293-product. There will be three new entries from the tarball.
294+product. We can ask to only upload the template from the tarball and ignore
295+the other files.
296+
297+ >>> translationimportqueue.addOrUpdateEntriesFromTarball(
298+ ... tarfile_content, by_maintainer, rosetta_experts,
299+ ... productseries=evolution_productseries,
300+ ... potemplate=evolution_22_test_template,
301+ ... only_templates=True)
302+ (1, [])
303+
304+And this new entry in the queue appears in the list.
305+
306+ >>> print_queue_entries(queue)
307+ hoary evolution | evolution | po/sr.po
308+ firefox | firefox | foo/bar.pot
309+ evolution | evolution-2.2-test | po/evolution-2.2-test.pot
310+ evolution | evolution-2.2-test | po/pt_BR.po
311+ firefox | None | foo/bar.po
312+ evolution | None | po/sr.po
313+ hoary evolution | None | po/evolution-2.2.pot
314+ warty evolution | None | po/sr.po
315+ evolution | evolution-2.2-test | foo.pot
316+
317+
318+But we really want all files from the tarball, so we upload them all.
319+There will be three new entries from the tarball.
320
321 >>> translationimportqueue.addOrUpdateEntriesFromTarball(
322 ... tarfile_content, by_maintainer, rosetta_experts,
323@@ -1170,8 +1195,8 @@
324 evolution | None | po/sr.po
325 hoary evolution | None | po/evolution-2.2.pot
326 warty evolution | None | po/sr.po
327+ evolution | evolution-2.2-test | foo.pot
328 evolution | evolution-2.2-test | es.po
329- evolution | evolution-2.2-test | foo.pot
330 evolution | evolution-2.2-test | fr.po
331
332 It is possible to update the content of an entry in the queue.
333@@ -1244,8 +1269,8 @@
334 >>> print_queue_entries(queue)
335 hoary ...
336 ...
337+ evolution | evolution-2.2-test | foo.pot
338 evolution | evolution-2.2-test | es.po
339- evolution | evolution-2.2-test | foo.pot
340 evolution | evolution-2.2-test | fr.po
341 evolution | evolution-2.2 | es.po
342 evolution | evolution-2.2 | foo.pot
343
344=== modified file 'lib/lp/translations/interfaces/hastranslationtemplates.py'
345--- lib/lp/translations/interfaces/hastranslationtemplates.py 2011-03-24 12:04:21 +0000
346+++ lib/lp/translations/interfaces/hastranslationtemplates.py 2011-03-24 12:04:23 +0000
347@@ -36,6 +36,10 @@
348 title=_("Does this object have obsolete translation templates?"),
349 readonly=True)
350
351+ has_sharing_translation_templates = Bool(
352+ title=_("Does this object have sharing translation templates?"),
353+ readonly=True)
354+
355 has_translation_files = Bool(
356 title=_("Does this object have translation files?"),
357 readonly=True)
358@@ -47,6 +51,13 @@
359 translation target that implements this interface.
360 """
361
362+ def getSharingPartner():
363+ """Return the object on the other side of the packaging link.
364+
365+ Return the object that is sharing translations with this one on the
366+ other side of a packaging link. It must also implement this interface.
367+ """
368+
369 def getCurrentTemplatesCollection():
370 """Return `TranslationTemplatesCollection` of current templates.
371
372@@ -54,8 +65,6 @@
373 `IPOTemplate`.iscurrent and the `official_rosetta` flag for its
374 containing `Product` or `Distribution` are set to True.
375 """
376- # XXX JeroenVermeulen 2010-07-16 bug=605924: Move the
377- # official_rosetta distinction into browser code.
378
379 def getCurrentTranslationTemplates(just_ids=False):
380 """Return an iterator over all active translation templates.
381@@ -68,8 +77,6 @@
382 `IPOTemplate`.iscurrent and the `official_rosetta` flag for its
383 containing `Product` or `Distribution` are set to True.
384 """
385- # XXX JeroenVermeulen 2010-07-16 bug=605924: Move the
386- # official_rosetta distinction into browser code.
387
388 def getCurrentTranslationFiles(just_ids=False):
389 """Return an iterator over all active translation files.
390
391=== modified file 'lib/lp/translations/interfaces/translationimportqueue.py'
392--- lib/lp/translations/interfaces/translationimportqueue.py 2011-01-21 20:37:59 +0000
393+++ lib/lp/translations/interfaces/translationimportqueue.py 2011-03-24 12:04:23 +0000
394@@ -335,7 +335,8 @@
395
396 def addOrUpdateEntriesFromTarball(content, by_maintainer, importer,
397 sourcepackagename=None, distroseries=None, productseries=None,
398- potemplate=None, filename_filter=None, approver_factory=None):
399+ potemplate=None, filename_filter=None, approver_factory=None,
400+ only_templates=False):
401 """Add all .po or .pot files from the tarball at :content:.
402
403 :arg content: is a tarball stream.
404@@ -350,6 +351,8 @@
405 :arg approver_factory: is a factory that can be called to create an
406 approver. The method invokes the approver on any queue entries
407 that it creates. If this is None, no approval is performed.
408+ :arg only_templates: Flag to indicate that only translation templates
409+ in the tarball should be used.
410 :return: A tuple of the number of successfully processed files and a
411 list of those filenames that could not be processed correctly.
412
413
414=== modified file 'lib/lp/translations/model/hastranslationtemplates.py'
415--- lib/lp/translations/model/hastranslationtemplates.py 2011-03-24 12:04:21 +0000
416+++ lib/lp/translations/model/hastranslationtemplates.py 2011-03-24 12:04:23 +0000
417@@ -34,6 +34,14 @@
418 raise NotImplementedError(
419 "Child class must provide getTemplatesCollection.")
420
421+ def getSharingPartner(self):
422+ """See `IHasTranslationTemplates`.
423+
424+ To be provided by derived classes.
425+ """
426+ raise NotImplementedError(
427+ "Child class must provide getSharingPartner.")
428+
429 def _orderTemplates(self, result):
430 """Apply the conventional ordering to a result set of templates."""
431 return result.order_by(Desc(POTemplate.priority), POTemplate.name)
432@@ -72,6 +80,14 @@
433 self.getCurrentTranslationTemplates(
434 just_ids=True, current_value=False).any())
435
436+ @property
437+ def has_sharing_translation_templates(self):
438+ """See `IHasTranslationTemplates`."""
439+ other_side_obj = self.getSharingPartner()
440+ if other_side_obj is None:
441+ return False
442+ return other_side_obj.has_current_translation_templates
443+
444 def getCurrentTranslationFiles(self, just_ids=False):
445 """See `IHasTranslationTemplates`."""
446 if just_ids:
447
448=== modified file 'lib/lp/translations/model/translationimportqueue.py'
449--- lib/lp/translations/model/translationimportqueue.py 2011-01-11 16:15:52 +0000
450+++ lib/lp/translations/model/translationimportqueue.py 2011-03-24 12:04:23 +0000
451@@ -1009,7 +1009,7 @@
452 path = path_filter(path)
453 return path
454
455- def _isTranslationFile(self, path):
456+ def _isTranslationFile(self, path, only_templates):
457 """Is this a translation file that should be uploaded?"""
458 if path is None or path == '':
459 return False
460@@ -1024,11 +1024,15 @@
461 # Doesn't look like a supported translation file type.
462 return False
463
464+ if only_templates and not translation_importer.isTemplateName(path):
465+ return False
466+
467 return True
468
469 def addOrUpdateEntriesFromTarball(self, content, by_maintainer, importer,
470 sourcepackagename=None, distroseries=None, productseries=None,
471- potemplate=None, filename_filter=None, approver_factory=None):
472+ potemplate=None, filename_filter=None, approver_factory=None,
473+ only_templates=False):
474 """See ITranslationImportQueue."""
475 num_files = 0
476 conflict_files = []
477@@ -1045,7 +1049,7 @@
478 upload_files = {}
479 for name in self._iterTarballFiles(tarball):
480 path = self._makePath(name, filename_filter)
481- if self._isTranslationFile(path):
482+ if self._isTranslationFile(path, only_templates):
483 upload_files[name] = path
484 tarball.close()
485
486
487=== modified file 'lib/lp/translations/tests/test_hastranslationtemplates.py'
488--- lib/lp/translations/tests/test_hastranslationtemplates.py 2011-03-24 12:04:21 +0000
489+++ lib/lp/translations/tests/test_hastranslationtemplates.py 2011-03-24 12:04:23 +0000
490@@ -6,7 +6,6 @@
491 from zope.interface.verify import verifyObject
492
493 from canonical.testing.layers import ZopelessDatabaseLayer
494-from lp.app.enums import ServiceUsage
495 from lp.testing import TestCaseWithFactory
496 from lp.translations.interfaces.hastranslationtemplates import (
497 IHasTranslationTemplates,
498@@ -36,6 +35,16 @@
499 raise NotImplementedError(
500 'This must be provided by an executable test.')
501
502+ def createPackaging(self):
503+ """Creates a packaging link for the container."""
504+ raise NotImplementedError(
505+ 'This must be provided by an executable test.')
506+
507+ def createSharingTranslationTemplate(self):
508+ """Attaches a template to the sharing partner of the container."""
509+ raise NotImplementedError(
510+ 'This must be provided by an executable test.')
511+
512 def test_implements_interface(self):
513 # Make sure container implements IHasTranslationTemplates.
514 verifyObject(IHasTranslationTemplates, self.container)
515@@ -187,6 +196,21 @@
516 self.createTranslationTemplate()
517 self.assertTrue(self.container.has_obsolete_translation_templates)
518
519+ def test_has_sharing_translation_templates__no_link(self):
520+ # Without a packaging link, no sharing templates are found.
521+ self.assertFalse(self.container.has_sharing_translation_templates)
522+
523+ def test_has_sharing_translation_templates__no_templates(self):
524+ # Without templates on the other side, no sharing templates are found.
525+ self.createPackaging()
526+ self.assertFalse(self.container.has_sharing_translation_templates)
527+
528+ def test_has_sharing_translation_templates__templates(self):
529+ # Without templates on the other side, no sharing templates are found.
530+ self.createPackaging()
531+ self.createSharingTranslationTemplate()
532+ self.assertTrue(self.container.has_sharing_translation_templates)
533+
534 def test_has_translation_files(self):
535 # has_translations_files should only return true if the object has
536 # pofiles.
537@@ -264,11 +288,18 @@
538 potemplate=potemplate)
539 return pofile
540
541+ def createPackaging(self):
542+ self.packaging = self.factory.makePackagingLink(
543+ productseries=self.container, in_ubuntu=True)
544+ return self.packaging
545+
546+ def createSharingTranslationTemplate(self):
547+ return self.factory.makePOTemplate(
548+ sourcepackage=self.packaging.sourcepackage)
549+
550 def setUp(self):
551 super(TestProductSeriesHasTranslationTemplates, self).setUp()
552 self.container = self.factory.makeProductSeries()
553- self.product_or_distro = self.container.product
554- self.product_or_distro.translations_usage = ServiceUsage.LAUNCHPAD
555
556
557 class TestSourcePackageHasTranslationTemplates(
558@@ -289,11 +320,18 @@
559 potemplate=potemplate)
560 return pofile
561
562+ def createPackaging(self):
563+ self.packaging = self.factory.makePackagingLink(
564+ sourcepackage=self.container)
565+ return self.packaging
566+
567+ def createSharingTranslationTemplate(self):
568+ return self.factory.makePOTemplate(
569+ productseries=self.packaging.productseries)
570+
571 def setUp(self):
572 super(TestSourcePackageHasTranslationTemplates, self).setUp()
573 self.container = self.factory.makeSourcePackage()
574- self.product_or_distro = self.container.distroseries.distribution
575- self.product_or_distro.translations_usage = ServiceUsage.LAUNCHPAD
576
577
578 class TestDistroSeriesHasTranslationTemplates(
579@@ -316,8 +354,23 @@
580 potemplate=potemplate)
581 return pofile
582
583+ def createPackaging(self):
584+ sourcepackage = self.factory.makeSourcePackage(
585+ distroseries=self.container)
586+ self.packaging = self.factory.makePackagingLink(
587+ sourcepackage=sourcepackage)
588+ return self.packaging
589+
590+ def createSharingTranslationTemplate(self):
591+ return self.factory.makePOTemplate(
592+ productseries=self.packaging.productseries)
593+
594 def setUp(self):
595 super(TestDistroSeriesHasTranslationTemplates, self).setUp()
596 self.container = self.factory.makeDistroRelease()
597- self.product_or_distro = self.container.distribution
598- self.product_or_distro.translations_usage = ServiceUsage.LAUNCHPAD
599+
600+ def test_has_sharing_translation_templates__templates(self):
601+ # This attribute is always False for DistroSeries
602+ self.createPackaging()
603+ self.createSharingTranslationTemplate()
604+ self.assertFalse(self.container.has_sharing_translation_templates)
605
606=== modified file 'lib/lp/translations/utilities/translation_import.py'
607--- lib/lp/translations/utilities/translation_import.py 2011-03-24 12:04:21 +0000
608+++ lib/lp/translations/utilities/translation_import.py 2011-03-24 12:04:23 +0000
609@@ -444,10 +444,7 @@
610 sourcepackage = getUtility(ISourcePackageFactory).new(
611 self.translation_import_queue_entry.sourcepackagename,
612 self.translation_import_queue_entry.distroseries)
613- productseries = sourcepackage.productseries
614- if productseries is None:
615- return True
616- return not productseries.has_current_translation_templates
617+ return not sourcepackage.has_sharing_translation_templates
618
619 @cachedproperty
620 def translations_are_msgids(self):