11666.3.2
by Curtis Hovey
Fixed test imports. |
1 |
PO import script |
2 |
================ |
|
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
3 |
|
8751.1.10
by Danilo Šegan
Remove dependency on glob imports from most of the stuff. |
4 |
>>> from lp.translations.model.potemplate import POTemplate |
13130.1.6
by Curtis Hovey
Move ILaunchpadCelebrity to lp.app. |
5 |
>>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities |
11666.3.2
by Curtis Hovey
Fixed test imports. |
6 |
>>> from lp.registry.interfaces.person import IPersonSet |
11818.3.1
by Jeroen Vermeulen
Split out lp.translations.enums and lp.translations.interfaces.hastranslationimports. |
7 |
>>> from lp.translations.enums import RosettaImportStatus |
8751.1.10
by Danilo Šegan
Remove dependency on glob imports from most of the stuff. |
8 |
>>> from lp.translations.interfaces.translationimportqueue import ( |
9 |
... ITranslationImportQueue, |
|
11818.3.1
by Jeroen Vermeulen
Split out lp.translations.enums and lp.translations.interfaces.hastranslationimports. |
10 |
... ) |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
11 |
>>> from canonical.config import config |
12 |
>>> import datetime |
|
13 |
>>> import pytz |
|
14 |
>>> UTC = pytz.timezone('UTC') |
|
9893.3.1
by Henning Eggers
Merged API work. |
15 |
>>> rosetta_experts = getUtility(ILaunchpadCelebrities).rosetta_experts |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
16 |
|
17 |
Login as an admin to be able to do changes to the import queue. |
|
18 |
||
19 |
>>> login('carlos@canonical.com') |
|
20 |
||
21 |
>>> translation_import_queue = getUtility(ITranslationImportQueue) |
|
22 |
>>> import transaction |
|
23 |
||
24 |
We don't care about a POTemplate we are working with, so just pick any. |
|
25 |
||
26 |
>>> potemplate = POTemplate.get(1) |
|
27 |
||
28 |
Provide a POFile with Last-Translator set to a user not existing in |
|
29 |
the sampledata. |
|
30 |
||
31 |
>>> print getUtility(IPersonSet).getByEmail('danilo@canonical.com') |
|
32 |
None |
|
33 |
||
34 |
>>> pofile = potemplate.newPOFile('sr') |
|
35 |
>>> pofile_content = r''' |
|
36 |
... msgid "" |
|
37 |
... msgstr "" |
|
38 |
... "PO-Revision-Date: 2005-06-04 20:41+0100\n" |
|
39 |
... "Last-Translator: Danilo Šegan <danilo@canonical.com>\n" |
|
40 |
... "Content-Type: text/plain; charset=UTF-8\n" |
|
41 |
... "X-Rosetta-Export-Date: %s\n" |
|
42 |
... |
|
43 |
... msgid "Foo %%s" |
|
44 |
... msgstr "Bar" |
|
45 |
... ''' % datetime.datetime.now(UTC).isoformat() |
|
46 |
||
47 |
We clean the import queue. |
|
48 |
||
49 |
>>> for entry in translation_import_queue: |
|
50 |
... translation_import_queue.remove(entry) |
|
8137.16.1
by Jeroen Vermeulen
Oops, previous commit included ugly prototype Ajax code. |
51 |
>>> translation_import_queue.countEntries() |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
52 |
0 |
53 |
||
7184.1.2
by Danilo Šegan
Improve narrative as per kiko's suggestions. |
54 |
Product must have privileges which allow suggestions from those |
55 |
without special privileges, like "cprov": structured privileges are |
|
56 |
enough (but we could go with "open" as well, which would allow not |
|
57 |
only suggestions but full translations as well). |
|
7184.1.1
by Danilo Šegan
Fix privileges for poimport script. |
58 |
|
11869.1.1
by Jeroen Vermeulen
Move TranslationPermission to enums to reduce import cycles. |
59 |
>>> from lp.translations.enums import TranslationPermission |
7184.1.1
by Danilo Šegan
Fix privileges for poimport script. |
60 |
>>> product = pofile.potemplate.productseries.product |
61 |
>>> product.translationpermission = TranslationPermission.STRUCTURED |
|
62 |
||
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
63 |
We add a PO file to the import queue, approving it along the way. |
64 |
||
7184.1.1
by Danilo Šegan
Fix privileges for poimport script. |
65 |
>>> cprov = getUtility(IPersonSet).getByName('cprov') |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
66 |
>>> entry = translation_import_queue.addOrUpdateEntry( |
7184.1.1
by Danilo Šegan
Fix privileges for poimport script. |
67 |
... pofile.path, pofile_content, False, cprov, |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
68 |
... sourcepackagename=pofile.potemplate.sourcepackagename, |
69 |
... distroseries=pofile.potemplate.distroseries, |
|
70 |
... productseries=pofile.potemplate.productseries) |
|
71 |
>>> entry.pofile = pofile |
|
9893.3.1
by Henning Eggers
Merged API work. |
72 |
>>> entry.setStatus(RosettaImportStatus.APPROVED, rosetta_experts) |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
73 |
>>> transaction.commit() |
8137.16.1
by Jeroen Vermeulen
Oops, previous commit included ugly prototype Ajax code. |
74 |
>>> translation_import_queue.countEntries() |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
75 |
1 |
76 |
||
7184.1.2
by Danilo Šegan
Improve narrative as per kiko's suggestions. |
77 |
Now we run the import script, making sure that the DB user it runs under |
78 |
has enough privileges for the script to run to completion. |
|
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
79 |
|
80 |
>>> import os |
|
81 |
>>> import sys |
|
82 |
>>> import subprocess |
|
83 |
>>> script = os.path.join(config.root, "cronscripts", |
|
84 |
... "rosetta-poimport.py") |
|
85 |
>>> process = subprocess.Popen([sys.executable, script], |
|
86 |
... stdout=subprocess.PIPE, |
|
87 |
... stderr=subprocess.PIPE,) |
|
88 |
>>> stdout, stderr = process.communicate() |
|
89 |
>>> process.returncode |
|
90 |
0 |
|
91 |
>>> print stderr |
|
7675.624.73
by Tim Penhey
Some lock files, some job runs. |
92 |
INFO Creating lockfile: /var/lock/launchpad-rosetta-poimport.lock |
11666.3.7
by Curtis Hovey
Hushed lint. |
93 |
INFO Importing: Serbian (sr) ... of evolution-2.2 in Evolution trunk |
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
94 |
INFO Import requests completed. |
95 |
<BLANKLINE> |
|
96 |
>>> transaction.commit() |
|
7184.1.2
by Danilo Šegan
Improve narrative as per kiko's suggestions. |
97 |
|
98 |
A new Account for 'danilo@canonical.com' is created. |
|
99 |
||
6934.6.1
by Danilo Šegan
Add test and fix security.cfg. |
100 |
>>> danilo = getUtility(IPersonSet).getByEmail('danilo@canonical.com') |
101 |
>>> danilo.displayname |
|
102 |
u'Danilo \u0160egan' |
|
103 |