~launchpad-pqm/launchpad/devel

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
Uploading translations
----------------------

It's time to check the translation upload function.

We need a test tarball uploaded into librarian to run this test. We will
upload the same sampledata tarball twice, one public and one restricted
`LibraryFileAlias` objects.

    >>> import os.path
    >>> import lp.translations
    >>> tarball_path = os.path.join(
    ...     os.path.dirname(lp.translations.__file__),
    ...     'doc/sourcepackagerelease-translations.tar.gz')
    >>> tarball = open(tarball_path)
    >>> tarball_size = len(tarball.read())
    >>> tarball.seek(0)

    >>> from lp.services.librarian.interfaces import (
    ...     ILibraryFileAliasSet)
    >>> public_translation = getUtility(ILibraryFileAliasSet).create(
    ...     name='test.tar.gz',
    ...     size=tarball_size,
    ...     file=tarball,
    ...     contentType='application/x-gtar')

    >>> tarball.seek(0)
    >>> restricted_translation = getUtility(ILibraryFileAliasSet).create(
    ...     name='test.tar.gz',
    ...     size=tarball_size,
    ...     file=tarball,
    ...     contentType='application/x-gtar',
    ...     restricted=True)

Commit, so uploaded contents are available in the current test.

    >>> transaction.commit()

We will use an arbitrary source package release from the sampledata.

    >>> from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
    >>> spr_test = SourcePackageRelease.get(20)
    >>> print spr_test.title
    pmount - 0.1-1

And the 'katie' celebrity as the user responsible for the transalation.

    >>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
    >>> katie = getUtility(ILaunchpadCelebrities).katie

Before the final upload, we can see that the translation queue for the
testing source package is empty.

    >>> from lp.translations.interfaces.translationimportqueue import (
    ...     ITranslationImportQueue)
    >>> translation_import_queue = getUtility(ITranslationImportQueue)
    >>> translation_import_queue.getAllEntries(
    ...     target=spr_test.sourcepackage).count()
    0

Now we bind both uploaded translations, the public and the restricted
ones, to the testing source package.

    >>> spr_test.attachTranslationFiles(public_translation, True, katie)

    >>> spr_test.attachTranslationFiles(restricted_translation, True, katie)

And the queue should have 2 entries, with exactly the same contents.

    >>> queue_entries = translation_import_queue.getAllEntries(
    ...     target=spr_test.sourcepackage)

    >>> queue_entries.count()
    2

    >>> for entry in queue_entries:
    ...     print entry.path, entry.importer.name
    something/en-US.xpi  katie
    po/es.po             katie

Commit, so the uploaded translations become available to the scripts.

    >>> transaction.commit()

Now, we need to do the final import. It's done as a two steps procedure.

The first one, approves the import.

    >>> import subprocess, sys
    >>> process = subprocess.Popen([
    ...     sys.executable, 'cronscripts/rosetta-approve-imports.py'
    ...     ], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
    ...     stderr=subprocess.STDOUT
    ...     )
    >>> (output, empty) = process.communicate()
    >>> print output
    INFO    Creating lockfile:
         /var/lock/launchpad-translations-import-queue-gardener.lock
    INFO    The automatic approval system approved some entries.
    INFO    Removed 2 entries from the queue.
    <BLANKLINE>

The second one, executes the import.

    >>> import subprocess, sys
    >>> process = subprocess.Popen([
    ...     sys.executable, 'cronscripts/rosetta-poimport.py'
    ...     ], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
    ...     stderr=subprocess.STDOUT
    ...     )
    >>> (output, empty) = process.communicate()
    >>> print output
    INFO    Creating lockfile: /var/lock/launchpad-rosetta-poimport.lock
    INFO    Importing: Spanish (es) translation of pmount in Ubuntu Hoary
            package "pmount"
    ...


Translation file names
......................

A callback tells the translations import queue what to do with the file
names found in the tarball:

    >>> from lp.soyuz.model.sourcepackagerelease import (
    ...     _filter_ubuntu_translation_file)

Anything not in the "source/" directory is ignored.

    >>> print _filter_ubuntu_translation_file('foo/bar.po')
    None

Files in source/ have that directory stripped off.

    >>> print _filter_ubuntu_translation_file('source/bar.po')
    bar.po

Files in source/debian/po/* and a few other paths are ignored.

Ones in debian/po are generally debconf translations, unused in Ubuntu.

    >>> print _filter_ubuntu_translation_file('source/debian/po/bar.po')
    None

Ones in d-i are Debian Installer translations.  Ubuntu builds those
translations very differently from how Debian does it, so we don't need
these uploads.

    >>> print _filter_ubuntu_translation_file('source/d-i/foo.po')
    None

Then there are some documentation directories whose contents we can't
translate in Launchpad.

    >>> print _filter_ubuntu_translation_file('source/help/xx.pot')
    None

    >>> print _filter_ubuntu_translation_file('source/man/po/yy.po')
    None

    >>> print _filter_ubuntu_translation_file('source/man/po4a/zz.pot')
    None

The match is on a path component boundary, so we don't filter other
uploads whose paths happen to begin with the same words as a directory
we filter.

    >>> print _filter_ubuntu_translation_file('source/debian/pool.pot')
    debian/pool.pot

    >>> print _filter_ubuntu_translation_file('source/d-input.pot')
    d-input.pot

    >>> print _filter_ubuntu_translation_file('source/man/positive/nl.po')
    man/positive/nl.po