Rev 6285: Change option scheme so users mainly have to deal with po_merge.po_dirs only. in file:///home/vila/src/bzr/bugs/884270-merge-po/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Nov 28 16:31:24 UTC 2011


At file:///home/vila/src/bzr/bugs/884270-merge-po/

------------------------------------------------------------
revno: 6285
revision-id: v.ladeuil+lp at free.fr-20111128163124-u6ji7qtvcd8lsh80
parent: v.ladeuil+lp at free.fr-20111128151659-aafu1y91s05aippx
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 884270-merge-po
timestamp: Mon 2011-11-28 17:31:24 +0100
message:
  Change option scheme so users mainly have to deal with po_merge.po_dirs only.
-------------- next part --------------
=== modified file 'bzrlib/plugins/po_merge/po_merge.py'
--- a/bzrlib/plugins/po_merge/po_merge.py	2011-11-28 15:16:59 +0000
+++ b/bzrlib/plugins/po_merge/po_merge.py	2011-11-28 16:31:24 +0000
@@ -58,15 +58,18 @@
 
 
 config.option_registry.register(config.Option(
-        'po_merge.po_files', default=[],
-        from_unicode=config.list_from_store,
-        help='List of globs the po_merge hook applies to.'))
-
-
-config.option_registry.register(config.Option(
-        'po_merge.pot_file', default=[],
-        from_unicode=config.list_from_store,
-        help='List of ``.pot`` filenames related to ``po_merge.po_files``.'))
+        'po_merge.po_dirs', default='po,',
+        from_unicode=config.list_from_store,
+        help='List of dirs containing .po files that the hook applies to.'))
+
+
+config.option_registry.register(config.Option(
+        'po_merge.po_glob', default='*.po',
+        help='Glob matching all ``.po`` files in one of ``po_merge.po_dirs``.'))
+
+config.option_registry.register(config.Option(
+        'po_merge.pot_glob', default='*.pot',
+        help='Glob matching the ``.pot`` file in one of ``po_merge.po_dirs``.'))
 
 
 class PoMerger(merge.PerFileMerger):
@@ -80,49 +83,56 @@
         # FIXME: We use the branch config as there is no tree config
         # -- vila 2011-11-23
         self.conf = merger.this_branch.get_config_stack()
+        # Which dirs are targeted by the hook 
+        self.po_dirs = self.conf.get('po_merge.po_dirs')
         # Which files are targeted by the hook 
-        self.po_files = self.conf.get('po_merge.po_files')
+        self.po_glob = self.conf.get('po_merge.po_glob')
         # Which .pot file should be used
-        self.pot_file = self.conf.get('po_merge.pot_file')
+        self.pot_glob = self.conf.get('po_merge.pot_glob')
         self.command = self.conf.get('po_merge.command', expand=False)
         # file_matches() will set the following for merge_text()
         self.selected_po_file = None
         self.selected_pot_file = None
+        trace.mutter('PoMerger created')
 
     def file_matches(self, params):
         """Return True if merge_matching should be called on this file."""
-        if not self.po_files or not self.pot_file or not self.command:
+        if not self.po_dirs or not self.command:
             # Return early if there is no options defined
             return False
-        match = False
+        po_dir = None
         po_path = self.get_filepath(params, self.merger.this_tree)
-        # Does the merged file match one of the globs
-        for idx, glob in enumerate(self.po_files):
+        for po_dir in self.po_dirs:
+            glob = osutils.pathjoin(po_dir, self.po_glob)
             if fnmatch.fnmatch(po_path, glob):
-                match = True
+                trace.mutter('po %s matches: %s' % (po_path, glob))
                 break
-        if not match:
+        else:
+            trace.mutter('PoMerger did not match for %s and %s'
+                         % (self.po_dirs, self.po_glob))
             return False
         # Do we have the corresponding .pot file
-        try:
-            pot_path = self.pot_file[idx]
-        except KeyError:
-            trace.note('po_merge.po_files and po_merge.pot_file mismatch'
-                       ' for index %d' %d)
+        for inv_entry in self.merger.this_tree.list_files(from_dir=po_dir,
+                                                          recursive=False):
+            pot_name = inv_entry[0]
+            if fnmatch.fnmatch(pot_name, self.pot_glob):
+                self.selected_pot_file = osutils.pathjoin(po_dir, pot_name)
+                self.selected_po_file = po_path
+                # FIXME: I can't find an easy way to know if the .pot file has
+                # conflicts *during* the merge itself. So either the actual
+                # content on disk is fine and msgmerge will work OR it's not
+                # and it will fail. Conversely, either the result is ok for the
+                # user and he's happy OR the user needs to resolve the
+                # conflicts in the .pot file and use remerge.
+                # -- vila 2011-11-24
+                trace.mutter('will msgmerge with %s and %s'
+                             % (self.selected_po_file, self.selected_pot_file))
+                return True
+        else:
             return False
-        if self.merger.this_tree.has_filename(pot_path):
-            self.selected_pot_file = pot_path
-            self.selected_po_file = po_path
-            # FIXME: I can't find an easy way to know if the .pot file has
-            # conflicts *during* the merge itself. So either the actual content
-            # on disk is fine and msgmerge will work OR it's not and it will
-            # fail. Conversely, either the result is ok for the user and he's
-            # happy OR the user needs to resolve the conflicts in the .pot file
-            # and use remerge. -- vila 2011-11-24
-            return True
-        return False
 
     def _invoke(self, command):
+        trace.mutter('Will msgmerge: %s' % (command,))
         proc = subprocess.Popen(cmdline.split(command),
                                 # FIXME: cwd= ? -- vila 2011-11-24
                                 stdout=subprocess.PIPE,

=== modified file 'bzrlib/plugins/po_merge/tests/__init__.py'
--- a/bzrlib/plugins/po_merge/tests/__init__.py	2011-11-24 10:47:43 +0000
+++ b/bzrlib/plugins/po_merge/tests/__init__.py	2011-11-28 16:31:24 +0000
@@ -16,7 +16,6 @@
 
 def load_tests(basic_tests, module, loader):
     testmod_names = [
-        'test_blackbox_po_merge',
         'test_po_merge',
         ]
     basic_tests.addTest(loader.loadTestsFromModuleNames(

=== renamed file 'bzrlib/plugins/po_merge/tests/test_blackbox_po_merge.py' => 'bzrlib/plugins/po_merge/tests/test_po_merge.py'
--- a/bzrlib/plugins/po_merge/tests/test_blackbox_po_merge.py	2011-11-28 15:16:59 +0000
+++ b/bzrlib/plugins/po_merge/tests/test_po_merge.py	2011-11-28 16:31:24 +0000
@@ -48,12 +48,10 @@
 $ bzr branch adduser -rrevid:this work
 2>Branched 2 revisions.
 $ cd work
-$ bzr config po_merge.pot_file=adduser.pot
-$ bzr config po_merge.po_files=fr.po
 $ bzr merge ../adduser -rrevid:other
-2> M  adduser.pot
-2> M  fr.po
-2>Text conflict in adduser.pot
+2> M  po/adduser.pot
+2> M  po/fr.po
+2>Text conflict in po/adduser.pot
 2>1 conflicts encountered.
 """)
 
@@ -63,29 +61,30 @@
 $ bzr branch adduser -rrevid:this work
 2>Branched 2 revisions.
 $ cd work
+$ bzr config po_merge.po_dirs=dont-exist
 $ bzr merge ../adduser -rrevid:other
-2> M  adduser.pot
-2> M  fr.po
-2>Text conflict in adduser.pot
-2>Text conflict in fr.po
+2> M  po/adduser.pot
+2> M  po/fr.po
+2>Text conflict in po/adduser.pot
+2>Text conflict in po/fr.po
 2>2 conflicts encountered.
 """)
         # Fix the conflicts in the .pot file
-        with open('adduser.pot', 'w') as f:
+        with open('po/adduser.pot', 'w') as f:
             f.write(_Adduser['resolved_pot'])
         # Tell bzr the conflict is resolved
         self.run_script("""\
-$ bzr resolve adduser.pot
+$ bzr resolve po/adduser.pot
 2>1 conflict resolved, 1 remaining
 """)
         # set config options to activate the hook
         self.run_script("""\
-$ bzr config po_merge.pot_file=adduser.pot
-$ bzr config po_merge.po_files=fr.po
+$ bzr config po_merge.po_dirs=po,
 """)
+        self.debug()
         # Use remerge to trigger the hook, 
         self.run_script("""\
-$ bzr remerge *.po
+$ bzr remerge po/*.po
 2>All changes applied successfully.
 """)
         # There should be no conflicts anymore
@@ -105,9 +104,10 @@
     builder.build_snapshot('base', None,
                            [('add', ('', 'root-id', 'directory', '')),
                             # Create empty files
-                            ('add', ('adduser.pot', 'pot-id', 'file',
+                            ('add', ('po', 'dir-id', 'directory', None),),
+                            ('add', ('po/adduser.pot', 'pot-id', 'file',
                                      _Adduser['base_pot'])),
-                            ('add', ('fr.po', 'po-id', 'file',
+                            ('add', ('po/fr.po', 'po-id', 'file',
                                      _Adduser['base_po'])),
             ])
     # The 'other' branch
@@ -140,9 +140,9 @@
 $ bzr branch adduser -rrevid:%(revid)s %(branch_name)s
 """ % env, null_output_matches_anything=True)
         self.assertFileEqual(_Adduser['%(revid)s_pot' % env],
-                             '%(branch_name)s/adduser.pot' % env)
+                             '%(branch_name)s/po/adduser.pot' % env)
         self.assertFileEqual(_Adduser['%(revid)s_po' % env],
-                             '%(branch_name)s/fr.po' % env )
+                             '%(branch_name)s/po/fr.po' % env )
 
     def test_base(self):
         self.assertAdduserBranchContent('base')

=== removed file 'bzrlib/plugins/po_merge/tests/test_po_merge.py'
--- a/bzrlib/plugins/po_merge/tests/test_po_merge.py	2011-11-24 10:47:43 +0000
+++ b/bzrlib/plugins/po_merge/tests/test_po_merge.py	1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
-# Copyright (C) 2011 by Canonical Ltd
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-import os
-
-from bzrlib import (
-    tests,
-    )
-
-class TestPoMerger(tests.TestCaseWithTransport):
-
-    def test_bad_config_options(self):
-        # pot_file and po_files lengths should match
-        pass
-
-    def test_match_po_files(self):
-        # hook will fire if the merged file matches one of the globs
-        pass
-
-    def test_no_pot_file(self):
-        # hook won't fire if there is no pot file
-        # - not present
-        # - doesn't match
-        pass
-
-    def test_no_pot_file(self):
-        # hook won't fire if there are conflicts in the pot file
-        pass
-



More information about the bazaar-commits mailing list