[damned-lies] Support modules naming POTFILES.in as POTFILES



commit ed9683897c35e8df08357f29e6c1e2427dea4632
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Jan 13 15:50:20 2022 +0100

    Support modules naming POTFILES.in as POTFILES
    
    gstreamer is one of them, and Meson supports that.

 stats/models.py                           | 27 +++++++++++++++++----------
 stats/tests/git/testmodule/po/POTFILES.in |  0
 2 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 85f7f010..e917a88f 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -811,7 +811,10 @@ class Domain(models.Model):
                 f.write(handle.read())
 
         elif pot_method == 'gettext':
-            pot_command, env = self.get_xgettext_command(current_branch)
+            try:
+                pot_command, env = self.get_xgettext_command(current_branch)
+            except Exception as err:
+                errors.append(str(err))
 
         elif pot_method == 'intltool':
             pot_command = ['intltool-update', '-g', self.potbase(), '-p']
@@ -872,9 +875,7 @@ class Domain(models.Model):
         return potfile, ()
 
     def get_xgettext_command(self, branch):
-        pot_command = [
-            'xgettext',
-            '--files-from', 'POTFILES.in',
+        xgettext_args = [
             '--directory', str(branch.co_path),
             '--from-code', 'utf-8',
             '--add-comments',
@@ -888,21 +889,27 @@ class Domain(models.Model):
                 [env['GETTEXTDATADIRS']] + [str(branch.co_path / path)
                                             for path in self.extra_its_dirs.split(':')]
             )
-        # Parse and use content from: "XGETTEXT_OPTIONS = --keyword=_ --keyword=N_"
         vcs_path = branch.co_path / self.base_dir
+        if (vcs_path / 'POTFILES.in').exists():
+            xgettext_args = ['--files-from', 'POTFILES.in'] + xgettext_args
+        elif (vcs_path / 'POTFILES').exists():
+            xgettext_args = ['--files-from', 'POTFILES'] + xgettext_args
+        else:
+            raise RuntimeError(f"No POTFILES file found in {self.base_dir}")
+        # Parse and use content from: "XGETTEXT_OPTIONS = --keyword=_ --keyword=N_"
         makefile = utils.MakefileWrapper.find_file(branch, [vcs_path], file_name='Makevars')
         if makefile:
             kwds_vars = makefile.read_variable('XGETTEXT_OPTIONS')
             if kwds_vars:
-                pot_command.extend(kwds_vars.split())
+                xgettext_args.extend(kwds_vars.split())
         else:
             makefile = utils.MakefileWrapper.find_file(branch, [vcs_path], file_name='meson.build')
             if makefile:
                 if makefile.read_variable('gettext.preset') == 'glib' or not makefile.readable:
-                    pot_command.extend(GLIB_PRESET)
+                    xgettext_args.extend(GLIB_PRESET)
                 extra_args = makefile.read_variable('gettext.args')
                 if extra_args:
-                    pot_command.extend([extra_args] if isinstance(extra_args, str) else extra_args)
+                    xgettext_args.extend([extra_args] if isinstance(extra_args, str) else extra_args)
                 datadirs = makefile.read_variable('gettext.data_dirs')
                 if datadirs:
                     env['GETTEXTDATADIRS'] = ':'.join(
@@ -911,8 +918,8 @@ class Domain(models.Model):
                     )
         # Added last as some chars in it may disturb CLI parsing
         if self.module.bugs_base:
-            pot_command.extend(['--msgid-bugs-address', self.module.bugs_base])
-        return pot_command, env
+            xgettext_args.extend(['--msgid-bugs-address', self.module.bugs_base])
+        return ['xgettext'] + xgettext_args, env
 
     def commit_info(self, branch, language):
         """
diff --git a/stats/tests/git/testmodule/po/POTFILES.in b/stats/tests/git/testmodule/po/POTFILES.in
new file mode 100644
index 00000000..e69de29b


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]