[damned-lies] Fix and test POT-in-respository domain method



commit 4dd36d59ec6f9f6d937ad5a786a55ff038eb7f38
Author: Claude Paroz <claude 2xlibre net>
Date:   Sun Jun 24 22:22:24 2018 +0200

    Fix and test POT-in-respository domain method

 stats/models.py                                  | 49 +++++++++++++-----------
 stats/tests/git/testmodule/inrepo/testmodule.pot | 22 +++++++++++
 stats/tests/tests.py                             |  9 +++++
 3 files changed, 58 insertions(+), 22 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index dd1b2fb4..f215af47 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -827,7 +827,6 @@ class Domain(models.Model):
                 # Standard gnome-doc-utils pot generation
                 potfile, errs = utils.generate_doc_pot_file(current_branch, self)
                 errors.extend(errs)
-                status = utils.STATUS_OK if not errors else 1
                 pot_method = None
         else:
             pot_method = self.pot_method
@@ -835,7 +834,6 @@ class Domain(models.Model):
         if self.module.name == 'damned-lies':
             # Special case for d-l, pot file should be generated from running instance dir
             call_command('update-trans', 'en')
-            status, output, errs = utils.STATUS_OK, '', ''
 
         elif pot_method == 'url':
             # Get POT from URL and save file locally
@@ -846,7 +844,6 @@ class Domain(models.Model):
                 return "", (("error", ugettext_noop("Error retrieving pot file from URL.")),)
             with potfile.open('wb') as f:
                 f.write(handle.read())
-            status = utils.STATUS_OK
 
         elif pot_method == 'gettext':
             pot_command, env = self.get_xgettext_command(current_branch)
@@ -860,6 +857,9 @@ class Domain(models.Model):
         elif pot_method == 'shell':
             pot_command = self.pot_params
 
+        elif pot_method == 'in_repo':
+            pass  # Nothing to do, pot exists
+
         elif pot_method == 'subtitles':
             from translate.convert import sub2po
             srt_files = [
@@ -869,29 +869,34 @@ class Domain(models.Model):
                 return "", (("error", ugettext_noop("No subtitle files found.")),)
             with srt_files[0].open(mode='r') as po_fh, potfile.open(mode='wb') as pot_fh:
                 sub2po.convertsub(po_fh, pot_fh)
-            status = utils.STATUS_OK
 
         if pot_command:
             status, output, errs = run_shell_command(pot_command, env=env, cwd=vcs_path)
+            if status != utils.STATUS_OK:
+                return "", (
+                    ("error",
+                     ugettext_noop("Error regenerating POT file for 
%(file)s:\n<pre>%(cmd)s\n%(output)s</pre>") % {
+                        'file': self.potbase(),
+                        'cmd': ' '.join(pot_command) if isinstance(pot_command, list) else pot_command,
+                        'output': force_text(errs)
+                    }),
+                )
+            if not potfile.exists() and output:
+                # Try to get POT file from command output, with path relative to checkout root
+                m = re.search('([\w/-]*\.pot)', output)
+                if m:
+                    potfile = current_branch.co_path / m.group(0)
+                else:
+                    # Try to find .pot file in /po dir
+                    for file_ in vcs_path.iterdir():
+                        if file_.match('*.pot'):
+                            potfile = file_
+                            break
 
-        if not potfile.exists():
-            # Try to get POT file from command output, with path relative to checkout root
-            m = re.search('([\w/-]*\.pot)', output)
-            if m:
-                potfile = current_branch.co_path / m.group(0)
-            else:
-                # Try to find .pot file in /po dir
-                for file_ in vcs_path.iterdir():
-                    if file_.match('*.pot'):
-                        potfile = file_
-                        break
-
-        if status != utils.STATUS_OK or not potfile.exists():
-            return "", (("error", ugettext_noop("Error regenerating POT file for 
%(file)s:\n<pre>%(cmd)s\n%(output)s</pre>")
-                                 % {'file': self.potbase(),
-                                    'cmd': ' '.join(pot_command) if isinstance(pot_command, list) else 
pot_command,
-                                    'output': force_text(errs)}),
-                       )
+        if errors:
+            return "", errors
+        elif not potfile.exists():
+            return "", (("error", ugettext_noop("Unable to generate POT file")),)
         else:
             return potfile, ()
 
diff --git a/stats/tests/git/testmodule/inrepo/testmodule.pot 
b/stats/tests/git/testmodule/inrepo/testmodule.pot
new file mode 100644
index 00000000..c9ad8e83
--- /dev/null
+++ b/stats/tests/git/testmodule/inrepo/testmodule.pot
@@ -0,0 +1,22 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Matthias Klumpp
+# This file is distributed under the same license as the appstream package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid   ""
+msgstr  "Project-Id-Version: appstream\n"
+        "Report-Msgid-Bugs-To: appstream lists freedesktop org\n"
+        "POT-Creation-Date: 2018-06-10 15:36+0200\n"
+        "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+        "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+        "Language-Team: LANGUAGE <LL li org>\n"
+        "Language: \n"
+        "MIME-Version: 1.0\n"
+        "Content-Type: text/plain; charset=UTF-8\n"
+        "Content-Transfer-Encoding: 8bit\n"
+
+#: tools/appstream-cli.c:146
+#, c-format
+msgid   "'%s' command"
+msgstr  ""
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 3c17f538..954d4d20 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -512,6 +512,15 @@ class DomainTests(TestCase):
             [('es', Path('%s/git/testmodule/subtitles/po/es.po' % settings.SCRATCHDIR))]
         )
 
+    def test_repository_pot(self):
+        dom = Domain.objects.create(
+            module=self.mod, name='po', dtype='ui', directory='inrepo',
+            pot_method='in_repo',
+        )
+        potfile, errs = dom.generate_pot_file(self.branch)
+        self.assertEqual(errs, ())
+        self.assertTrue(potfile.exists())
+
 
 class StatisticsTests(TestCase):
     fixtures = ['sample_data.json']


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