1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
= TranslationBuildApprover =
The TranslationBuildApprover is a much simpler approver than the
TranslationBranchApprover. The latter tries to detect when templates have
been removed or renamed and refuses to approve anything when that happens.
This new approver does not care about these things but tries to approve as
many templates as possible. If this behavior proofs practical, it should
replace the TranslationBranchApprover in the future.
>>> from lp.translations.interfaces.translationimportqueue import (
... ITranslationImportQueue)
>>> queue = getUtility(ITranslationImportQueue)
>>> importer_person = factory.makePerson()
>>> from lp.translations.model.approver import TranslationBuildApprover
>>> def makeQueueEntry(path, series):
... return queue.addOrUpdateEntry(
... path, "#Dummy content.", False, importer_person,
... productseries=series)
>>> login("foo.bar@canonical.com")
It will approve all template files that it can derive a name from. It will
create a new template if none is found by that name.
>>> productseries = factory.makeProductSeries()
>>> approver = TranslationBuildApprover(
... ["po/my_domain.pot"], productseries=productseries)
>>> entry = makeQueueEntry("po/my_domain.pot", productseries)
>>> print entry.status.title
Needs Review
>>> entry = approver.approve(entry)
>>> print entry.status.title
Approved
If a template with the name exists, it will target the import entry to it and
not create a new template.
>>> productseries = factory.makeProductSeries()
>>> existing_potemplate = factory.makePOTemplate(
... name='existing-domain', productseries=productseries)
>>> approver = TranslationBuildApprover(
... ["po/existing_domain.pot"], productseries=productseries)
>>> entry = makeQueueEntry(
... "po/existing_domain.pot", productseries)
>>> entry = approver.approve(entry)
>>> print entry.status.title
Approved
>>> print entry.potemplate == existing_potemplate
True
A template file with generic names is only approved if it is the only one that
is being imported and the series has zero or one templates. If no template
exists, a template with the name of the product is created.
>>> product = factory.makeProduct(name='fooproduct')
>>> productseries = factory.makeProductSeries(product=product)
>>> generic_entry = makeQueueEntry('po/messages.pot', productseries)
>>> approver = TranslationBuildApprover(
... ['po/messages.pot'], productseries=productseries)
>>> generic_entry = approver.approve(generic_entry)
>>> print generic_entry.status.title
Approved
>>> print generic_entry.potemplate.translation_domain
fooproduct
>>> print generic_entry.potemplate.name
fooproduct
If there are other files or templates, files with generic names are not
approved. Only the ones containing a translation domain are approved.
>>> productseries = factory.makeProductSeries()
>>> approver = TranslationBuildApprover(
... ["po/messages.pot", "validdomain.pot"],
... productseries=productseries)
>>> generic_entry = makeQueueEntry("po/messages.pot", productseries)
>>> generic_entry = approver.approve(generic_entry)
>>> print generic_entry.status.title
Needs Review
>>> valid_entry = makeQueueEntry("validdomain.pot", productseries)
>>> valid_entry = approver.approve(valid_entry)
>>> print valid_entry.status.title
Approved
|