def testHiddenFilesRecognition(self):
     # Hidden files and directories (leading dot) are recognized.
     importer = TranslationImporter()
     hidden_files = [
         ".hidden.pot",
         ".hidden/foo.pot",
         "po/.hidden/foo.pot",
         "po/.hidden.pot",
         "bla/.hidden/foo/bar.pot",
         ]
     visible_files = [
         "not.hidden.pot",
         "not.hidden/foo.pot",
         "po/not.hidden/foo.pot",
         "po/not.hidden.pot",
         "bla/not.hidden/foo/bar.pot",
         ]
     for path in hidden_files:
         self.assertTrue(
             importer.isHidden(path),
             'Failed to recognized "%s" as a hidden file.' % path)
     for path in visible_files:
         self.assertFalse(
             importer.isHidden(path),
             'Failed to recognized "%s" as a visible file.' % path)
Exemplo n.º 2
0
 def testHiddenFilesRecognition(self):
     # Hidden files and directories (leading dot) are recognized.
     importer = TranslationImporter()
     hidden_files = [
         ".hidden.pot",
         ".hidden/foo.pot",
         "po/.hidden/foo.pot",
         "po/.hidden.pot",
         "bla/.hidden/foo/bar.pot",
     ]
     visible_files = [
         "not.hidden.pot",
         "not.hidden/foo.pot",
         "po/not.hidden/foo.pot",
         "po/not.hidden.pot",
         "bla/not.hidden/foo/bar.pot",
     ]
     for path in hidden_files:
         self.assertTrue(
             importer.isHidden(path),
             'Failed to recognized "%s" as a hidden file.' % path)
     for path in visible_files:
         self.assertFalse(
             importer.isHidden(path),
             'Failed to recognized "%s" as a visible file.' % path)
Exemplo n.º 3
0
    def _init_translation_file_lists(self):
        """Initialize the member variables that hold the information about
        the relevant files.

        The information is collected from the branch tree and stored in the
        following member variables:
        * file_names is a dictionary of two lists ('pot', 'po') of file names
          that are POT or PO files respectively. This includes all files,
          changed or unchanged.
        * changed_files is a dictionary of two lists ('pot', 'po') of tuples
          of (file_name, file_content) of all changed files that are POT or
          PO files respectively.
        """

        bzrbranch = self.branch.getBzrBranch()
        from_tree = bzrbranch.repository.revision_tree(
            self.from_revision_id)
        to_tree = bzrbranch.repository.revision_tree(
            self.branch.last_scanned_id)

        importer = TranslationImporter()

        to_tree.lock_read()
        try:
            for dir, files in to_tree.walkdirs():
                for afile in files:
                    file_path, file_name, file_type = afile[:3]
                    if file_type != 'file':
                        continue
                    if importer.isHidden(file_path):
                        continue
                    if importer.isTemplateName(file_name):
                        append_to = self.template_file_names
                    elif importer.isTranslationName(file_name):
                        append_to = self.translation_file_names
                    else:
                        continue
                    append_to.append(file_path)
            from_tree.lock_read()
            try:
                for file_names, changed_files in self._iter_all_lists():
                    for changed_file in to_tree.iter_changes(
                            from_tree, specific_files=file_names):
                        (from_kind, to_kind) = changed_file[6]
                        if to_kind != 'file':
                            continue
                        file_id, (from_path, to_path) = changed_file[:2]
                        changed_files.append((
                            to_path, to_tree.get_file_text(file_id)))
            finally:
                from_tree.unlock()
        finally:
            to_tree.unlock()
Exemplo n.º 4
0
    def _init_translation_file_lists(self):
        """Initialize the member variables that hold the information about
        the relevant files.

        The information is collected from the branch tree and stored in the
        following member variables:
        * file_names is a dictionary of two lists ('pot', 'po') of file names
          that are POT or PO files respectively. This includes all files,
          changed or unchanged.
        * changed_files is a dictionary of two lists ('pot', 'po') of tuples
          of (file_name, file_content) of all changed files that are POT or
          PO files respectively.
        """

        bzrbranch = self.branch.getBzrBranch()
        from_tree = bzrbranch.repository.revision_tree(
            self.from_revision_id)
        to_tree = bzrbranch.repository.revision_tree(
            self.branch.last_scanned_id)

        importer = TranslationImporter()

        to_tree.lock_read()
        try:
            for dir, files in to_tree.walkdirs():
                for afile in files:
                    file_path, file_name, file_type = afile[:3]
                    if file_type != 'file':
                        continue
                    if importer.isHidden(file_path):
                        continue
                    if importer.isTemplateName(file_name):
                        append_to = self.template_file_names
                    elif importer.isTranslationName(file_name):
                        append_to = self.translation_file_names
                    else:
                        continue
                    append_to.append(file_path)
            from_tree.lock_read()
            try:
                for file_names, changed_files in self._iter_all_lists():
                    for changed_file in to_tree.iter_changes(
                            from_tree, specific_files=file_names):
                        (from_kind, to_kind) = changed_file[6]
                        if to_kind != 'file':
                            continue
                        file_id, (from_path, to_path) = changed_file[:2]
                        changed_files.append((
                            to_path, to_tree.get_file_text(file_id)))
            finally:
                from_tree.unlock()
        finally:
            to_tree.unlock()
Exemplo n.º 5
0
 def testGetImporterByFileFormat(self):
     """Check whether we get the right importer from the file format."""
     importer = TranslationImporter()
     self.assertIsNot(
         None,
         importer.getTranslationFormatImporter(TranslationFileFormat.PO))
     self.assertIsNot(
         None,
         importer.getTranslationFormatImporter(TranslationFileFormat.KDEPO))
     self.assertIsNot(
         None,
         importer.getTranslationFormatImporter(TranslationFileFormat.XPI))
 def testGetImporterByFileFormat(self):
     """Check whether we get the right importer from the file format."""
     importer = TranslationImporter()
     self.assertIsNot(
         None,
         importer.getTranslationFormatImporter(TranslationFileFormat.PO))
     self.assertIsNot(
         None,
         importer.getTranslationFormatImporter(
             TranslationFileFormat.KDEPO))
     self.assertIsNot(
         None,
         importer.getTranslationFormatImporter(TranslationFileFormat.XPI))
Exemplo n.º 7
0
    def __init__(self, files, productseries=None,
                 distroseries=None, sourcepackagename=None):
        """Create the approver and build the approval list by comparing
        the given files as found in the source tree to the database entries.

        Either productseries or distroseries/sourcepackagename must be given
        but not all.

        :param files: A list of paths to the translation files.
        :param productseries: The productseries that this upload is for.
        :param distroseries: The distroseries that this upload is for.
        :param sourcepackagename: The sourcepackagename that this upload
            is for.
        """

        assert (distroseries is None or sourcepackagename is not None), (
                "Please specify distroseries and sourcepackagename together.")

        self._potemplates = {}
        self._n_matched = 0
        self.is_approval_possible = True

        potemplate_names = set()
        product_name = get_product_name(productseries)

        importer = TranslationImporter()
        self._potemplateset = getUtility(IPOTemplateSet).getSubset(
            iscurrent=True, productseries=productseries,
            distroseries=distroseries, sourcepackagename=sourcepackagename)
        for path in files:
            if importer.isTemplateName(path):
                potemplate = self._potemplateset.getPOTemplateByPath(path)
                if potemplate is None:
                    name = make_name_from_path(path, default=product_name)
                    potemplate = self._potemplateset.getPOTemplateByName(name)
                else:
                    name = potemplate.name
                # Template names must occur only once.
                if name in potemplate_names:
                    self.is_approval_possible = False
                else:
                    potemplate_names.add(name)
                if potemplate is not None:
                    self._n_matched += 1
                self._potemplates[path] = potemplate
        # The simplest case of exactly one file and one POTemplate object is
        # always approved.
        if len(self._potemplateset) == len(self._potemplates) == 1:
            self._potemplates[self._potemplates.keys()[0]] = (
                list(self._potemplateset)[0])
            self.is_approval_possible = True
Exemplo n.º 8
0
    def test_unseen_messages_stay_intact(self):
        # If an import does not mention a particular msgid, that msgid
        # keeps its current translation.
        pofile = self.factory.makePOFile()
        template = pofile.potemplate
        potmsgset1 = self.factory.makePOTMsgSet(template, sequence=1)
        potmsgset2 = self.factory.makePOTMsgSet(template, sequence=2)
        existing_translation = self.factory.makeCurrentTranslationMessage(
            pofile=pofile, potmsgset=potmsgset1)

        text = """
            msgid ""
            msgstr ""
            "MIME-Version: 1.0\\n"
            "Content-Type: text/plain; charset=UTF-8\\n"
            "Content-Transfer-Encoding: 8bit\\n"
            "X-Launchpad-Export-Date: 2010-11-24\\n"

            msgid "%s"
            msgstr "A translation."
        """ % potmsgset2.msgid_singular.msgid

        entry = self.factory.makeTranslationImportQueueEntry(
            'foo.po',
            potemplate=template,
            pofile=pofile,
            status=RosettaImportStatus.APPROVED,
            content=text)
        transaction.commit()

        self.assertTrue(existing_translation.is_current_upstream)
        TranslationImporter().importFile(entry)
        self.assertTrue(existing_translation.is_current_upstream)
Exemplo n.º 9
0
 def testNoConflictingPriorities(self):
     """Check that no two importers for the same file extension have
     exactly the same priority."""
     for file_extension in TranslationImporter().supported_file_extensions:
         priorities = []
         for format, importer in importers.iteritems():
             if file_extension in importer.file_extensions:
                 self.assertNotIn(importer.priority, priorities)
                 priorities.append(importer.priority)
    def testGetTranslationFileFormatByFileExtension(self):
        """Checked whether file format precedence works correctly."""
        importer = TranslationImporter()

        # Even if the file extension is the same for both PO and KDEPO
        # file formats, a PO file containing no KDE-style messages is
        # recognized as regular PO file.
        self.assertEqual(
            TranslationFileFormat.PO,
            importer.getTranslationFileFormat(".po",
                                              u'msgid "message"\nmsgstr ""'))

        # And PO file with KDE-style messages is recognised as KDEPO file.
        self.assertEqual(
            TranslationFileFormat.KDEPO,
            importer.getTranslationFileFormat(
                ".po", u'msgid "_: kde context\nmessage"\nmsgstr ""'))

        self.assertEqual(TranslationFileFormat.XPI,
                         importer.getTranslationFileFormat(".xpi", u""))
    def testGetTranslationFileFormatByFileExtension(self):
        """Checked whether file format precedence works correctly."""
        importer = TranslationImporter()

        # Even if the file extension is the same for both PO and KDEPO
        # file formats, a PO file containing no KDE-style messages is
        # recognized as regular PO file.
        self.assertEqual(
            TranslationFileFormat.PO,
            importer.getTranslationFileFormat(
                ".po", u'msgid "message"\nmsgstr ""'))

        # And PO file with KDE-style messages is recognised as KDEPO file.
        self.assertEqual(
            TranslationFileFormat.KDEPO,
            importer.getTranslationFileFormat(
                ".po", u'msgid "_: kde context\nmessage"\nmsgstr ""'))

        self.assertEqual(
            TranslationFileFormat.XPI,
            importer.getTranslationFileFormat(".xpi", u""))
Exemplo n.º 12
0
    def __init__(
        self, filenames,
        productseries=None, distroseries=None, sourcepackagename=None):

        # Productseries and distroseries will be asserted in getSubset but
        # not sourcepackagename.
        assert (distroseries is None and sourcepackagename is None or
                distroseries is not None and sourcepackagename is not None), (
                "Please specify distroseries and sourcepackagename together.")

        importer = TranslationImporter()
        # We only care for templates.
        self.filenames = filter(importer.isTemplateName, filenames)
        self._potemplateset = getUtility(IPOTemplateSet).getSubset(
            productseries=productseries,
            distroseries=distroseries,
            sourcepackagename=sourcepackagename)
        if productseries is not None:
            self.owner = productseries.product.owner
        else:
            self.owner = distroseries.distribution.owner
Exemplo n.º 13
0
 def testTemplateSuffixes(self):
     """Check for changes in filename suffixes that identify templates."""
     self.assertEqual(['.pot', 'en-US.xpi'],
                      TranslationImporter().template_suffixes)
Exemplo n.º 14
0
 def testInterface(self):
     """Check whether the object follows the interface."""
     self.assertThat(TranslationImporter(), Provides(ITranslationImporter))
Exemplo n.º 15
0
 def _assertIsNotTranslation(self, path):
     self.assertFalse(TranslationImporter().isTranslationName(path),
                      'Mistook "%s for a translation file name.' % path)
Exemplo n.º 16
0
 def _assertIsTranslation(self, path):
     self.assertTrue(
         TranslationImporter().isTranslationName(path),
         'Failed to recognize "%s" as a translation file name.' % path)
Exemplo n.º 17
0
 def testFileExtensionsWithImporters(self):
     """Check whether we get the right list of file extensions handled."""
     self.assertEqual(['.po', '.pot', '.xpi'],
                      TranslationImporter().supported_file_extensions)
Exemplo n.º 18
0
 def _assertIsNotTemplate(self, path):
     self.assertFalse(TranslationImporter().isTemplateName(path),
                      'Mistook "%s" for a template name.' % path)