Merge lp:~cjwatson/launchpad-buildd/ttb-git into lp:launchpad-buildd
- ttb-git
- Merge into trunk
Proposed by
Colin Watson
Status: | Rejected |
---|---|
Rejected by: | Colin Watson |
Proposed branch: | lp:~cjwatson/launchpad-buildd/ttb-git |
Merge into: | lp:launchpad-buildd |
Prerequisite: | lp:~cjwatson/launchpad-buildd/refactor-vcs |
Diff against target: |
532 lines (+246/-152) 5 files modified
debian/changelog (+2/-0) lpbuildd/target/generate_translation_templates.py (+25/-40) lpbuildd/target/tests/test_generate_translation_templates.py (+202/-107) lpbuildd/tests/test_translationtemplatesbuildmanager.py (+1/-1) lpbuildd/translationtemplates.py (+16/-4) |
To merge this branch: | bzr merge lp:~cjwatson/launchpad-buildd/ttb-git |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Launchpad code reviewers | Pending | ||
Review via email: mp+341389@code.launchpad.net |
Commit message
Convert translation templates builds to the new VCS mixin, thereby adding git support.
Description of the change
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.
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote : | # |
Unmerged revisions
- 329. By Colin Watson
-
Convert translation templates builds to the new VCS mixin, thereby adding git support.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/changelog' | |||
2 | --- debian/changelog 2018-03-14 14:15:15 +0000 | |||
3 | +++ debian/changelog 2018-03-14 14:15:15 +0000 | |||
4 | @@ -7,6 +7,8 @@ | |||
5 | 7 | * Allow optionally installing snapcraft as a snap (LP: #1737994). | 7 | * Allow optionally installing snapcraft as a snap (LP: #1737994). |
6 | 8 | * Refactor VCS operations from lpbuildd.target.build_snap out to a module | 8 | * Refactor VCS operations from lpbuildd.target.build_snap out to a module |
7 | 9 | that can be used by other targets. | 9 | that can be used by other targets. |
8 | 10 | * Convert translation templates builds to the new VCS mixin, thereby | ||
9 | 11 | adding git support. | ||
10 | 10 | 12 | ||
11 | 11 | -- Colin Watson <cjwatson@ubuntu.com> Fri, 02 Feb 2018 16:14:46 +0000 | 13 | -- Colin Watson <cjwatson@ubuntu.com> Fri, 02 Feb 2018 16:14:46 +0000 |
12 | 12 | 14 | ||
13 | 13 | 15 | ||
14 | === modified file 'lpbuildd/target/generate_translation_templates.py' | |||
15 | --- lpbuildd/target/generate_translation_templates.py 2017-11-10 22:13:03 +0000 | |||
16 | +++ lpbuildd/target/generate_translation_templates.py 2018-03-14 14:15:15 +0000 | |||
17 | @@ -10,6 +10,7 @@ | |||
18 | 10 | 10 | ||
19 | 11 | from lpbuildd.pottery import intltool | 11 | from lpbuildd.pottery import intltool |
20 | 12 | from lpbuildd.target.operation import Operation | 12 | from lpbuildd.target.operation import Operation |
21 | 13 | from lpbuildd.target.vcs import VCSOperationMixin | ||
22 | 13 | 14 | ||
23 | 14 | 15 | ||
24 | 15 | logger = logging.getLogger(__name__) | 16 | logger = logging.getLogger(__name__) |
25 | @@ -19,7 +20,7 @@ | |||
26 | 19 | RETCODE_FAILURE_BUILD = 201 | 20 | RETCODE_FAILURE_BUILD = 201 |
27 | 20 | 21 | ||
28 | 21 | 22 | ||
30 | 22 | class GenerateTranslationTemplates(Operation): | 23 | class GenerateTranslationTemplates(VCSOperationMixin, Operation): |
31 | 23 | """Script to generate translation templates from a branch.""" | 24 | """Script to generate translation templates from a branch.""" |
32 | 24 | 25 | ||
33 | 25 | description = "Generate templates for a branch." | 26 | description = "Generate templates for a branch." |
34 | @@ -28,42 +29,24 @@ | |||
35 | 28 | def add_arguments(cls, parser): | 29 | def add_arguments(cls, parser): |
36 | 29 | super(GenerateTranslationTemplates, cls).add_arguments(parser) | 30 | super(GenerateTranslationTemplates, cls).add_arguments(parser) |
37 | 30 | parser.add_argument( | 31 | parser.add_argument( |
38 | 31 | "branch_spec", help=( | ||
39 | 32 | "A branch URL or the path of a local branch. URLs are " | ||
40 | 33 | "recognised by the occurrence of ':'. In the case of a URL, " | ||
41 | 34 | "this will make up a path for the branch and check out the " | ||
42 | 35 | "branch to there.")) | ||
43 | 36 | parser.add_argument( | ||
44 | 37 | "result_name", | 32 | "result_name", |
46 | 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'") |
47 | 39 | 34 | ||
48 | 40 | def __init__(self, args, parser): | 35 | def __init__(self, args, parser): |
49 | 41 | super(GenerateTranslationTemplates, self).__init__(args, parser) | 36 | super(GenerateTranslationTemplates, self).__init__(args, parser) |
50 | 42 | self.work_dir = os.environ["HOME"] | 37 | self.work_dir = os.environ["HOME"] |
75 | 43 | 38 | self.branch_dir = os.path.join(self.work_dir, "source-tree") | |
76 | 44 | def _getBranch(self): | 39 | |
77 | 45 | """Set `self.branch_dir`, and check out branch if needed.""" | 40 | def install(self): |
78 | 46 | if ':' in self.args.branch_spec: | 41 | logger.info("Installing dependencies...") |
79 | 47 | # This is a branch URL. Check out the branch. | 42 | deps = ["intltool"] |
80 | 48 | self.branch_dir = os.path.join(self.work_dir, 'source-tree') | 43 | deps.extend(self.vcs_deps) |
81 | 49 | logger.info("Getting remote branch %s..." % self.args.branch_spec) | 44 | self.backend.run(["apt-get", "-y", "install"] + deps) |
82 | 50 | self._checkout(self.args.branch_spec) | 45 | |
83 | 51 | else: | 46 | def fetch(self, quiet=False): |
84 | 52 | # This is a local filesystem path. Use the branch in-place. | 47 | logger.info("Fetching %s...", self.vcs_description) |
85 | 53 | logger.info("Using local branch %s..." % self.args.branch_spec) | 48 | self.vcs_fetch( |
86 | 54 | self.branch_dir = self.args.branch_spec | 49 | os.path.basename(self.branch_dir), cwd=self.work_dir, quiet=quiet) |
63 | 55 | |||
64 | 56 | def _checkout(self, branch_url): | ||
65 | 57 | """Check out a source branch to generate from. | ||
66 | 58 | |||
67 | 59 | The branch is checked out to the location specified by | ||
68 | 60 | `self.branch_dir`. | ||
69 | 61 | """ | ||
70 | 62 | logger.info( | ||
71 | 63 | "Exporting branch %s to %s..." % (branch_url, self.branch_dir)) | ||
72 | 64 | self.backend.run( | ||
73 | 65 | ["bzr", "export", "-q", "-d", branch_url, self.branch_dir]) | ||
74 | 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 @@ | |||
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 | 99 | 84 | ||
123 | === modified file 'lpbuildd/target/tests/test_generate_translation_templates.py' | |||
124 | --- lpbuildd/target/tests/test_generate_translation_templates.py 2017-10-27 08:08:49 +0000 | |||
125 | +++ lpbuildd/target/tests/test_generate_translation_templates.py 2018-03-14 14:15:15 +0000 | |||
126 | @@ -15,23 +15,37 @@ | |||
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 |
149 | 25 | from lpbuildd.tests.fakeslave import FakeMethod | 26 | |
150 | 26 | 27 | ||
151 | 27 | 28 | class RanCommand(MatchesListwise): | |
152 | 28 | class MatchesCall(MatchesListwise): | 29 | |
153 | 29 | 30 | def __init__(self, args, get_output=None, echo=None, cwd=None, **env): | |
154 | 30 | def __init__(self, *args, **kwargs): | 31 | kwargs_matcher = {} |
155 | 31 | super(MatchesCall, self).__init__([ | 32 | if get_output is not None: |
156 | 32 | Equals(args), | 33 | kwargs_matcher["get_output"] = Is(get_output) |
157 | 33 | ContainsDict( | 34 | if echo is not None: |
158 | 34 | {name: Equals(value) for name, value in kwargs.items()})]) | 35 | kwargs_matcher["echo"] = Is(echo) |
159 | 36 | if cwd: | ||
160 | 37 | kwargs_matcher["cwd"] = Equals(cwd) | ||
161 | 38 | if env: | ||
162 | 39 | kwargs_matcher["env"] = MatchesDict( | ||
163 | 40 | {key: Equals(value) for key, value in env.items()}) | ||
164 | 41 | super(RanCommand, self).__init__( | ||
165 | 42 | [Equals((args,)), ContainsDict(kwargs_matcher)]) | ||
166 | 43 | |||
167 | 44 | |||
168 | 45 | class RanAptGet(RanCommand): | ||
169 | 46 | |||
170 | 47 | def __init__(self, *args): | ||
171 | 48 | super(RanAptGet, self).__init__(["apt-get", "-y"] + list(args)) | ||
172 | 35 | 49 | ||
173 | 36 | 50 | ||
174 | 37 | class TestGenerateTranslationTemplates(TestCase): | 51 | class TestGenerateTranslationTemplates(TestCase): |
175 | @@ -45,82 +59,125 @@ | |||
176 | 45 | self.useFixture(EnvironmentVariable("HOME", self.home_dir)) | 59 | self.useFixture(EnvironmentVariable("HOME", self.home_dir)) |
177 | 46 | self.logger = self.useFixture(FakeLogger()) | 60 | self.logger = self.useFixture(FakeLogger()) |
178 | 47 | 61 | ||
219 | 48 | def test_getBranch_url(self): | 62 | def make_branch_contents(self, content_map): |
220 | 49 | # If passed a branch URL, the template generation script will | 63 | """Create a directory with the contents of a working branch. |
221 | 50 | # check out that branch into a directory called "source-tree." | 64 | |
222 | 51 | args = [ | 65 | :param content_map: A dict mapping file names to file contents. |
223 | 52 | "generate-translation-templates", | 66 | Each of these files with their contents will be written to the |
224 | 53 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | 67 | branch. Currently only supports writing files at the root |
225 | 54 | "lp://~my/translation/branch", self.result_name, | 68 | directory of the branch. |
186 | 55 | ] | ||
187 | 56 | generator = parse_args(args=args).operation | ||
188 | 57 | generator._checkout = FakeMethod() | ||
189 | 58 | generator._getBranch() | ||
190 | 59 | |||
191 | 60 | self.assertEqual(1, generator._checkout.call_count) | ||
192 | 61 | self.assertThat(generator.branch_dir, EndsWith("source-tree")) | ||
193 | 62 | |||
194 | 63 | def test_getBranch_dir(self): | ||
195 | 64 | # If passed a branch directory, the template generation script | ||
196 | 65 | # works directly in that directory. | ||
197 | 66 | branch_dir = "/home/me/branch" | ||
198 | 67 | args = [ | ||
199 | 68 | "generate-translation-templates", | ||
200 | 69 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | ||
201 | 70 | branch_dir, self.result_name, | ||
202 | 71 | ] | ||
203 | 72 | generator = parse_args(args=args).operation | ||
204 | 73 | generator._checkout = FakeMethod() | ||
205 | 74 | generator._getBranch() | ||
206 | 75 | |||
207 | 76 | self.assertEqual(0, generator._checkout.call_count) | ||
208 | 77 | self.assertEqual(branch_dir, generator.branch_dir) | ||
209 | 78 | |||
210 | 79 | def _createBranch(self, content_map=None): | ||
211 | 80 | """Create a working branch. | ||
212 | 81 | |||
213 | 82 | :param content_map: optional dict mapping file names to file | ||
214 | 83 | contents. Each of these files with their contents will be | ||
215 | 84 | written to the branch. Currently only supports writing files at | ||
216 | 85 | the root directory of the branch. | ||
217 | 86 | |||
218 | 87 | :return: the URL of a fresh bzr branch. | ||
226 | 88 | """ | 69 | """ |
227 | 89 | branch_path = self.useFixture(TempDir()).path | 70 | branch_path = self.useFixture(TempDir()).path |
235 | 90 | branch_url = 'file://' + branch_path | 71 | for name, contents in content_map.items(): |
236 | 91 | subprocess.check_call(['bzr', 'init', '-q'], cwd=branch_path) | 72 | with open(os.path.join(branch_path, name), 'wb') as f: |
237 | 92 | 73 | f.write(contents) | |
238 | 93 | if content_map is not None: | 74 | return branch_path |
239 | 94 | for name, contents in content_map.items(): | 75 | |
240 | 95 | with open(os.path.join(branch_path, name), 'wb') as f: | 76 | def make_bzr_branch(self, branch_path): |
241 | 96 | f.write(contents) | 77 | """Make a bzr branch from an existing directory.""" |
242 | 78 | bzr_home = self.useFixture(TempDir()).path | ||
243 | 79 | self.useFixture(EnvironmentVariable("BZR_HOME", bzr_home)) | ||
244 | 80 | self.useFixture(EnvironmentVariable("BZR_EMAIL")) | ||
245 | 81 | self.useFixture(EnvironmentVariable("EMAIL")) | ||
246 | 82 | |||
247 | 83 | subprocess.check_call(["bzr", "init", "-q"], cwd=branch_path) | ||
248 | 84 | subprocess.check_call(["bzr", "add", "-q"], cwd=branch_path) | ||
249 | 85 | committer_id = "Committer <committer@example.com>" | ||
250 | 86 | with EnvironmentVariable("BZR_EMAIL", committer_id): | ||
251 | 97 | subprocess.check_call( | 87 | subprocess.check_call( |
278 | 98 | ['bzr', 'add', '-q'] + list(content_map), cwd=branch_path) | 88 | ["bzr", "commit", "-q", "-m", "Populating branch."], |
279 | 99 | committer_id = 'Committer <committer@example.com>' | 89 | cwd=branch_path) |
280 | 100 | with EnvironmentVariable('BZR_EMAIL', committer_id): | 90 | |
281 | 101 | subprocess.check_call( | 91 | def make_git_branch(self, branch_path): |
282 | 102 | ['bzr', 'commit', '-q', '-m', 'Populating branch.'], | 92 | subprocess.check_call(["git", "init", "-q"], cwd=branch_path) |
283 | 103 | cwd=branch_path) | 93 | subprocess.check_call( |
284 | 104 | 94 | ["git", "config", "user.name", "Committer"], cwd=branch_path) | |
285 | 105 | return branch_url | 95 | subprocess.check_call( |
286 | 106 | 96 | ["git", "config", "user.email", "committer@example.com"], | |
287 | 107 | def test_getBranch_bzr(self): | 97 | cwd=branch_path) |
288 | 108 | # _getBranch can retrieve branch contents from a branch URL. | 98 | subprocess.check_call(["git", "add", "."], cwd=branch_path) |
289 | 109 | bzr_home = self.useFixture(TempDir()).path | 99 | subprocess.check_call( |
290 | 110 | self.useFixture(EnvironmentVariable('BZR_HOME', bzr_home)) | 100 | ["git", "commit", "-q", "--allow-empty", |
291 | 111 | self.useFixture(EnvironmentVariable('BZR_EMAIL')) | 101 | "-m", "Populating branch"], |
292 | 112 | self.useFixture(EnvironmentVariable('EMAIL')) | 102 | cwd=branch_path) |
293 | 113 | 103 | ||
294 | 114 | marker_text = "Ceci n'est pas cet branch." | 104 | def test_install_bzr(self): |
295 | 115 | branch_url = self._createBranch({'marker.txt': marker_text}) | 105 | args = [ |
296 | 116 | 106 | "generate-translation-templates", | |
297 | 117 | args = [ | 107 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
298 | 118 | "generate-translation-templates", | 108 | "--branch", "lp:foo", self.result_name, |
299 | 119 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | 109 | ] |
300 | 120 | branch_url, self.result_name, | 110 | generator = parse_args(args=args).operation |
301 | 121 | ] | 111 | generator.install() |
302 | 122 | generator = parse_args(args=args).operation | 112 | self.assertThat(generator.backend.run.calls, MatchesListwise([ |
303 | 123 | generator._getBranch() | 113 | RanAptGet("install", "intltool", "bzr"), |
304 | 114 | ])) | ||
305 | 115 | |||
306 | 116 | def test_install_git(self): | ||
307 | 117 | args = [ | ||
308 | 118 | "generate-translation-templates", | ||
309 | 119 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | ||
310 | 120 | "--git-repository", "lp:foo", self.result_name, | ||
311 | 121 | ] | ||
312 | 122 | generator = parse_args(args=args).operation | ||
313 | 123 | generator.install() | ||
314 | 124 | self.assertThat(generator.backend.run.calls, MatchesListwise([ | ||
315 | 125 | RanAptGet("install", "intltool", "git"), | ||
316 | 126 | ])) | ||
317 | 127 | |||
318 | 128 | def test_fetch_bzr(self): | ||
319 | 129 | # fetch can retrieve branch contents from a Bazaar branch. | ||
320 | 130 | marker_text = "Ceci n'est pas cet branch." | ||
321 | 131 | branch_path = self.make_branch_contents({'marker.txt': marker_text}) | ||
322 | 132 | self.make_bzr_branch(branch_path) | ||
323 | 133 | |||
324 | 134 | args = [ | ||
325 | 135 | "generate-translation-templates", | ||
326 | 136 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | ||
327 | 137 | "--branch", branch_path, self.result_name, | ||
328 | 138 | ] | ||
329 | 139 | generator = parse_args(args=args).operation | ||
330 | 140 | generator.fetch(quiet=True) | ||
331 | 141 | |||
332 | 142 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') | ||
333 | 143 | with open(marker_path) as marker_file: | ||
334 | 144 | self.assertEqual(marker_text, marker_file.read()) | ||
335 | 145 | |||
336 | 146 | def test_fetch_git(self): | ||
337 | 147 | # fetch can retrieve branch contents from a Git repository. | ||
338 | 148 | marker_text = "Ceci n'est pas cet branch." | ||
339 | 149 | branch_path = self.make_branch_contents({'marker.txt': marker_text}) | ||
340 | 150 | self.make_git_branch(branch_path) | ||
341 | 151 | |||
342 | 152 | args = [ | ||
343 | 153 | "generate-translation-templates", | ||
344 | 154 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | ||
345 | 155 | "--git-repository", branch_path, self.result_name, | ||
346 | 156 | ] | ||
347 | 157 | generator = parse_args(args=args).operation | ||
348 | 158 | generator.fetch(quiet=True) | ||
349 | 159 | |||
350 | 160 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') | ||
351 | 161 | with open(marker_path) as marker_file: | ||
352 | 162 | self.assertEqual(marker_text, marker_file.read()) | ||
353 | 163 | |||
354 | 164 | def test_fetch_git_with_path(self): | ||
355 | 165 | # fetch can retrieve branch contents from a Git repository and | ||
356 | 166 | # branch name. | ||
357 | 167 | marker_text = "Ceci n'est pas cet branch." | ||
358 | 168 | branch_path = self.make_branch_contents({'marker.txt': marker_text}) | ||
359 | 169 | self.make_git_branch(branch_path) | ||
360 | 170 | subprocess.call( | ||
361 | 171 | ["git", "branch", "-m", "master", "next"], cwd=branch_path) | ||
362 | 172 | |||
363 | 173 | args = [ | ||
364 | 174 | "generate-translation-templates", | ||
365 | 175 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | ||
366 | 176 | "--git-repository", branch_path, "--git-path", "next", | ||
367 | 177 | self.result_name, | ||
368 | 178 | ] | ||
369 | 179 | generator = parse_args(args=args).operation | ||
370 | 180 | generator.fetch(quiet=True) | ||
371 | 124 | 181 | ||
372 | 125 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') | 182 | marker_path = os.path.join(generator.branch_dir, 'marker.txt') |
373 | 126 | with open(marker_path) as marker_file: | 183 | with open(marker_path) as marker_file: |
374 | @@ -136,22 +193,23 @@ | |||
375 | 136 | potnames = [ | 193 | potnames = [ |
376 | 137 | member.name | 194 | member.name |
377 | 138 | for member in tar.getmembers() if not member.isdir()] | 195 | for member in tar.getmembers() if not member.isdir()] |
378 | 196 | self.make_bzr_branch(branchdir) | ||
379 | 139 | 197 | ||
380 | 140 | args = [ | 198 | args = [ |
381 | 141 | "generate-translation-templates", | 199 | "generate-translation-templates", |
382 | 142 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", | 200 | "--backend=uncontained", "--series=xenial", "--arch=amd64", "1", |
384 | 143 | branchdir, self.result_name, | 201 | "--branch", branchdir, self.result_name, |
385 | 144 | ] | 202 | ] |
386 | 145 | generator = parse_args(args=args).operation | 203 | generator = parse_args(args=args).operation |
388 | 146 | generator._getBranch() | 204 | generator.fetch(quiet=True) |
389 | 147 | generator._makeTarball(potnames) | 205 | generator._makeTarball(potnames) |
390 | 148 | result_path = os.path.join(self.home_dir, self.result_name) | 206 | result_path = os.path.join(self.home_dir, self.result_name) |
391 | 149 | with tarfile.open(result_path, 'r|*') as tar: | 207 | with tarfile.open(result_path, 'r|*') as tar: |
392 | 150 | tarnames = tar.getnames() | 208 | tarnames = tar.getnames() |
393 | 151 | self.assertThat(tarnames, MatchesSetwise(*(map(Equals, potnames)))) | 209 | self.assertThat(tarnames, MatchesSetwise(*(map(Equals, potnames)))) |
394 | 152 | 210 | ||
397 | 153 | def test_run(self): | 211 | def test_run_bzr(self): |
398 | 154 | # Install dependencies and generate a templates tarball. | 212 | # Install dependencies and generate a templates tarball from Bazaar. |
399 | 155 | branch_url = "lp:~my/branch" | 213 | branch_url = "lp:~my/branch" |
400 | 156 | branch_dir = os.path.join(self.home_dir, "source-tree") | 214 | branch_dir = os.path.join(self.home_dir, "source-tree") |
401 | 157 | po_dir = os.path.join(branch_dir, "po") | 215 | po_dir = os.path.join(branch_dir, "po") |
402 | @@ -160,24 +218,61 @@ | |||
403 | 160 | args = [ | 218 | args = [ |
404 | 161 | "generate-translation-templates", | 219 | "generate-translation-templates", |
405 | 162 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | 220 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
425 | 163 | branch_url, self.result_name, | 221 | "--branch", branch_url, self.result_name, |
426 | 164 | ] | 222 | ] |
427 | 165 | generator = parse_args(args=args).operation | 223 | generator = parse_args(args=args).operation |
428 | 166 | generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), "") | 224 | generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), "") |
429 | 167 | generator.backend.add_file( | 225 | generator.backend.add_file( |
430 | 168 | os.path.join(po_dir, "Makevars"), "DOMAIN = test\n") | 226 | os.path.join(po_dir, "Makevars"), "DOMAIN = test\n") |
431 | 169 | generator.run() | 227 | generator.run() |
432 | 170 | self.assertThat(generator.backend.run.calls, MatchesListwise([ | 228 | self.assertThat(generator.backend.run.calls, MatchesListwise([ |
433 | 171 | MatchesCall(["apt-get", "-y", "install", "bzr", "intltool"]), | 229 | RanAptGet("install", "intltool", "bzr"), |
434 | 172 | MatchesCall( | 230 | RanCommand( |
435 | 173 | ["bzr", "export", "-q", "-d", "lp:~my/branch", branch_dir]), | 231 | ["bzr", "branch", "lp:~my/branch", "source-tree"], |
436 | 174 | MatchesCall( | 232 | cwd=self.home_dir, LANG="C.UTF-8", SHELL="/bin/sh"), |
437 | 175 | ["rm", "-f", | 233 | RanCommand( |
438 | 176 | os.path.join(po_dir, "missing"), | 234 | ["rm", "-f", |
439 | 177 | os.path.join(po_dir, "notexist")]), | 235 | os.path.join(po_dir, "missing"), |
440 | 178 | MatchesCall(["/usr/bin/intltool-update", "-m"], cwd=po_dir), | 236 | os.path.join(po_dir, "notexist")]), |
441 | 179 | MatchesCall( | 237 | RanCommand(["/usr/bin/intltool-update", "-m"], cwd=po_dir), |
442 | 180 | ["/usr/bin/intltool-update", "-p", "-g", "test"], cwd=po_dir), | 238 | RanCommand( |
443 | 181 | MatchesCall( | 239 | ["/usr/bin/intltool-update", "-p", "-g", "test"], cwd=po_dir), |
444 | 240 | RanCommand( | ||
445 | 241 | ["tar", "-C", branch_dir, "-czf", result_path, "po/test.pot"]), | ||
446 | 242 | ])) | ||
447 | 243 | |||
448 | 244 | def test_run_git(self): | ||
449 | 245 | # Install dependencies and generate a templates tarball from Git. | ||
450 | 246 | repository_url = "lp:~my/repository" | ||
451 | 247 | branch_dir = os.path.join(self.home_dir, "source-tree") | ||
452 | 248 | po_dir = os.path.join(branch_dir, "po") | ||
453 | 249 | result_path = os.path.join(self.home_dir, self.result_name) | ||
454 | 250 | |||
455 | 251 | args = [ | ||
456 | 252 | "generate-translation-templates", | ||
457 | 253 | "--backend=fake", "--series=xenial", "--arch=amd64", "1", | ||
458 | 254 | "--git-repository", repository_url, self.result_name, | ||
459 | 255 | ] | ||
460 | 256 | generator = parse_args(args=args).operation | ||
461 | 257 | generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), "") | ||
462 | 258 | generator.backend.add_file( | ||
463 | 259 | os.path.join(po_dir, "Makevars"), "DOMAIN = test\n") | ||
464 | 260 | generator.run() | ||
465 | 261 | self.assertThat(generator.backend.run.calls, MatchesListwise([ | ||
466 | 262 | RanAptGet("install", "intltool", "git"), | ||
467 | 263 | RanCommand( | ||
468 | 264 | ["git", "clone", "lp:~my/repository", "source-tree"], | ||
469 | 265 | cwd=self.home_dir, LANG="C.UTF-8", SHELL="/bin/sh"), | ||
470 | 266 | RanCommand( | ||
471 | 267 | ["git", "submodule", "update", "--init", "--recursive"], | ||
472 | 268 | cwd=branch_dir, LANG="C.UTF-8", SHELL="/bin/sh"), | ||
473 | 269 | RanCommand( | ||
474 | 270 | ["rm", "-f", | ||
475 | 271 | os.path.join(po_dir, "missing"), | ||
476 | 272 | os.path.join(po_dir, "notexist")]), | ||
477 | 273 | RanCommand(["/usr/bin/intltool-update", "-m"], cwd=po_dir), | ||
478 | 274 | RanCommand( | ||
479 | 275 | ["/usr/bin/intltool-update", "-p", "-g", "test"], cwd=po_dir), | ||
480 | 276 | RanCommand( | ||
481 | 182 | ["tar", "-C", branch_dir, "-czf", result_path, "po/test.pot"]), | 277 | ["tar", "-C", branch_dir, "-czf", result_path, "po/test.pot"]), |
482 | 183 | ])) | 278 | ])) |
483 | 184 | 279 | ||
484 | === modified file 'lpbuildd/tests/test_translationtemplatesbuildmanager.py' | |||
485 | --- lpbuildd/tests/test_translationtemplatesbuildmanager.py 2017-09-08 15:57:18 +0000 | |||
486 | +++ lpbuildd/tests/test_translationtemplatesbuildmanager.py 2018-03-14 14:15:15 +0000 | |||
487 | @@ -82,7 +82,7 @@ | |||
488 | 82 | 'generate-translation-templates', | 82 | 'generate-translation-templates', |
489 | 83 | '--backend=chroot', '--series=xenial', '--arch=i386', | 83 | '--backend=chroot', '--series=xenial', '--arch=i386', |
490 | 84 | self.buildid, | 84 | self.buildid, |
492 | 85 | url, 'resultarchive', | 85 | '--branch', url, 'resultarchive', |
493 | 86 | ] | 86 | ] |
494 | 87 | self.assertEqual(expected_command, self.buildmanager.commands[-1]) | 87 | self.assertEqual(expected_command, self.buildmanager.commands[-1]) |
495 | 88 | self.assertEqual( | 88 | self.assertEqual( |
496 | 89 | 89 | ||
497 | === modified file 'lpbuildd/translationtemplates.py' | |||
498 | --- lpbuildd/translationtemplates.py 2017-09-08 15:57:18 +0000 | |||
499 | +++ lpbuildd/translationtemplates.py 2018-03-14 14:15:15 +0000 | |||
500 | @@ -36,16 +36,28 @@ | |||
501 | 36 | 36 | ||
502 | 37 | def initiate(self, files, chroot, extra_args): | 37 | def initiate(self, files, chroot, extra_args): |
503 | 38 | """See `BuildManager`.""" | 38 | """See `BuildManager`.""" |
505 | 39 | self._branch_url = extra_args['branch_url'] | 39 | self.branch = extra_args.get('branch') |
506 | 40 | # XXX cjwatson 2017-11-10: Backward-compatibility; remove once the | ||
507 | 41 | # manager passes branch instead. | ||
508 | 42 | if self.branch is None: | ||
509 | 43 | self.branch = extra_args['branch_url'] | ||
510 | 44 | self.git_repository = extra_args.get("git_repository") | ||
511 | 45 | self.git_path = extra_args.get("git_path") | ||
512 | 40 | 46 | ||
513 | 41 | super(TranslationTemplatesBuildManager, self).initiate( | 47 | super(TranslationTemplatesBuildManager, self).initiate( |
514 | 42 | files, chroot, extra_args) | 48 | files, chroot, extra_args) |
515 | 43 | 49 | ||
516 | 44 | def doGenerate(self): | 50 | def doGenerate(self): |
517 | 45 | """Generate templates.""" | 51 | """Generate templates.""" |
521 | 46 | self.runTargetSubProcess( | 52 | args = [] |
522 | 47 | "generate-translation-templates", | 53 | if self.branch is not None: |
523 | 48 | self._branch_url, self._resultname) | 54 | args.extend(["--branch", self.branch]) |
524 | 55 | if self.git_repository is not None: | ||
525 | 56 | args.extend(["--git-repository", self.git_repository]) | ||
526 | 57 | if self.git_path is not None: | ||
527 | 58 | args.extend(["--git-path", self.git_path]) | ||
528 | 59 | args.append(self._resultname) | ||
529 | 60 | self.runTargetSubProcess("generate-translation-templates", *args) | ||
530 | 49 | 61 | ||
531 | 50 | # Satisfy DebianPackageManager's needs without having a misleading | 62 | # Satisfy DebianPackageManager's needs without having a misleading |
532 | 51 | # method name here. | 63 | # method name here. |
Superseded by https:/ /code.launchpad .net/~cjwatson/ launchpad- buildd/ +git/launchpad- buildd/ +merge/ 383063.