← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:restore-pottery-detect-intltool into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:restore-pottery-detect-intltool into launchpad:master.

Commit message:
Restore pottery-generate-intltool.py script

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/390901

This reverts part of commit 36352ca7744a6473ed3a526824c45bf79ed27454.  Although nothing in Launchpad itself uses this script, it's useful for testing (see https://dev.launchpad.net/Translations/GenerateTemplatesOnTestServers).
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:restore-pottery-detect-intltool into launchpad:master.
diff --git a/lib/lp/translations/pottery/tests/test_detect_intltool.py b/lib/lp/translations/pottery/tests/test_detect_intltool.py
index cc0d5d7..21dce33 100644
--- a/lib/lp/translations/pottery/tests/test_detect_intltool.py
+++ b/lib/lp/translations/pottery/tests/test_detect_intltool.py
@@ -6,9 +6,11 @@ __metaclass__ = type
 import errno
 import os
 import tarfile
+from textwrap import dedent
 
 from breezy.controldir import ControlDir
 
+from lp.services.scripts.tests import run_script
 from lp.testing import TestCase
 from lp.translations.pottery.detect_intltool import is_intltool_structure
 
@@ -52,6 +54,18 @@ class SetupTestPackageMixin:
             with open(path, 'w') as the_file:
                 the_file.write(content)
 
+    def test_pottery_generate_intltool_script(self):
+        # Let the script run to see it works fine.
+        self.prepare_package("intltool_POTFILES_in_2")
+
+        return_code, stdout, stderr = run_script(
+            'scripts/rosetta/pottery-generate-intltool.py', [])
+
+        self.assertEqual(dedent("""\
+            module1/po/messages.pot
+            po/messages.pot
+            """), stdout)
+
 
 class TestDetectIntltoolInBzrTree(TestCase, SetupTestPackageMixin):
 
diff --git a/scripts/rosetta/pottery-generate-intltool.py b/scripts/rosetta/pottery-generate-intltool.py
new file mode 100755
index 0000000..4557676
--- /dev/null
+++ b/scripts/rosetta/pottery-generate-intltool.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python2 -S
+#
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Print a list of directories that contain a valid intltool structure."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+import _pythonpath
+
+import os.path
+
+from lpbuildd.pottery.intltool import generate_pots
+from lpbuildd.tests.fakeslave import UncontainedBackend as _UncontainedBackend
+
+from lp.services.scripts.base import LaunchpadScript
+
+
+class UncontainedBackend(_UncontainedBackend):
+    """Like UncontainedBackend, except avoid executing "test".
+
+    Otherwise we can end up with confusion between the Unix "test" utility
+    and Launchpad's bin/test.
+    """
+
+    def path_exists(self, path):
+        """See `Backend`."""
+        return os.path.exists(path)
+
+    def isdir(self, path):
+        """See `Backend`."""
+        return os.path.isdir(path)
+
+    def islink(self, path):
+        """See `Backend`."""
+        return os.path.islink(path)
+
+
+class PotteryGenerateIntltool(LaunchpadScript):
+    """Print a list of directories that contain a valid intltool structure."""
+
+    def add_my_options(self):
+        """See `LaunchpadScript`."""
+        self.parser.usage = "%prog [options] [PATH]"
+
+    def main(self):
+        """See `LaunchpadScript`."""
+        path = self.args[0] if self.args else "."
+        backend = UncontainedBackend("dummy")
+        print("\n".join(generate_pots(backend, path)))
+
+
+if __name__ == "__main__":
+    script = PotteryGenerateIntltool(name="pottery-generate-intltool")
+    script.run()