Merge ~cjwatson/launchpad-buildd:ttb-git into launchpad-buildd:master
- Git
- lp:~cjwatson/launchpad-buildd
- ttb-git
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | 63b920feffbe405e69997b9475b83fb0bb54cc07 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad-buildd:ttb-git |
Merge into: | launchpad-buildd:master |
Diff against target: |
496 lines (+209/-115) 5 files modified
debian/changelog (+2/-0) lpbuildd/target/generate_translation_templates.py (+24/-39) lpbuildd/target/tests/test_generate_translation_templates.py (+166/-71) lpbuildd/tests/test_translationtemplatesbuildmanager.py (+1/-1) lpbuildd/translationtemplates.py (+16/-4) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ioana Lasc (community) | Approve | ||
Review via email: mp+383063@code.launchpad.net |
Commit message
Convert translation templates builds to the VCS mixin
Description of the change
This adds git support. There'll be a fair bit of work needed on the Launchpad side before this is useful, but we might as well get started here.
This is essentially the same as https:/
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
1 | diff --git a/debian/changelog b/debian/changelog | |||
2 | index b6abb76..867b35e 100644 | |||
3 | --- a/debian/changelog | |||
4 | +++ b/debian/changelog | |||
5 | @@ -19,6 +19,8 @@ launchpad-buildd (190) UNRELEASED; urgency=medium | |||
6 | 19 | * Only include mock in tests_require for Python 2. | 19 | * Only include mock in tests_require for Python 2. |
7 | 20 | * Fix snap proxy testing for Python 3. | 20 | * Fix snap proxy testing for Python 3. |
8 | 21 | * Rename [slave] configuration section to [builder]. | 21 | * Rename [slave] configuration section to [builder]. |
9 | 22 | * Convert translation templates builds to the VCS mixin, thereby adding | ||
10 | 23 | git support. | ||
11 | 22 | 24 | ||
12 | 23 | -- Colin Watson <cjwatson@ubuntu.com> Tue, 28 Apr 2020 10:19:27 +0100 | 25 | -- Colin Watson <cjwatson@ubuntu.com> Tue, 28 Apr 2020 10:19:27 +0100 |
13 | 24 | 26 | ||
14 | diff --git a/lpbuildd/target/generate_translation_templates.py b/lpbuildd/target/generate_translation_templates.py | |||
15 | index 3e44af7..1e708ba 100644 | |||
16 | --- a/lpbuildd/target/generate_translation_templates.py | |||
17 | +++ b/lpbuildd/target/generate_translation_templates.py | |||
18 | @@ -10,6 +10,7 @@ import os.path | |||
19 | 10 | 10 | ||
20 | 11 | from lpbuildd.pottery import intltool | 11 | from lpbuildd.pottery import intltool |
21 | 12 | from lpbuildd.target.operation import Operation | 12 | from lpbuildd.target.operation import Operation |
22 | 13 | from lpbuildd.target.vcs import VCSOperationMixin | ||
23 | 13 | 14 | ||
24 | 14 | 15 | ||
25 | 15 | logger = logging.getLogger(__name__) | 16 | logger = logging.getLogger(__name__) |
26 | @@ -19,7 +20,7 @@ RETCODE_FAILURE_INSTALL = 200 | |||
27 | 19 | RETCODE_FAILURE_BUILD = 201 | 20 | RETCODE_FAILURE_BUILD = 201 |
28 | 20 | 21 | ||
29 | 21 | 22 | ||
31 | 22 | class GenerateTranslationTemplates(Operation): | 23 | class GenerateTranslationTemplates(VCSOperationMixin, Operation): |
32 | 23 | """Script to generate translation templates from a branch.""" | 24 | """Script to generate translation templates from a branch.""" |
33 | 24 | 25 | ||
34 | 25 | description = "Generate templates for a branch." | 26 | description = "Generate templates for a branch." |
35 | @@ -28,42 +29,24 @@ class GenerateTranslationTemplates(Operation): | |||
36 | 28 | def add_arguments(cls, parser): | 29 | def add_arguments(cls, parser): |
37 | 29 | super(GenerateTranslationTemplates, cls).add_arguments(parser) | 30 | super(GenerateTranslationTemplates, cls).add_arguments(parser) |
38 | 30 | parser.add_argument( | 31 | parser.add_argument( |
39 | 31 | "branch_spec", help=( | ||
40 | 32 | "A branch URL or the path of a local branch. URLs are " | ||
41 | 33 | "recognised by the occurrence of ':'. In the case of a URL, " | ||
42 | 34 | "this will make up a path for the branch and check out the " | ||
43 | 35 | "branch to there.")) | ||
44 | 36 | parser.add_argument( | ||
45 | 37 | "result_name", | 32 | "result_name", |
47 | 38 | help="The name of the result tarball. Should end in '.tar.gz'.") | 33 | help="the name of the result tarball; should end in '.tar.gz'") |
48 | 39 | 34 | ||
49 | 40 | def __init__(self, args, parser): | 35 | def __init__(self, args, parser): |
50 | 41 | super(GenerateTranslationTemplates, self).__init__(args, parser) | 36 | super(GenerateTranslationTemplates, self).__init__(args, parser) |
51 | 42 | self.work_dir = os.environ["HOME"] | 37 | self.work_dir = os.environ["HOME"] |
52 | 38 | self.branch_dir = os.path.join(self.work_dir, "source-tree") | ||
53 | 39 | |||
54 | 40 | def install(self): | ||
55 | 41 | logger.info("Installing dependencies...") | ||
56 | 42 | deps = ["intltool"] | ||
57 | 43 | deps.extend(self.vcs_deps) | ||
58 | 44 | self.backend.run(["apt-get", "-y", "install"] + deps) | ||
59 | 43 | 45 | ||
83 | 44 | def _getBranch(self): | 46 | def fetch(self, quiet=False): |
84 | 45 | """Set `self.branch_dir`, and check out branch if needed.""" | 47 | logger.info("Fetching %s...", self.vcs_description) |
85 | 46 | if ':' in self.args.branch_spec: | 48 | self.vcs_fetch( |
86 | 47 | # This is a branch URL. Check out the branch. | 49 | os.path.basename(self.branch_dir), cwd=self.work_dir, quiet=quiet) |
64 | 48 | self.branch_dir = os.path.join(self.work_dir, 'source-tree') | ||
65 | 49 | logger.info("Getting remote branch %s..." % self.args.branch_spec) | ||
66 | 50 | self._checkout(self.args.branch_spec) | ||
67 | 51 | else: | ||
68 | 52 | # This is a local filesystem path. Use the branch in-place. | ||
69 | 53 | logger.info("Using local branch %s..." % self.args.branch_spec) | ||
70 | 54 | self.branch_dir = self.args.branch_spec | ||
71 | 55 | |||
72 | 56 | def _checkout(self, branch_url): | ||
73 | 57 | """Check out a source branch to generate from. | ||
74 | 58 | |||
75 | 59 | The branch is checked out to the location specified by | ||
76 | 60 | `self.branch_dir`. | ||
77 | 61 | """ | ||
78 | 62 | logger.info( | ||
79 | 63 | "Exporting branch %s to %s..." % (branch_url, self.branch_dir)) | ||
80 | 64 | self.backend.run( | ||
81 | 65 | ["bzr", "export", "-q", "-d", branch_url, self.branch_dir]) | ||
82 | 66 | logger.info("Exporting branch done.") | ||
87 | 67 | 50 | ||
88 | 68 | def _makeTarball(self, files): | 51 | def _makeTarball(self, files): |
89 | 69 | """Put the given files into a tarball in the working directory.""" | 52 | """Put the given files into a tarball in the working directory.""" |
90 | @@ -78,21 +61,23 @@ class GenerateTranslationTemplates(Operation): | |||
91 | 78 | self.backend.run(cmd) | 61 | self.backend.run(cmd) |
92 | 79 | logger.info("Tarball generated.") | 62 | logger.info("Tarball generated.") |
93 | 80 | 63 | ||
94 | 64 | def generate(self): | ||
95 | 65 | logger.info("Generating templates...") | ||
96 | 66 | pots = intltool.generate_pots(self.backend, self.branch_dir) | ||
97 | 67 | logger.info("Generated %d templates." % len(pots)) | ||
98 | 68 | if len(pots) > 0: | ||
99 | 69 | self._makeTarball(pots) | ||
100 | 70 | |||
101 | 81 | def run(self): | 71 | def run(self): |
102 | 82 | """Do It. Generate templates.""" | 72 | """Do It. Generate templates.""" |
103 | 83 | try: | 73 | try: |
105 | 84 | self.backend.run(["apt-get", "-y", "install", "bzr", "intltool"]) | 74 | self.install() |
106 | 85 | except Exception: | 75 | except Exception: |
107 | 86 | logger.exception("Install failed") | 76 | logger.exception("Install failed") |
108 | 87 | return RETCODE_FAILURE_INSTALL | 77 | return RETCODE_FAILURE_INSTALL |
109 | 88 | try: | 78 | try: |
117 | 89 | logger.info( | 79 | self.fetch() |
118 | 90 | "Generating templates for %s." % self.args.branch_spec) | 80 | self.generate() |
112 | 91 | self._getBranch() | ||
113 | 92 | pots = intltool.generate_pots(self.backend, self.branch_dir) | ||
114 | 93 | logger.info("Generated %d templates." % len(pots)) | ||
115 | 94 | if len(pots) > 0: | ||
116 | 95 | self._makeTarball(pots) | ||
119 | 96 | except Exception: | 81 | except Exception: |
120 | 97 | logger.exception("Build failed") | 82 | logger.exception("Build failed") |
121 | 98 | return RETCODE_FAILURE_BUILD | 83 | return RETCODE_FAILURE_BUILD |
122 | diff --git a/lpbuildd/target/tests/test_generate_translation_templates.py b/lpbuildd/target/tests/test_generate_translation_templates.py | |||
123 | index 16f6848..864e595 100644 | |||
124 | --- a/lpbuildd/target/tests/test_generate_translation_templates.py | |||
125 | +++ b/lpbuildd/target/tests/test_generate_translation_templates.py | |||
126 | @@ -15,23 +15,37 @@ from fixtures import ( | |||
127 | 15 | from testtools import TestCase | 15 | from testtools import TestCase |
128 | 16 | from testtools.matchers import ( | 16 | from testtools.matchers import ( |
129 | 17 | ContainsDict, | 17 | ContainsDict, |
130 | 18 | EndsWith, | ||
131 | 19 | Equals, | 18 | Equals, |
132 | 19 | Is, | ||
133 | 20 | MatchesDict, | ||
134 | 20 | MatchesListwise, | 21 | MatchesListwise, |
135 | 21 | MatchesSetwise, | 22 | MatchesSetwise, |
136 | 22 | ) | 23 | ) |
137 | 23 | 24 | ||
138 | 24 | from lpbuildd.target.cli import parse_args | 25 | from lpbuildd.target.cli import parse_args |
139 | 25 | from lpbuildd.tests.fakebuilder import FakeMethod | ||
140 | 26 | 26 | ||
141 | 27 | 27 | ||
143 | 28 | class MatchesCall(MatchesListwise): | 28 | class RanCommand(MatchesListwise): |
144 | 29 | 29 | ||
150 | 30 | def __init__(self, *args, **kwargs): | 30 | def __init__(self, args, get_output=None, echo=None, cwd=None, **env): |
151 | 31 | super(MatchesCall, self).__init__([ | 31 | kwargs_matcher = {} |
152 | 32 | Equals(args), | 32 | if get_output is not None: |
153 | 33 | ContainsDict( | 33 | kwargs_matcher["get_output"] = Is(get_output) |
154 | 34 | {name: Equals(value) for name, value in kwargs.items()})]) | 34 | if echo is not None: |
155 | 35 | kwargs_matcher["echo"] = Is(echo) | ||
156 | 36 | if cwd: | ||
157 | 37 | kwargs_matcher["cwd"] = Equals(cwd) | ||
158 | 38 | if env: | ||
159 | 39 | kwargs_matcher["env"] = MatchesDict( | ||
160 | 40 | {key: Equals(value) for key, value in env.items()}) | ||
161 | 41 | super(RanCommand, self).__init__( | ||
162 | 42 | [Equals((args,)), ContainsDict(kwargs_matcher)]) | ||
163 | 43 | |||
164 | 44 | |||
165 | 45 | class RanAptGet(RanCommand): | ||
166 | 46 | |||
167 | 47 | def __init__(self, *args): | ||
168 | 48 | super(RanAptGet, self).__init__(["apt-get", "-y"] + list(args)) | ||
169 | 35 | 49 | ||
170 | 36 | 50 | ||
171 | 37 | class TestGenerateTranslationTemplates(TestCase): | 51 | class TestGenerateTranslationTemplates(TestCase): |
172 | @@ -45,82 +59,125 @@ class TestGenerateTranslationTemplates(TestCase): | |||
173 | 45 | self.useFixture(EnvironmentVariable("HOME", self.home_dir)) | 59 | self.useFixture(EnvironmentVariable("HOME", self.home_dir)) |
174 | 46 | self.logger = self.useFixture(FakeLogger()) | 60 | self.logger = self.useFixture(FakeLogger()) |
175 | 47 | 61 | ||
179 | 48 | def test_getBranch_url(self): | 62 | def make_branch_contents(self, content_map): |
180 | 49 | # If passed a branch URL, the template generation script will | 63 | """Create a directory with the contents of a working branch. |
181 | 50 | # check out that branch into a directory called "source-tree." | 64 | |
182 | 65 | :param content_map: A dict mapping file names to file contents. | ||
183 | 66 | Each of these files with their contents will be written to the | ||
184 | 67 | branch. Currently only supports writing files at the root | ||
185 | 68 | directory of the branch. | ||
186 | 69 | """ | ||
187 | 70 | branch_path = self.useFixture(TempDir()).path | ||
188 | 71 | for name, contents in content_map.items(): | ||
189 | 72 | with open(os.path.join(branch_path, name), 'wb') as f: | ||
190 | 73 | f.write(contents) | ||
191 | 74 | return branch_path | ||
192 | 75 | |||
193 | 76 | def make_bzr_branch(self, branch_path): | ||
194 | 77 | """Make a bzr branch from an existing directory.""" | ||
195 | 78 | bzr_home = self.useFixture(TempDir()).path | ||
196 | 79 | self.useFixture(EnvironmentVariable("BZR_HOME", bzr_home)) | ||
197 | 80 | self.useFixture(EnvironmentVariable("BZR_EMAIL")) | ||
198 | 81 | self.useFixture(EnvironmentVariable("EMAIL")) | ||
199 | 82 | |||
200 | 83 | subprocess.check_call(["bzr", "init", "-q"], cwd=branch_path) | ||
201 | 84 | subprocess.check_call(["bzr", "add", "-q"], cwd=branch_path) | ||
202 | 85 | committer_id = "Committer <committer@example.com>" | ||
203 | 86 | with EnvironmentVariable("BZR_EMAIL", committer_id): | ||
204 | 87 | subprocess.check_call( | ||
205 | 88 | ["bzr", "commit", "-q", "-m", "Populating branch."], | ||
206 | 89 | cwd=branch_path) | ||
207 | 90 | |||
208 | 91 | def make_git_branch(self, branch_path): | ||
209 | 92 | subprocess.check_call(["git", "init", "-q"], cwd=branch_path) | ||
210 | 93 | subprocess.check_call( | ||
211 | 94 | ["git", "config", "user.name", "Committer"], cwd=branch_path) | ||
212 | 95 | subprocess.check_call( | ||
213 | 96 | ["git", "config", "user.email", "committer@example.com"], | ||
214 | 97 | cwd=branch_path) | ||
215 | 98 | subprocess.check_call(["git", "add", "."], cwd=branch_path) | ||
216 | 99 | subprocess.check_call( | ||
217 | 100 | ["git", "commit", "-q", "--allow-empty", | ||
218 | 101 | "-m", "Populating branch"], | ||
219 | 102 | cwd=branch_path) | ||
220 | 103 | |||
221 | 104 | def test_install_bzr(self): | ||
222 | 51 | args = [ | 105 | args = [ |
223 | 52 | "generate-translation-templates", | 106 | "generate-translation-templates", |
224 | 53 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | 107 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
226 | 54 | "lp://~my/translation/branch", self.result_name, | 108 | "--branch", "lp:foo", self.result_name, |
227 | 55 | ] | 109 | ] |
228 | 56 | generator = parse_args(args=args).operation | 110 | generator = parse_args(args=args).operation |
234 | 57 | generator._checkout = FakeMethod() | 111 | generator.install() |
235 | 58 | generator._getBranch() | 112 | self.assertThat(generator.backend.run.calls, MatchesListwise([ |
236 | 59 | 113 | RanAptGet("install", "intltool", "bzr"), | |
237 | 60 | self.assertEqual(1, generator._checkout.call_count) | 114 | ])) |
233 | 61 | self.assertThat(generator.branch_dir, EndsWith("source-tree")) | ||
238 | 62 | 115 | ||
243 | 63 | def test_getBranch_dir(self): | 116 | def test_install_git(self): |
240 | 64 | # If passed a branch directory, the template generation script | ||
241 | 65 | # works directly in that directory. | ||
242 | 66 | branch_dir = "/home/me/branch" | ||
244 | 67 | args = [ | 117 | args = [ |
245 | 68 | "generate-translation-templates", | 118 | "generate-translation-templates", |
246 | 69 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | 119 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
248 | 70 | branch_dir, self.result_name, | 120 | "--git-repository", "lp:foo", self.result_name, |
249 | 71 | ] | 121 | ] |
250 | 72 | generator = parse_args(args=args).operation | 122 | generator = parse_args(args=args).operation |
256 | 73 | generator._checkout = FakeMethod() | 123 | generator.install() |
257 | 74 | generator._getBranch() | 124 | self.assertThat(generator.backend.run.calls, MatchesListwise([ |
258 | 75 | 125 | RanAptGet("install", "intltool", "git"), | |
259 | 76 | self.assertEqual(0, generator._checkout.call_count) | 126 | ])) |
255 | 77 | self.assertEqual(branch_dir, generator.branch_dir) | ||
260 | 78 | 127 | ||
263 | 79 | def _createBranch(self, content_map=None): | 128 | def test_fetch_bzr(self): |
264 | 80 | """Create a working branch. | 129 | # fetch can retrieve branch contents from a Bazaar branch. |
265 | 130 | marker_text = "Ceci n'est pas cet branch." | ||
266 | 131 | branch_path = self.make_branch_contents({'marker.txt': marker_text}) | ||
267 | 132 | self.make_bzr_branch(branch_path) | ||
268 | 81 | 133 | ||
273 | 82 | :param content_map: optional dict mapping file names to file | 134 | args = [ |
274 | 83 | contents. Each of these files with their contents will be | 135 | "generate-translation-templates", |
275 | 84 | written to the branch. Currently only supports writing files at | 136 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", |
276 | 85 | the root directory of the branch. | 137 | "--branch", branch_path, self.result_name, |
277 | 138 | ] | ||
278 | 139 | generator = parse_args(args=args).operation | ||
279 | 140 | generator.fetch(quiet=True) | ||
280 | 86 | 141 | ||
286 | 87 | :return: the URL of a fresh bzr branch. | 142 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') |
287 | 88 | """ | 143 | with open(marker_path) as marker_file: |
288 | 89 | branch_path = self.useFixture(TempDir()).path | 144 | self.assertEqual(marker_text, marker_file.read()) |
284 | 90 | branch_url = 'file://' + branch_path | ||
285 | 91 | subprocess.check_call(['bzr', 'init', '-q'], cwd=branch_path) | ||
289 | 92 | 145 | ||
301 | 93 | if content_map is not None: | 146 | def test_fetch_git(self): |
302 | 94 | for name, contents in content_map.items(): | 147 | # fetch can retrieve branch contents from a Git repository. |
303 | 95 | with open(os.path.join(branch_path, name), 'wb') as f: | 148 | marker_text = b"Ceci n'est pas cet branch." |
304 | 96 | f.write(contents) | 149 | branch_path = self.make_branch_contents({'marker.txt': marker_text}) |
305 | 97 | subprocess.check_call( | 150 | self.make_git_branch(branch_path) |
295 | 98 | ['bzr', 'add', '-q'] + list(content_map), cwd=branch_path) | ||
296 | 99 | committer_id = 'Committer <committer@example.com>' | ||
297 | 100 | with EnvironmentVariable('BZR_EMAIL', committer_id): | ||
298 | 101 | subprocess.check_call( | ||
299 | 102 | ['bzr', 'commit', '-q', '-m', 'Populating branch.'], | ||
300 | 103 | cwd=branch_path) | ||
306 | 104 | 151 | ||
308 | 105 | return branch_url | 152 | args = [ |
309 | 153 | "generate-translation-templates", | ||
310 | 154 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | ||
311 | 155 | "--git-repository", branch_path, self.result_name, | ||
312 | 156 | ] | ||
313 | 157 | generator = parse_args(args=args).operation | ||
314 | 158 | generator.fetch(quiet=True) | ||
315 | 106 | 159 | ||
322 | 107 | def test_getBranch_bzr(self): | 160 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') |
323 | 108 | # _getBranch can retrieve branch contents from a branch URL. | 161 | with open(marker_path, "rb") as marker_file: |
324 | 109 | bzr_home = self.useFixture(TempDir()).path | 162 | self.assertEqual(marker_text, marker_file.read()) |
319 | 110 | self.useFixture(EnvironmentVariable('BZR_HOME', bzr_home)) | ||
320 | 111 | self.useFixture(EnvironmentVariable('BZR_EMAIL')) | ||
321 | 112 | self.useFixture(EnvironmentVariable('EMAIL')) | ||
325 | 113 | 163 | ||
326 | 164 | def test_fetch_git_with_path(self): | ||
327 | 165 | # fetch can retrieve branch contents from a Git repository and | ||
328 | 166 | # branch name. | ||
329 | 114 | marker_text = b"Ceci n'est pas cet branch." | 167 | marker_text = b"Ceci n'est pas cet branch." |
331 | 115 | branch_url = self._createBranch({'marker.txt': marker_text}) | 168 | branch_path = self.make_branch_contents({'marker.txt': marker_text}) |
332 | 169 | self.make_git_branch(branch_path) | ||
333 | 170 | subprocess.call( | ||
334 | 171 | ["git", "branch", "-m", "master", "next"], cwd=branch_path) | ||
335 | 116 | 172 | ||
336 | 117 | args = [ | 173 | args = [ |
337 | 118 | "generate-translation-templates", | 174 | "generate-translation-templates", |
338 | 119 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | 175 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", |
340 | 120 | branch_url, self.result_name, | 176 | "--git-repository", branch_path, "--git-path", "next", |
341 | 177 | self.result_name, | ||
342 | 121 | ] | 178 | ] |
343 | 122 | generator = parse_args(args=args).operation | 179 | generator = parse_args(args=args).operation |
345 | 123 | generator._getBranch() | 180 | generator.fetch(quiet=True) |
346 | 124 | 181 | ||
347 | 125 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') | 182 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') |
348 | 126 | with open(marker_path, "rb") as marker_file: | 183 | with open(marker_path, "rb") as marker_file: |
349 | @@ -136,22 +193,23 @@ class TestGenerateTranslationTemplates(TestCase): | |||
350 | 136 | potnames = [ | 193 | potnames = [ |
351 | 137 | member.name | 194 | member.name |
352 | 138 | for member in tar.getmembers() if not member.isdir()] | 195 | for member in tar.getmembers() if not member.isdir()] |
353 | 196 | self.make_bzr_branch(branchdir) | ||
354 | 139 | 197 | ||
355 | 140 | args = [ | 198 | args = [ |
356 | 141 | "generate-translation-templates", | 199 | "generate-translation-templates", |
357 | 142 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | 200 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", |
359 | 143 | branchdir, self.result_name, | 201 | "--branch", branchdir, self.result_name, |
360 | 144 | ] | 202 | ] |
361 | 145 | generator = parse_args(args=args).operation | 203 | generator = parse_args(args=args).operation |
363 | 146 | generator._getBranch() | 204 | generator.fetch(quiet=True) |
364 | 147 | generator._makeTarball(potnames) | 205 | generator._makeTarball(potnames) |
365 | 148 | result_path = os.path.join(self.home_dir, self.result_name) | 206 | result_path = os.path.join(self.home_dir, self.result_name) |
366 | 149 | with tarfile.open(result_path, 'r|*') as tar: | 207 | with tarfile.open(result_path, 'r|*') as tar: |
367 | 150 | tarnames = tar.getnames() | 208 | tarnames = tar.getnames() |
368 | 151 | self.assertThat(tarnames, MatchesSetwise(*(map(Equals, potnames)))) | 209 | self.assertThat(tarnames, MatchesSetwise(*(map(Equals, potnames)))) |
369 | 152 | 210 | ||
372 | 153 | def test_run(self): | 211 | def test_run_bzr(self): |
373 | 154 | # Install dependencies and generate a templates tarball. | 212 | # Install dependencies and generate a templates tarball from Bazaar. |
374 | 155 | branch_url = "lp:~my/branch" | 213 | branch_url = "lp:~my/branch" |
375 | 156 | branch_dir = os.path.join(self.home_dir, "source-tree") | 214 | branch_dir = os.path.join(self.home_dir, "source-tree") |
376 | 157 | po_dir = os.path.join(branch_dir, "po") | 215 | po_dir = os.path.join(branch_dir, "po") |
377 | @@ -160,7 +218,40 @@ class TestGenerateTranslationTemplates(TestCase): | |||
378 | 160 | args = [ | 218 | args = [ |
379 | 161 | "generate-translation-templates", | 219 | "generate-translation-templates", |
380 | 162 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | 220 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
382 | 163 | branch_url, self.result_name, | 221 | "--branch", branch_url, self.result_name, |
383 | 222 | ] | ||
384 | 223 | generator = parse_args(args=args).operation | ||
385 | 224 | generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), "") | ||
386 | 225 | generator.backend.add_file( | ||
387 | 226 | os.path.join(po_dir, "Makevars"), "DOMAIN = test\n") | ||
388 | 227 | generator.run() | ||
389 | 228 | self.assertThat(generator.backend.run.calls, MatchesListwise([ | ||
390 | 229 | RanAptGet("install", "intltool", "bzr"), | ||
391 | 230 | RanCommand( | ||
392 | 231 | ["bzr", "branch", "lp:~my/branch", "source-tree"], | ||
393 | 232 | cwd=self.home_dir, LANG="C.UTF-8", SHELL="/bin/sh"), | ||
394 | 233 | RanCommand( | ||
395 | 234 | ["rm", "-f", | ||
396 | 235 | os.path.join(po_dir, "missing"), | ||
397 | 236 | os.path.join(po_dir, "notexist")]), | ||
398 | 237 | RanCommand(["/usr/bin/intltool-update", "-m"], cwd=po_dir), | ||
399 | 238 | RanCommand( | ||
400 | 239 | ["/usr/bin/intltool-update", "-p", "-g", "test"], cwd=po_dir), | ||
401 | 240 | RanCommand( | ||
402 | 241 | ["tar", "-C", branch_dir, "-czf", result_path, "po/test.pot"]), | ||
403 | 242 | ])) | ||
404 | 243 | |||
405 | 244 | def test_run_git(self): | ||
406 | 245 | # Install dependencies and generate a templates tarball from Git. | ||
407 | 246 | repository_url = "lp:~my/repository" | ||
408 | 247 | branch_dir = os.path.join(self.home_dir, "source-tree") | ||
409 | 248 | po_dir = os.path.join(branch_dir, "po") | ||
410 | 249 | result_path = os.path.join(self.home_dir, self.result_name) | ||
411 | 250 | |||
412 | 251 | args = [ | ||
413 | 252 | "generate-translation-templates", | ||
414 | 253 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | ||
415 | 254 | "--git-repository", repository_url, self.result_name, | ||
416 | 164 | ] | 255 | ] |
417 | 165 | generator = parse_args(args=args).operation | 256 | generator = parse_args(args=args).operation |
418 | 166 | generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), b"") | 257 | generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), b"") |
419 | @@ -168,16 +259,20 @@ class TestGenerateTranslationTemplates(TestCase): | |||
420 | 168 | os.path.join(po_dir, "Makevars"), b"DOMAIN = test\n") | 259 | os.path.join(po_dir, "Makevars"), b"DOMAIN = test\n") |
421 | 169 | generator.run() | 260 | generator.run() |
422 | 170 | self.assertThat(generator.backend.run.calls, MatchesListwise([ | 261 | self.assertThat(generator.backend.run.calls, MatchesListwise([ |
427 | 171 | MatchesCall(["apt-get", "-y", "install", "bzr", "intltool"]), | 262 | RanAptGet("install", "intltool", "git"), |
428 | 172 | MatchesCall( | 263 | RanCommand( |
429 | 173 | ["bzr", "export", "-q", "-d", "lp:~my/branch", branch_dir]), | 264 | ["git", "clone", "lp:~my/repository", "source-tree"], |
430 | 174 | MatchesCall( | 265 | cwd=self.home_dir, LANG="C.UTF-8", SHELL="/bin/sh"), |
431 | 266 | RanCommand( | ||
432 | 267 | ["git", "submodule", "update", "--init", "--recursive"], | ||
433 | 268 | cwd=branch_dir, LANG="C.UTF-8", SHELL="/bin/sh"), | ||
434 | 269 | RanCommand( | ||
435 | 175 | ["rm", "-f", | 270 | ["rm", "-f", |
436 | 176 | os.path.join(po_dir, "missing"), | 271 | os.path.join(po_dir, "missing"), |
437 | 177 | os.path.join(po_dir, "notexist")]), | 272 | os.path.join(po_dir, "notexist")]), |
440 | 178 | MatchesCall(["/usr/bin/intltool-update", "-m"], cwd=po_dir), | 273 | RanCommand(["/usr/bin/intltool-update", "-m"], cwd=po_dir), |
441 | 179 | MatchesCall( | 274 | RanCommand( |
442 | 180 | ["/usr/bin/intltool-update", "-p", "-g", "test"], cwd=po_dir), | 275 | ["/usr/bin/intltool-update", "-p", "-g", "test"], cwd=po_dir), |
444 | 181 | MatchesCall( | 276 | RanCommand( |
445 | 182 | ["tar", "-C", branch_dir, "-czf", result_path, "po/test.pot"]), | 277 | ["tar", "-C", branch_dir, "-czf", result_path, "po/test.pot"]), |
446 | 183 | ])) | 278 | ])) |
447 | diff --git a/lpbuildd/tests/test_translationtemplatesbuildmanager.py b/lpbuildd/tests/test_translationtemplatesbuildmanager.py | |||
448 | index a47e5f8..196f4d8 100644 | |||
449 | --- a/lpbuildd/tests/test_translationtemplatesbuildmanager.py | |||
450 | +++ b/lpbuildd/tests/test_translationtemplatesbuildmanager.py | |||
451 | @@ -88,7 +88,7 @@ class TestTranslationTemplatesBuildManagerIteration(TestCase): | |||
452 | 88 | 'generate-translation-templates', | 88 | 'generate-translation-templates', |
453 | 89 | '--backend=chroot', '--series=xenial', '--arch=i386', | 89 | '--backend=chroot', '--series=xenial', '--arch=i386', |
454 | 90 | self.buildid, | 90 | self.buildid, |
456 | 91 | url, 'resultarchive', | 91 | '--branch', url, 'resultarchive', |
457 | 92 | ] | 92 | ] |
458 | 93 | self.assertEqual(expected_command, self.buildmanager.commands[-1]) | 93 | self.assertEqual(expected_command, self.buildmanager.commands[-1]) |
459 | 94 | self.assertEqual( | 94 | self.assertEqual( |
460 | diff --git a/lpbuildd/translationtemplates.py b/lpbuildd/translationtemplates.py | |||
461 | index 2e778c5..36f4335 100644 | |||
462 | --- a/lpbuildd/translationtemplates.py | |||
463 | +++ b/lpbuildd/translationtemplates.py | |||
464 | @@ -37,16 +37,28 @@ class TranslationTemplatesBuildManager(DebianBuildManager): | |||
465 | 37 | 37 | ||
466 | 38 | def initiate(self, files, chroot, extra_args): | 38 | def initiate(self, files, chroot, extra_args): |
467 | 39 | """See `BuildManager`.""" | 39 | """See `BuildManager`.""" |
469 | 40 | self._branch_url = extra_args['branch_url'] | 40 | self.branch = extra_args.get('branch') |
470 | 41 | # XXX cjwatson 2017-11-10: Backward-compatibility; remove once the | ||
471 | 42 | # manager passes branch instead. | ||
472 | 43 | if self.branch is None: | ||
473 | 44 | self.branch = extra_args['branch_url'] | ||
474 | 45 | self.git_repository = extra_args.get("git_repository") | ||
475 | 46 | self.git_path = extra_args.get("git_path") | ||
476 | 41 | 47 | ||
477 | 42 | super(TranslationTemplatesBuildManager, self).initiate( | 48 | super(TranslationTemplatesBuildManager, self).initiate( |
478 | 43 | files, chroot, extra_args) | 49 | files, chroot, extra_args) |
479 | 44 | 50 | ||
480 | 45 | def doGenerate(self): | 51 | def doGenerate(self): |
481 | 46 | """Generate templates.""" | 52 | """Generate templates.""" |
485 | 47 | self.runTargetSubProcess( | 53 | args = [] |
486 | 48 | "generate-translation-templates", | 54 | if self.branch is not None: |
487 | 49 | self._branch_url, self._resultname) | 55 | args.extend(["--branch", self.branch]) |
488 | 56 | if self.git_repository is not None: | ||
489 | 57 | args.extend(["--git-repository", self.git_repository]) | ||
490 | 58 | if self.git_path is not None: | ||
491 | 59 | args.extend(["--git-path", self.git_path]) | ||
492 | 60 | args.append(self._resultname) | ||
493 | 61 | self.runTargetSubProcess("generate-translation-templates", *args) | ||
494 | 50 | 62 | ||
495 | 51 | # Satisfy DebianPackageManager's needs without having a misleading | 63 | # Satisfy DebianPackageManager's needs without having a misleading |
496 | 52 | # method name here. | 64 | # method name here. |