Merge lp:~cjwatson/launchpad/ttb-from-disk into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18362
Proposed branch: lp:~cjwatson/launchpad/ttb-from-disk
Merge into: lp:launchpad
Diff against target: 541 lines (+94/-78)
16 files modified
lib/lp/translations/doc/poexport-language-pack.txt (+3/-3)
lib/lp/translations/interfaces/translationimporter.py (+7/-6)
lib/lp/translations/interfaces/translationimportqueue.py (+5/-3)
lib/lp/translations/model/translationimportqueue.py (+24/-14)
lib/lp/translations/model/translationtemplatesbuildbehaviour.py (+7/-16)
lib/lp/translations/scripts/upload_translations.py (+6/-6)
lib/lp/translations/tests/test_translationimportqueue.py (+5/-5)
lib/lp/translations/utilities/kde_po_importer.py (+12/-6)
lib/lp/translations/utilities/tests/helpers.py (+3/-2)
lib/lp/translations/utilities/tests/test_gettext_po_importer.py (+3/-2)
lib/lp/translations/utilities/tests/test_kde_po_importer.py (+3/-2)
lib/lp/translations/utilities/tests/test_mozilla_xpi_importer.py (+3/-2)
lib/lp/translations/utilities/tests/test_translation_importer.py (+6/-4)
lib/lp/translations/utilities/tests/test_xpi_import.py (+3/-3)
lib/lp/translations/utilities/tests/test_xpi_po_exporter.py (+2/-2)
lib/lp/translations/utilities/tests/test_xpi_search.py (+2/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/ttb-from-disk
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+322759@code.launchpad.net

Commit message

Allow TranslationImportQueue to import entries from file objects rather than having to read arbitrarily-large files into memory.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/doc/poexport-language-pack.txt'
--- lib/lp/translations/doc/poexport-language-pack.txt 2016-02-05 16:51:12 +0000
+++ lib/lp/translations/doc/poexport-language-pack.txt 2017-04-24 14:03:06 +0000
@@ -153,11 +153,11 @@
153153
154Attach the en-US.xpi (the template) file.154Attach the en-US.xpi (the template) file.
155155
156 >>> en_US_xpi = get_en_US_xpi_file_to_import('en-US')156 >>> en_US_xpi = get_en_US_xpi_file_to_import('en-US')
157 >>> translation_import_queue = getUtility(ITranslationImportQueue)157 >>> translation_import_queue = getUtility(ITranslationImportQueue)
158 >>> by_maintainer = True158 >>> by_maintainer = True
159 >>> template_entry = translation_import_queue.addOrUpdateEntry(159 >>> template_entry = translation_import_queue.addOrUpdateEntry(
160 ... firefox_template.path, en_US_xpi.read(), by_maintainer,160 ... firefox_template.path, en_US_xpi, by_maintainer,
161 ... mark, distroseries=series, sourcepackagename=spn,161 ... mark, distroseries=series, sourcepackagename=spn,
162 ... potemplate=firefox_template)162 ... potemplate=firefox_template)
163163
@@ -166,7 +166,7 @@
166 >>> es_xpi = get_en_US_xpi_file_to_import('en-US')166 >>> es_xpi = get_en_US_xpi_file_to_import('en-US')
167 >>> firefox_es_translation = firefox_template.newPOFile('es')167 >>> firefox_es_translation = firefox_template.newPOFile('es')
168 >>> translation_entry = translation_import_queue.addOrUpdateEntry(168 >>> translation_entry = translation_import_queue.addOrUpdateEntry(
169 ... 'es.xpi', es_xpi.read(), by_maintainer,169 ... 'es.xpi', es_xpi, by_maintainer,
170 ... mark, distroseries=series, sourcepackagename=spn,170 ... mark, distroseries=series, sourcepackagename=spn,
171 ... potemplate=firefox_template,171 ... potemplate=firefox_template,
172 ... pofile=firefox_es_translation)172 ... pofile=firefox_es_translation)
173173
=== modified file 'lib/lp/translations/interfaces/translationimporter.py'
--- lib/lp/translations/interfaces/translationimporter.py 2013-01-07 02:40:55 +0000
+++ lib/lp/translations/interfaces/translationimporter.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Interfaces to handle translation files imports."""4"""Interfaces to handle translation files imports."""
@@ -141,7 +141,7 @@
141 """Return the translation file format for the given file extension.141 """Return the translation file format for the given file extension.
142142
143 :param file_extension: File extension including the dot.143 :param file_extension: File extension including the dot.
144 :param file_contents: File contents.144 :param file_contents: File contents (a seekable file object).
145 :return: A `TranslationFileFormat` for the given file extension145 :return: A `TranslationFileFormat` for the given file extension
146 and file contents or None if it's not supported format.146 and file contents or None if it's not supported format.
147 """147 """
@@ -182,10 +182,11 @@
182 def getFormat(file_contents):182 def getFormat(file_contents):
183 """The file format of the import.183 """The file format of the import.
184184
185 :param file_contents: A unicode string with the contents of the file185 :param file_contents: A seekable file object with the contents of
186 being imported. A returned format may sometimes be different186 the file being imported. A returned format may sometimes be
187 from the base format of the `ITranslationFormatImporter`, and187 different from the base format of the
188 that is determined based on the `contents`.188 `ITranslationFormatImporter`, and that is determined based on
189 the `contents`.
189 :return: A `TranslationFileFormat` value.190 :return: A `TranslationFileFormat` value.
190 """191 """
191192
192193
=== modified file 'lib/lp/translations/interfaces/translationimportqueue.py'
--- lib/lp/translations/interfaces/translationimportqueue.py 2014-08-20 06:59:52 +0000
+++ lib/lp/translations/interfaces/translationimportqueue.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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
4from datetime import timedelta4from datetime import timedelta
@@ -313,7 +313,8 @@
313 """Return a new or updated entry of the import queue.313 """Return a new or updated entry of the import queue.
314314
315 :arg path: is the path, with the filename, of the uploaded file.315 :arg path: is the path, with the filename, of the uploaded file.
316 :arg content: is the file content.316 :arg content: is the file content, or a seekable file object open on
317 the file content.
317 :arg by_maintainer: indicates if the file was uploaded by the318 :arg by_maintainer: indicates if the file was uploaded by the
318 maintainer of the project or package.319 maintainer of the project or package.
319 :arg importer: is the person that did the import.320 :arg importer: is the person that did the import.
@@ -336,7 +337,8 @@
336 only_templates=False):337 only_templates=False):
337 """Add all .po or .pot files from the tarball at :content:.338 """Add all .po or .pot files from the tarball at :content:.
338339
339 :arg content: is a tarball stream.340 :arg content: is the tarball content, or a seekable file object open
341 on the tarball.
340 :arg by_maintainer: indicates if the file was uploaded by the342 :arg by_maintainer: indicates if the file was uploaded by the
341 maintainer of the project or package.343 maintainer of the project or package.
342 :arg importer: is the person that did the import.344 :arg importer: is the person that did the import.
343345
=== modified file 'lib/lp/translations/model/translationimportqueue.py'
--- lib/lp/translations/model/translationimportqueue.py 2015-07-08 16:05:11 +0000
+++ lib/lp/translations/model/translationimportqueue.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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__metaclass__ = type4__metaclass__ = type
@@ -8,8 +8,8 @@
8 'TranslationImportQueue',8 'TranslationImportQueue',
9 ]9 ]
1010
11from cStringIO import StringIO
12import datetime11import datetime
12from io import BytesIO
13import logging13import logging
14from operator import attrgetter14from operator import attrgetter
15import os.path15import os.path
@@ -1030,6 +1030,19 @@
1030 return (1030 return (
1031 format, translation_importer.getTranslationFormatImporter(format))1031 format, translation_importer.getTranslationFormatImporter(format))
10321032
1033 def _getFileObjectAndSize(self, file_or_data):
1034 """Get the size of a seekable file object."""
1035 if (isinstance(file_or_data, basestring)):
1036 file_obj = BytesIO(file_or_data)
1037 file_size = len(file_or_data)
1038 else:
1039 file_obj = file_or_data
1040 start = file_obj.tell()
1041 file_obj.seek(0, os.SEEK_END)
1042 file_size = file_obj.tell()
1043 file_obj.seek(start)
1044 return file_obj, file_size
1045
1033 def addOrUpdateEntry(self, path, content, by_maintainer, importer,1046 def addOrUpdateEntry(self, path, content, by_maintainer, importer,
1034 sourcepackagename=None, distroseries=None,1047 sourcepackagename=None, distroseries=None,
1035 productseries=None, potemplate=None, pofile=None,1048 productseries=None, potemplate=None, pofile=None,
@@ -1040,16 +1053,18 @@
1040 "This one has either neither or both.")1053 "This one has either neither or both.")
1041 assert productseries is None or sourcepackagename is None, (1054 assert productseries is None or sourcepackagename is None, (
1042 "Can't upload to a sourcepackagename in a productseries.")1055 "Can't upload to a sourcepackagename in a productseries.")
1043 assert content is not None and content != '', "Upload has no content."1056 assert content is not None, "Upload has no content."
1044 assert path is not None and path != '', "Upload has no path."1057 assert path is not None and path != '', "Upload has no path."
10451058
1059 file, size = self._getFileObjectAndSize(content)
1060 assert size is not None and size != 0, "Upload has empty content."
1061
1046 filename = os.path.basename(path)1062 filename = os.path.basename(path)
1047 format, format_importer = self._getFormatAndImporter(1063 format, format_importer = self._getFormatAndImporter(
1048 filename, content, format=format)1064 filename, file, format=format)
1065 file.seek(0)
10491066
1050 # Upload the file into librarian.1067 # Upload the file into librarian.
1051 size = len(content)
1052 file = StringIO(content)
1053 client = getUtility(ILibrarianClient)1068 client = getUtility(ILibrarianClient)
1054 alias = client.addFile(1069 alias = client.addFile(
1055 name=filename, size=size, file=file,1070 name=filename, size=size, file=file,
@@ -1144,9 +1159,9 @@
1144 num_files = 01159 num_files = 0
1145 conflict_files = []1160 conflict_files = []
11461161
1147 tarball_io = StringIO(content)1162 tarball_io, _ = self._getFileObjectAndSize(content)
1148 try:1163 try:
1149 tarball = tarfile.open('', 'r|*', tarball_io)1164 tarball = tarfile.open('', 'r:*', tarball_io)
1150 except (tarfile.CompressionError, tarfile.ReadError):1165 except (tarfile.CompressionError, tarfile.ReadError):
1151 # If something went wrong with the tarfile, assume it's1166 # If something went wrong with the tarfile, assume it's
1152 # busted and let the user deal with it.1167 # busted and let the user deal with it.
@@ -1158,7 +1173,6 @@
1158 path = self._makePath(name, filename_filter)1173 path = self._makePath(name, filename_filter)
1159 if self._isTranslationFile(path, only_templates):1174 if self._isTranslationFile(path, only_templates):
1160 upload_files[name] = path1175 upload_files[name] = path
1161 tarball.close()
11621176
1163 if approver_factory is None:1177 if approver_factory is None:
1164 approver_factory = TranslationNullApprover1178 approver_factory = TranslationNullApprover
@@ -1167,14 +1181,10 @@
1167 productseries=productseries,1181 productseries=productseries,
1168 distroseries=distroseries, sourcepackagename=sourcepackagename)1182 distroseries=distroseries, sourcepackagename=sourcepackagename)
11691183
1170 # Re-opening because we are using sequential access ("r|*") which is
1171 # so much faster.
1172 tarball_io.seek(0)
1173 tarball = tarfile.open('', 'r|*', tarball_io)
1174 for tarinfo in tarball:1184 for tarinfo in tarball:
1175 if tarinfo.name not in upload_files:1185 if tarinfo.name not in upload_files:
1176 continue1186 continue
1177 file_content = tarball.extractfile(tarinfo).read()1187 file_content = tarball.extractfile(tarinfo)
11781188
1179 path = upload_files[tarinfo.name]1189 path = upload_files[tarinfo.name]
1180 entry = approver.approve(self.addOrUpdateEntry(1190 entry = approver.approve(self.addOrUpdateEntry(
11811191
=== modified file 'lib/lp/translations/model/translationtemplatesbuildbehaviour.py'
--- lib/lp/translations/model/translationtemplatesbuildbehaviour.py 2016-03-31 14:58:46 +0000
+++ lib/lp/translations/model/translationtemplatesbuildbehaviour.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2010-2014 Canonical Ltd. This software is licensed under the1# Copyright 2010-2017 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"""An `IBuildFarmJobBehaviour` for `TranslationTemplatesBuild`.4"""An `IBuildFarmJobBehaviour` for `TranslationTemplatesBuild`.
@@ -110,26 +110,17 @@
110 filename = yield self._readTarball(110 filename = yield self._readTarball(
111 self.build.buildqueue_record, filemap, logger)111 self.build.buildqueue_record, filemap, logger)
112112
113 # XXX 2010-11-12 bug=674575
114 # Please make addOrUpdateEntriesFromTarball() take files on
115 # disk; reading arbitrarily sized files into memory is
116 # dangerous.
117 if filename is None:113 if filename is None:
118 logger.error("Build produced no tarball.")114 logger.error("Build produced no tarball.")
119 else:115 else:
120 tarball_file = open(filename)116 tarball_file = open(filename)
121 try:117 try:
122 tarball = tarball_file.read()118 logger.debug("Uploading translation templates tarball.")
123 if tarball is None:119 self._uploadTarball(
124 logger.error("Build produced empty tarball.")120 self.build.buildqueue_record.specific_build.branch,
125 else:121 tarball_file, logger)
126 logger.debug(122 transaction.commit()
127 "Uploading translation templates tarball.")123 logger.debug("Upload complete.")
128 self._uploadTarball(
129 self.build.buildqueue_record.specific_build.branch,
130 tarball, logger)
131 transaction.commit()
132 logger.debug("Upload complete.")
133 finally:124 finally:
134 tarball_file.close()125 tarball_file.close()
135 os.remove(filename)126 os.remove(filename)
136127
=== modified file 'lib/lp/translations/scripts/upload_translations.py'
--- lib/lp/translations/scripts/upload_translations.py 2015-10-14 16:23:18 +0000
+++ lib/lp/translations/scripts/upload_translations.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the1# Copyright 2011-2017 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__metaclass__ = type4__metaclass__ = type
@@ -55,11 +55,11 @@
55 raise LaunchpadScriptFailure(55 raise LaunchpadScriptFailure(
56 "File not readable: %s" % filename)56 "File not readable: %s" % filename)
57 self.logger.info("Uploading: %s." % filename)57 self.logger.info("Uploading: %s." % filename)
58 content = open(filename).read()58 with open(filename) as content:
59 queue.addOrUpdateEntry(59 queue.addOrUpdateEntry(
60 filename, content, True, rosetta_team,60 filename, content, True, rosetta_team,
61 sourcepackagename=self.sourcepackagename,61 sourcepackagename=self.sourcepackagename,
62 distroseries=self.distroseries)62 distroseries=self.distroseries)
63 self._commit()63 self._commit()
6464
65 self.logger.info("Done.")65 self.logger.info("Done.")
6666
=== modified file 'lib/lp/translations/tests/test_translationimportqueue.py'
--- lib/lp/translations/tests/test_translationimportqueue.py 2013-07-26 12:48:37 +0000
+++ lib/lp/translations/tests/test_translationimportqueue.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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__metaclass__ = type4__metaclass__ = type
@@ -409,7 +409,7 @@
409 self._makeFile('po'),409 self._makeFile('po'),
410 self._makeFile('xpi'),410 self._makeFile('xpi'),
411 ))411 ))
412 tarfile_content = LaunchpadWriteTarFile.files_to_string(files)412 tarfile_content = LaunchpadWriteTarFile.files_to_stream(files)
413 self.import_queue.addOrUpdateEntriesFromTarball(413 self.import_queue.addOrUpdateEntriesFromTarball(
414 tarfile_content, True, self.importer,414 tarfile_content, True, self.importer,
415 productseries=self.productseries)415 productseries=self.productseries)
@@ -420,7 +420,7 @@
420 files = dict((420 files = dict((
421 self._makeFile(),421 self._makeFile(),
422 ))422 ))
423 tarfile_content = LaunchpadWriteTarFile.files_to_string(files)423 tarfile_content = LaunchpadWriteTarFile.files_to_stream(files)
424 self.import_queue.addOrUpdateEntriesFromTarball(424 self.import_queue.addOrUpdateEntriesFromTarball(
425 tarfile_content, True, self.importer,425 tarfile_content, True, self.importer,
426 productseries=self.productseries)426 productseries=self.productseries)
@@ -431,7 +431,7 @@
431 files = dict((431 files = dict((
432 self._makeFile('pot', 'directory'),432 self._makeFile('pot', 'directory'),
433 ))433 ))
434 tarfile_content = LaunchpadWriteTarFile.files_to_string(files)434 tarfile_content = LaunchpadWriteTarFile.files_to_stream(files)
435 self.import_queue.addOrUpdateEntriesFromTarball(435 self.import_queue.addOrUpdateEntriesFromTarball(
436 tarfile_content, True, self.importer,436 tarfile_content, True, self.importer,
437 productseries=self.productseries)437 productseries=self.productseries)
@@ -441,7 +441,7 @@
441 # Leading slashes are stripped from path names.441 # Leading slashes are stripped from path names.
442 path, content = self._makeFile('pot', '/directory')442 path, content = self._makeFile('pot', '/directory')
443 files = dict(((path, content),))443 files = dict(((path, content),))
444 tarfile_content = LaunchpadWriteTarFile.files_to_string(files)444 tarfile_content = LaunchpadWriteTarFile.files_to_stream(files)
445 self.import_queue.addOrUpdateEntriesFromTarball(445 self.import_queue.addOrUpdateEntriesFromTarball(
446 tarfile_content, True, self.importer,446 tarfile_content, True, self.importer,
447 productseries=self.productseries)447 productseries=self.productseries)
448448
=== modified file 'lib/lp/translations/utilities/kde_po_importer.py'
--- lib/lp/translations/utilities/kde_po_importer.py 2015-07-08 16:05:11 +0000
+++ lib/lp/translations/utilities/kde_po_importer.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Import module for legacy KDE .po files.4"""Import module for legacy KDE .po files.
@@ -41,11 +41,17 @@
41 # and with extremely big PO files, this will be too slow). Thus,41 # and with extremely big PO files, this will be too slow). Thus,
42 # a heuristic verified to be correct on all PO files from42 # a heuristic verified to be correct on all PO files from
43 # Ubuntu language packs.43 # Ubuntu language packs.
44 if ('msgid "_n: ' in file_contents or44 msgid_start = False
45 'msgid ""\n"_n: ' in file_contents or45 for line in file_contents:
46 'msgid "_: ' in file_contents or46 if line == b'msgid ""\n':
47 'msgid ""\n"_: ' in file_contents):47 msgid_start = True
48 return TranslationFileFormat.KDEPO48 elif (line.startswith(b'msgid "_n: ') or
49 (msgid_start and line.startswith(b'"_n: ')) or
50 line.startswith(b'msgid "_: ') or
51 (msgid_start and line.startswith(b'"_: '))):
52 return TranslationFileFormat.KDEPO
53 else:
54 msgid_start = False
49 else:55 else:
50 return TranslationFileFormat.PO56 return TranslationFileFormat.PO
5157
5258
=== modified file 'lib/lp/translations/utilities/tests/helpers.py'
--- lib/lp/translations/utilities/tests/helpers.py 2011-09-18 08:39:01 +0000
+++ lib/lp/translations/utilities/tests/helpers.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Helper module reused in different tests."""4"""Helper module reused in different tests."""
@@ -25,7 +25,8 @@
25 pofile=None, potemplate=None, by_maintainer=True):25 pofile=None, potemplate=None, by_maintainer=True):
26 """Import a `POFile` or `POTemplate` from the given string.26 """Import a `POFile` or `POTemplate` from the given string.
2727
28 :param file_contents: text of "file" to import.28 :param file_contents: text of "file" to import, or a seekable file
29 object containing the text.
29 :param person: party requesting the import.30 :param person: party requesting the import.
30 :param pofile: if uploading a `POFile`, file to import to; None otherwise.31 :param pofile: if uploading a `POFile`, file to import to; None otherwise.
31 :param potemplate: if uploading a `POTemplate`, file to import to; None32 :param potemplate: if uploading a `POTemplate`, file to import to; None
3233
=== modified file 'lib/lp/translations/utilities/tests/test_gettext_po_importer.py'
--- lib/lp/translations/utilities/tests/test_gettext_po_importer.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/utilities/tests/test_gettext_po_importer.py 2017-04-24 14:03:06 +0000
@@ -1,10 +1,11 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Gettext PO importer tests."""4"""Gettext PO importer tests."""
55
6__metaclass__ = type6__metaclass__ = type
77
8from io import BytesIO
8import unittest9import unittest
910
10import transaction11import transaction
@@ -89,7 +90,7 @@
8990
90 def testFormat(self):91 def testFormat(self):
91 # GettextPOImporter reports that it handles the PO file format.92 # GettextPOImporter reports that it handles the PO file format.
92 format = self.template_importer.getFormat(test_template)93 format = self.template_importer.getFormat(BytesIO(test_template))
93 self.failUnless(94 self.failUnless(
94 format == TranslationFileFormat.PO,95 format == TranslationFileFormat.PO,
95 'GettextPOImporter format expected PO but got %s' % format.name)96 'GettextPOImporter format expected PO but got %s' % format.name)
9697
=== modified file 'lib/lp/translations/utilities/tests/test_kde_po_importer.py'
--- lib/lp/translations/utilities/tests/test_kde_po_importer.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/utilities/tests/test_kde_po_importer.py 2017-04-24 14:03:06 +0000
@@ -1,10 +1,11 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""KDE PO importer tests."""4"""KDE PO importer tests."""
55
6__metaclass__ = type6__metaclass__ = type
77
8from io import BytesIO
8import unittest9import unittest
910
10import transaction11import transaction
@@ -114,7 +115,7 @@
114115
115 def testFormat(self):116 def testFormat(self):
116 """Check whether KdePOImporter can handle the KDEPO file format."""117 """Check whether KdePOImporter can handle the KDEPO file format."""
117 format = self.template_importer.getFormat(test_kde_template)118 format = self.template_importer.getFormat(BytesIO(test_kde_template))
118 self.failUnless(119 self.failUnless(
119 format == TranslationFileFormat.KDEPO,120 format == TranslationFileFormat.KDEPO,
120 'KdePOImporter format expected KDEPO but got %s' % format.name)121 'KdePOImporter format expected KDEPO but got %s' % format.name)
121122
=== modified file 'lib/lp/translations/utilities/tests/test_mozilla_xpi_importer.py'
--- lib/lp/translations/utilities/tests/test_mozilla_xpi_importer.py 2011-12-28 17:03:06 +0000
+++ lib/lp/translations/utilities/tests/test_mozilla_xpi_importer.py 2017-04-24 14:03:06 +0000
@@ -1,10 +1,11 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Mozilla XPI importer tests."""4"""Mozilla XPI importer tests."""
55
6__metaclass__ = type6__metaclass__ = type
77
8from io import BytesIO
8import unittest9import unittest
910
10from zope.interface.verify import verifyObject11from zope.interface.verify import verifyObject
@@ -34,7 +35,7 @@
3435
35 def testFormat(self):36 def testFormat(self):
36 """Check that MozillaXpiImporter handles the XPI file format."""37 """Check that MozillaXpiImporter handles the XPI file format."""
37 format = self.importer.getFormat(u'')38 format = self.importer.getFormat(BytesIO(b''))
38 self.failUnless(39 self.failUnless(
39 format == TranslationFileFormat.XPI,40 format == TranslationFileFormat.XPI,
40 'MozillaXpiImporter format expected XPI but got %s' % format.name)41 'MozillaXpiImporter format expected XPI but got %s' % format.name)
4142
=== modified file 'lib/lp/translations/utilities/tests/test_translation_importer.py'
--- lib/lp/translations/utilities/tests/test_translation_importer.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/utilities/tests/test_translation_importer.py 2017-04-24 14:03:06 +0000
@@ -1,10 +1,12 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Translation Importer tests."""4"""Translation Importer tests."""
55
6__metaclass__ = type6__metaclass__ = type
77
8from io import BytesIO
9
8import transaction10import transaction
911
10from lp.services.log.logger import DevNullLogger12from lp.services.log.logger import DevNullLogger
@@ -84,17 +86,17 @@
84 self.assertEqual(86 self.assertEqual(
85 TranslationFileFormat.PO,87 TranslationFileFormat.PO,
86 importer.getTranslationFileFormat(88 importer.getTranslationFileFormat(
87 ".po", u'msgid "message"\nmsgstr ""'))89 ".po", BytesIO(b'msgid "message"\nmsgstr ""')))
8890
89 # And PO file with KDE-style messages is recognised as KDEPO file.91 # And PO file with KDE-style messages is recognised as KDEPO file.
90 self.assertEqual(92 self.assertEqual(
91 TranslationFileFormat.KDEPO,93 TranslationFileFormat.KDEPO,
92 importer.getTranslationFileFormat(94 importer.getTranslationFileFormat(
93 ".po", u'msgid "_: kde context\nmessage"\nmsgstr ""'))95 ".po", BytesIO(b'msgid "_: kde context\nmessage"\nmsgstr ""')))
9496
95 self.assertEqual(97 self.assertEqual(
96 TranslationFileFormat.XPI,98 TranslationFileFormat.XPI,
97 importer.getTranslationFileFormat(".xpi", u""))99 importer.getTranslationFileFormat(".xpi", BytesIO(b"")))
98100
99 def testNoConflictingPriorities(self):101 def testNoConflictingPriorities(self):
100 """Check that no two importers for the same file extension have102 """Check that no two importers for the same file extension have
101103
=== modified file 'lib/lp/translations/utilities/tests/test_xpi_import.py'
--- lib/lp/translations/utilities/tests/test_xpi_import.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/utilities/tests/test_xpi_import.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2010 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Functional tests for XPI file format"""4"""Functional tests for XPI file format"""
@@ -61,7 +61,7 @@
61 # Get the file to import.61 # Get the file to import.
62 en_US_xpi = get_en_US_xpi_file_to_import(subdir)62 en_US_xpi = get_en_US_xpi_file_to_import(subdir)
63 return import_pofile_or_potemplate(63 return import_pofile_or_potemplate(
64 file_contents=en_US_xpi.read(),64 file_contents=en_US_xpi,
65 person=self.importer,65 person=self.importer,
66 potemplate=self.firefox_template)66 potemplate=self.firefox_template)
6767
@@ -74,7 +74,7 @@
74 # just use the same template file like a translation one.74 # just use the same template file like a translation one.
75 es_xpi = get_en_US_xpi_file_to_import(subdir)75 es_xpi = get_en_US_xpi_file_to_import(subdir)
76 return import_pofile_or_potemplate(76 return import_pofile_or_potemplate(
77 file_contents=es_xpi.read(),77 file_contents=es_xpi,
78 person=self.importer,78 person=self.importer,
79 pofile=self.spanish_firefox,79 pofile=self.spanish_firefox,
80 by_maintainer=True)80 by_maintainer=True)
8181
=== modified file 'lib/lp/translations/utilities/tests/test_xpi_po_exporter.py'
--- lib/lp/translations/utilities/tests/test_xpi_po_exporter.py 2012-03-27 13:41:38 +0000
+++ lib/lp/translations/utilities/tests/test_xpi_po_exporter.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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__metaclass__ = type4__metaclass__ = type
@@ -82,7 +82,7 @@
82 translation_import_queue = getUtility(ITranslationImportQueue)82 translation_import_queue = getUtility(ITranslationImportQueue)
83 by_maintainer = True83 by_maintainer = True
84 entry = translation_import_queue.addOrUpdateEntry(84 entry = translation_import_queue.addOrUpdateEntry(
85 self.firefox_template.path, en_US_xpi.read(), by_maintainer,85 self.firefox_template.path, en_US_xpi, by_maintainer,
86 self.importer, productseries=self.firefox_template.productseries,86 self.importer, productseries=self.firefox_template.productseries,
87 potemplate=self.firefox_template)87 potemplate=self.firefox_template)
8888
8989
=== modified file 'lib/lp/translations/utilities/tests/test_xpi_search.py'
--- lib/lp/translations/utilities/tests/test_xpi_search.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/utilities/tests/test_xpi_search.py 2017-04-24 14:03:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2017 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"""Functional tests for searching through XPI POTemplates"""4"""Functional tests for searching through XPI POTemplates"""
@@ -51,7 +51,7 @@
51 # Get the file to import.51 # Get the file to import.
52 en_US_xpi = get_en_US_xpi_file_to_import(subdir)52 en_US_xpi = get_en_US_xpi_file_to_import(subdir)
53 return import_pofile_or_potemplate(53 return import_pofile_or_potemplate(
54 file_contents=en_US_xpi.read(),54 file_contents=en_US_xpi,
55 person=self.importer,55 person=self.importer,
56 potemplate=self.firefox_template)56 potemplate=self.firefox_template)
5757