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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 69e66adcf4725fdc8f34708c9e10930c4c653597
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:restore-pottery-detect-intltool
Merge into: launchpad:master
Diff against target: 97 lines (+70/-0)
2 files modified
lib/lp/translations/pottery/tests/test_detect_intltool.py (+14/-0)
scripts/rosetta/pottery-generate-intltool.py (+56/-0)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+390901@code.launchpad.net

Commit message

Restore pottery-generate-intltool.py script

Description of the change

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).

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/translations/pottery/tests/test_detect_intltool.py b/lib/lp/translations/pottery/tests/test_detect_intltool.py
2index cc0d5d7..21dce33 100644
3--- a/lib/lp/translations/pottery/tests/test_detect_intltool.py
4+++ b/lib/lp/translations/pottery/tests/test_detect_intltool.py
5@@ -6,9 +6,11 @@ __metaclass__ = type
6 import errno
7 import os
8 import tarfile
9+from textwrap import dedent
10
11 from breezy.controldir import ControlDir
12
13+from lp.services.scripts.tests import run_script
14 from lp.testing import TestCase
15 from lp.translations.pottery.detect_intltool import is_intltool_structure
16
17@@ -52,6 +54,18 @@ class SetupTestPackageMixin:
18 with open(path, 'w') as the_file:
19 the_file.write(content)
20
21+ def test_pottery_generate_intltool_script(self):
22+ # Let the script run to see it works fine.
23+ self.prepare_package("intltool_POTFILES_in_2")
24+
25+ return_code, stdout, stderr = run_script(
26+ 'scripts/rosetta/pottery-generate-intltool.py', [])
27+
28+ self.assertEqual(dedent("""\
29+ module1/po/messages.pot
30+ po/messages.pot
31+ """), stdout)
32+
33
34 class TestDetectIntltoolInBzrTree(TestCase, SetupTestPackageMixin):
35
36diff --git a/scripts/rosetta/pottery-generate-intltool.py b/scripts/rosetta/pottery-generate-intltool.py
37new file mode 100755
38index 0000000..4557676
39--- /dev/null
40+++ b/scripts/rosetta/pottery-generate-intltool.py
41@@ -0,0 +1,56 @@
42+#!/usr/bin/python2 -S
43+#
44+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
45+# GNU Affero General Public License version 3 (see the file LICENSE).
46+
47+"""Print a list of directories that contain a valid intltool structure."""
48+
49+from __future__ import absolute_import, print_function, unicode_literals
50+
51+import _pythonpath
52+
53+import os.path
54+
55+from lpbuildd.pottery.intltool import generate_pots
56+from lpbuildd.tests.fakeslave import UncontainedBackend as _UncontainedBackend
57+
58+from lp.services.scripts.base import LaunchpadScript
59+
60+
61+class UncontainedBackend(_UncontainedBackend):
62+ """Like UncontainedBackend, except avoid executing "test".
63+
64+ Otherwise we can end up with confusion between the Unix "test" utility
65+ and Launchpad's bin/test.
66+ """
67+
68+ def path_exists(self, path):
69+ """See `Backend`."""
70+ return os.path.exists(path)
71+
72+ def isdir(self, path):
73+ """See `Backend`."""
74+ return os.path.isdir(path)
75+
76+ def islink(self, path):
77+ """See `Backend`."""
78+ return os.path.islink(path)
79+
80+
81+class PotteryGenerateIntltool(LaunchpadScript):
82+ """Print a list of directories that contain a valid intltool structure."""
83+
84+ def add_my_options(self):
85+ """See `LaunchpadScript`."""
86+ self.parser.usage = "%prog [options] [PATH]"
87+
88+ def main(self):
89+ """See `LaunchpadScript`."""
90+ path = self.args[0] if self.args else "."
91+ backend = UncontainedBackend("dummy")
92+ print("\n".join(generate_pots(backend, path)))
93+
94+
95+if __name__ == "__main__":
96+ script = PotteryGenerateIntltool(name="pottery-generate-intltool")
97+ script.run()

Subscribers

People subscribed via source and target branches

to status/vote changes: