Merge lp:~jelmer/bzr-builddeb/recommend-lplib into lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old
- recommend-lplib
- Merge into trunk-old
Proposed by
Jelmer Vernooij
Status: | Superseded |
---|---|
Proposed branch: | lp:~jelmer/bzr-builddeb/recommend-lplib |
Merge into: | lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~jelmer/bzr-builddeb/recommend-lplib |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Bzr-builddeb-hackers | Pending | ||
Review via email: mp+9296@code.launchpad.net |
This proposal has been superseded by a proposal from 2009-08-04.
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote : | # |
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmds.py' | |||
2 | --- cmds.py 2009-07-26 16:21:15 +0000 | |||
3 | +++ cmds.py 2009-07-26 18:21:49 +0000 | |||
4 | @@ -34,6 +34,7 @@ | |||
5 | 34 | urlutils, | 34 | urlutils, |
6 | 35 | ) | 35 | ) |
7 | 36 | from bzrlib.branch import Branch | 36 | from bzrlib.branch import Branch |
8 | 37 | from bzrlib.bzrdir import BzrDir | ||
9 | 37 | from bzrlib.commands import Command | 38 | from bzrlib.commands import Command |
10 | 38 | from bzrlib.errors import (BzrCommandError, | 39 | from bzrlib.errors import (BzrCommandError, |
11 | 39 | NoWorkingTree, | 40 | NoWorkingTree, |
12 | @@ -73,7 +74,11 @@ | |||
13 | 73 | MergeModeDistiller, | 74 | MergeModeDistiller, |
14 | 74 | NativeSourceDistiller, | 75 | NativeSourceDistiller, |
15 | 75 | ) | 76 | ) |
17 | 76 | from bzrlib.plugins.builddeb.upstream import UpstreamProvider, UpstreamBranchSource | 77 | from bzrlib.plugins.builddeb.upstream import ( |
18 | 78 | UpstreamProvider, | ||
19 | 79 | UpstreamBranchSource, | ||
20 | 80 | get_upstream_sources, | ||
21 | 81 | ) | ||
22 | 77 | from bzrlib.plugins.builddeb.util import (find_changelog, | 82 | from bzrlib.plugins.builddeb.util import (find_changelog, |
23 | 78 | get_export_upstream_revision, | 83 | get_export_upstream_revision, |
24 | 79 | find_last_distribution, | 84 | find_last_distribution, |
25 | @@ -211,12 +216,7 @@ | |||
26 | 211 | is_local = urlparse.urlsplit(location)[0] in ('', 'file') | 216 | is_local = urlparse.urlsplit(location)[0] in ('', 'file') |
27 | 212 | if is_local: | 217 | if is_local: |
28 | 213 | os.chdir(location) | 218 | os.chdir(location) |
35 | 214 | try: | 219 | tree, branch, relpath = BzrDir.open_containing_tree_or_branch(location) |
30 | 215 | tree, _ = WorkingTree.open_containing(location) | ||
31 | 216 | branch = tree.branch | ||
32 | 217 | except NoWorkingTree: | ||
33 | 218 | tree = None | ||
34 | 219 | branch, _ = Branch.open_containing(location) | ||
36 | 220 | return tree, branch, is_local | 220 | return tree, branch, is_local |
37 | 221 | 221 | ||
38 | 222 | def _get_build_tree(self, revision, tree, branch): | 222 | def _get_build_tree(self, revision, tree, branch): |
39 | @@ -375,10 +375,11 @@ | |||
40 | 375 | export_upstream_revision, config, | 375 | export_upstream_revision, config, |
41 | 376 | changelog.version) | 376 | changelog.version) |
42 | 377 | 377 | ||
44 | 378 | upstream_provider = UpstreamProvider(tree, branch, | 378 | upstream_provider = UpstreamProvider( |
45 | 379 | changelog.package, changelog.version, | 379 | changelog.package, changelog.version, |
48 | 380 | orig_dir, larstiq=larstiq, upstream_branch=upstream_branch, | 380 | orig_dir, get_upstream_sources(tree, branch, |
49 | 381 | upstream_revision=upstream_revision, allow_split=split) | 381 | larstiq=larstiq, upstream_branch=upstream_branch, |
50 | 382 | upstream_revision=upstream_revision, allow_split=split)) | ||
51 | 382 | 383 | ||
52 | 383 | if merge: | 384 | if merge: |
53 | 384 | distiller_cls = MergeModeDistiller | 385 | distiller_cls = MergeModeDistiller |
54 | @@ -392,8 +393,8 @@ | |||
55 | 392 | is_working_tree=working_tree) | 393 | is_working_tree=working_tree) |
56 | 393 | 394 | ||
57 | 394 | build_source_dir = os.path.join(build_dir, | 395 | build_source_dir = os.path.join(build_dir, |
60 | 395 | changelog.package + "-" | 396 | "%s-%s" % (changelog.package, |
61 | 396 | + changelog.version.upstream_version) | 397 | changelog.version.upstream_version)) |
62 | 397 | 398 | ||
63 | 398 | builder = DebBuild(distiller, build_source_dir, build_cmd, | 399 | builder = DebBuild(distiller, build_source_dir, build_cmd, |
64 | 399 | use_existing=use_existing) | 400 | use_existing=use_existing) |
65 | @@ -780,9 +781,9 @@ | |||
66 | 780 | orig_dir = config.orig_dir | 781 | orig_dir = config.orig_dir |
67 | 781 | if orig_dir is None: | 782 | if orig_dir is None: |
68 | 782 | orig_dir = default_orig_dir | 783 | orig_dir = default_orig_dir |
72 | 783 | upstream_provider = UpstreamProvider(t, t.branch, | 784 | upstream_provider = UpstreamProvider(changelog.package, |
73 | 784 | changelog.package, changelog.version.upstream_version, | 785 | changelog.version.upstream_version, orig_dir, |
74 | 785 | orig_dir, larstiq=larstiq) | 786 | get_upstream_sources(t, t.branch, larstiq=larstiq)) |
75 | 786 | 787 | ||
76 | 787 | distiller = MergeModeDistiller(t, upstream_provider, | 788 | distiller = MergeModeDistiller(t, upstream_provider, |
77 | 788 | larstiq=larstiq) | 789 | larstiq=larstiq) |
78 | 789 | 790 | ||
79 | === modified file 'debian/control' | |||
80 | --- debian/control 2009-03-31 14:48:29 +0000 | |||
81 | +++ debian/control 2009-07-26 18:35:25 +0000 | |||
82 | @@ -14,6 +14,7 @@ | |||
83 | 14 | Package: bzr-builddeb | 14 | Package: bzr-builddeb |
84 | 15 | Architecture: all | 15 | Architecture: all |
85 | 16 | Depends: bzr (>= 1.10~), python-debian (>= 0.1.11), python-apt, ${python:Depends}, dpkg-dev, fakeroot, bzrtools (>= 1.2), devscripts, patchutils, pristine-tar | 16 | Depends: bzr (>= 1.10~), python-debian (>= 0.1.11), python-apt, ${python:Depends}, dpkg-dev, fakeroot, bzrtools (>= 1.2), devscripts, patchutils, pristine-tar |
86 | 17 | Recommends: python-launchpadlib | ||
87 | 17 | Suggests: bzr-svn (>= 0.4.10) | 18 | Suggests: bzr-svn (>= 0.4.10) |
88 | 18 | Provides: bzr-buildpackage | 19 | Provides: bzr-buildpackage |
89 | 19 | XB-Python-Version: ${python:Versions} | 20 | XB-Python-Version: ${python:Versions} |
90 | 20 | 21 | ||
91 | === modified file 'directory.py' | |||
92 | --- directory.py 2009-04-15 23:17:50 +0000 | |||
93 | +++ directory.py 2009-04-16 10:42:12 +0000 | |||
94 | @@ -86,5 +86,15 @@ | |||
95 | 86 | else: | 86 | else: |
96 | 87 | return urls[version]["Git"] | 87 | return urls[version]["Git"] |
97 | 88 | 88 | ||
98 | 89 | if "Hg" in urls[version]: | ||
99 | 90 | try: | ||
100 | 91 | import bzrlib.plugins.hg | ||
101 | 92 | except ImportError: | ||
102 | 93 | info("This package uses hg. If you would like to " | ||
103 | 94 | "access it with bzr then please install bzr-hg" | ||
104 | 95 | "and re-run the command.") | ||
105 | 96 | else: | ||
106 | 97 | return urls[version]["Hg"] | ||
107 | 98 | |||
108 | 89 | raise errors.InvalidURL(path=url, | 99 | raise errors.InvalidURL(path=url, |
109 | 90 | extra='unsupported VCSes %r found' % urls[version].keys()) | 100 | extra='unsupported VCSes %r found' % urls[version].keys()) |
110 | 91 | 101 | ||
111 | === modified file 'errors.py' | |||
112 | --- errors.py 2009-03-02 22:36:36 +0000 | |||
113 | +++ errors.py 2009-04-16 09:30:49 +0000 | |||
114 | @@ -153,6 +153,14 @@ | |||
115 | 153 | _fmt = "You did not specify a package version." | 153 | _fmt = "You did not specify a package version." |
116 | 154 | 154 | ||
117 | 155 | 155 | ||
118 | 156 | class PackageVersionNotPresent(BzrError): | ||
119 | 157 | _fmt = "%(package)s %(version)s was not found in %(upstream)s." | ||
120 | 158 | |||
121 | 159 | def __init__(self, package, version, upstream): | ||
122 | 160 | BzrError.__init__(self, package=package, version=version, | ||
123 | 161 | upstream=upstream) | ||
124 | 162 | |||
125 | 163 | |||
126 | 156 | class UnsupportedRepackFormat(BzrError): | 164 | class UnsupportedRepackFormat(BzrError): |
127 | 157 | _fmt = ('Either the file extension of "%(location)s" indicates that ' | 165 | _fmt = ('Either the file extension of "%(location)s" indicates that ' |
128 | 158 | 'it is a format unsupported for repacking or it is a ' | 166 | 'it is a format unsupported for repacking or it is a ' |
129 | 159 | 167 | ||
130 | === modified file 'tests/test_upstream.py' | |||
131 | --- tests/test_upstream.py 2009-07-26 08:05:34 +0000 | |||
132 | +++ tests/test_upstream.py 2009-07-26 18:21:49 +0000 | |||
133 | @@ -30,12 +30,15 @@ | |||
134 | 30 | ) | 30 | ) |
135 | 31 | from bzrlib.plugins.builddeb.errors import ( | 31 | from bzrlib.plugins.builddeb.errors import ( |
136 | 32 | MissingUpstreamTarball, | 32 | MissingUpstreamTarball, |
137 | 33 | PackageVersionNotPresent, | ||
138 | 33 | ) | 34 | ) |
139 | 34 | from bzrlib.plugins.builddeb.upstream import ( | 35 | from bzrlib.plugins.builddeb.upstream import ( |
140 | 36 | AptSource, | ||
141 | 37 | PristineTarSource, | ||
142 | 38 | StackedUpstreamSource, | ||
143 | 35 | UpstreamProvider, | 39 | UpstreamProvider, |
144 | 36 | UpstreamSource, | 40 | UpstreamSource, |
147 | 37 | AptSource, | 41 | UScanSource, |
146 | 38 | PristineTarSource, | ||
148 | 39 | ) | 42 | ) |
149 | 40 | from bzrlib.plugins.builddeb.util import ( | 43 | from bzrlib.plugins.builddeb.util import ( |
150 | 41 | get_parent_dir, | 44 | get_parent_dir, |
151 | @@ -43,151 +46,6 @@ | |||
152 | 43 | ) | 46 | ) |
153 | 44 | 47 | ||
154 | 45 | 48 | ||
155 | 46 | class MockProvider(UpstreamSource): | ||
156 | 47 | |||
157 | 48 | def create_target(self, path): | ||
158 | 49 | parent_dir = get_parent_dir(path) | ||
159 | 50 | if parent_dir != '' and not os.path.exists(parent_dir): | ||
160 | 51 | os.makedirs(parent_dir) | ||
161 | 52 | f = open(path, "wb") | ||
162 | 53 | try: | ||
163 | 54 | f.write('') | ||
164 | 55 | finally: | ||
165 | 56 | f.close() | ||
166 | 57 | |||
167 | 58 | |||
168 | 59 | class MockAptProvider(MockProvider): | ||
169 | 60 | |||
170 | 61 | def __init__(self, find=False): | ||
171 | 62 | self.find = find | ||
172 | 63 | self.called_times = 0 | ||
173 | 64 | self.package = None | ||
174 | 65 | self.upstream_version = None | ||
175 | 66 | self.target_dir = None | ||
176 | 67 | |||
177 | 68 | def get_specific_version(self, package, upstream_version, target_dir): | ||
178 | 69 | self.called_times += 1 | ||
179 | 70 | self.package = package | ||
180 | 71 | self.upstream_version = upstream_version | ||
181 | 72 | self.target_dir = target_dir | ||
182 | 73 | if self.find: | ||
183 | 74 | self.create_target(os.path.join(target_dir, | ||
184 | 75 | tarball_name(package, upstream_version))) | ||
185 | 76 | return self.find | ||
186 | 77 | |||
187 | 78 | |||
188 | 79 | class MockUscanProvider(MockProvider): | ||
189 | 80 | |||
190 | 81 | def __init__(self, find=False): | ||
191 | 82 | self.find = find | ||
192 | 83 | self.called_times = 0 | ||
193 | 84 | self.package = None | ||
194 | 85 | self.upstream_version = None | ||
195 | 86 | self.watch_file_contents = None | ||
196 | 87 | self.target_dir = None | ||
197 | 88 | |||
198 | 89 | def provide(self, package, upstream_version, watch_file, target_dir): | ||
199 | 90 | self.called_times += 1 | ||
200 | 91 | self.package = package | ||
201 | 92 | self.upstream_version = upstream_version | ||
202 | 93 | f = open(watch_file, "rb") | ||
203 | 94 | try: | ||
204 | 95 | self.watch_file_contents = f.read() | ||
205 | 96 | finally: | ||
206 | 97 | f.close() | ||
207 | 98 | self.target_dir = target_dir | ||
208 | 99 | if self.find: | ||
209 | 100 | self.create_target(os.path.join(target_dir, | ||
210 | 101 | tarball_name(package, upstream_version))) | ||
211 | 102 | return self.find | ||
212 | 103 | |||
213 | 104 | |||
214 | 105 | class MockPristineProvider(MockProvider): | ||
215 | 106 | |||
216 | 107 | def __init__(self, find=False): | ||
217 | 108 | self.find = find | ||
218 | 109 | self.called_times = 0 | ||
219 | 110 | self.tree = None | ||
220 | 111 | self.branch = None | ||
221 | 112 | self.package = None | ||
222 | 113 | self.upstream_version = None | ||
223 | 114 | self.target_filename = None | ||
224 | 115 | |||
225 | 116 | def provide(self, tree, branch, package, upstream_version, target_filename): | ||
226 | 117 | self.called_times += 1 | ||
227 | 118 | self.tree = tree | ||
228 | 119 | self.branch = branch | ||
229 | 120 | self.package = package | ||
230 | 121 | self.upstream_version = upstream_version | ||
231 | 122 | self.target_filename = target_filename | ||
232 | 123 | if self.find: | ||
233 | 124 | self.create_target(target_filename) | ||
234 | 125 | return self.find | ||
235 | 126 | |||
236 | 127 | |||
237 | 128 | class MockOrigSourceProvider(MockProvider): | ||
238 | 129 | |||
239 | 130 | def __init__(self, find=False): | ||
240 | 131 | self.find = find | ||
241 | 132 | self.called_times = 0 | ||
242 | 133 | self.source_dir = None | ||
243 | 134 | self.desired_tarball_name = None | ||
244 | 135 | self.target_dir = None | ||
245 | 136 | |||
246 | 137 | def provide(self, source_dir, desired_tarball_name, | ||
247 | 138 | target_dir): | ||
248 | 139 | self.called_times += 1 | ||
249 | 140 | self.source_dir = source_dir | ||
250 | 141 | self.desired_tarball_name = desired_tarball_name | ||
251 | 142 | self.target_dir = target_dir | ||
252 | 143 | if self.find: | ||
253 | 144 | self.create_target(os.path.join(target_dir, desired_tarball_name)) | ||
254 | 145 | return self.find | ||
255 | 146 | |||
256 | 147 | |||
257 | 148 | class MockOtherBranchProvider(MockProvider): | ||
258 | 149 | |||
259 | 150 | def __init__(self, find=False): | ||
260 | 151 | self.find = find | ||
261 | 152 | self.called_times = 0 | ||
262 | 153 | self.upstream_branch = None | ||
263 | 154 | self.upstream_revision = None | ||
264 | 155 | self.target_filename = None | ||
265 | 156 | self.tarball_base = None | ||
266 | 157 | |||
267 | 158 | def provide(self, upstream_branch, upstream_revision, target_filename, | ||
268 | 159 | tarball_base): | ||
269 | 160 | self.called_times += 1 | ||
270 | 161 | self.upstream_branch = upstream_branch | ||
271 | 162 | self.upstream_revision = upstream_revision | ||
272 | 163 | self.target_filename = target_filename | ||
273 | 164 | self.tarball_base = tarball_base | ||
274 | 165 | if self.find: | ||
275 | 166 | self.create_target(target_filename) | ||
276 | 167 | return self.find | ||
277 | 168 | |||
278 | 169 | |||
279 | 170 | class MockSplitProvider(MockProvider): | ||
280 | 171 | |||
281 | 172 | def __init__(self, find=False): | ||
282 | 173 | self.find = find | ||
283 | 174 | self.called_times = 0 | ||
284 | 175 | self.tree = None | ||
285 | 176 | self.package = None | ||
286 | 177 | self.upstream_version = None | ||
287 | 178 | self.target_filename = None | ||
288 | 179 | |||
289 | 180 | def provide(self, tree, package, upstream_version, target_filename): | ||
290 | 181 | self.called_times += 1 | ||
291 | 182 | self.tree = tree | ||
292 | 183 | self.package = package | ||
293 | 184 | self.upstream_version = upstream_version | ||
294 | 185 | self.target_filename = target_filename | ||
295 | 186 | if self.find: | ||
296 | 187 | self.create_target(self.target_filename) | ||
297 | 188 | return self.find | ||
298 | 189 | |||
299 | 190 | |||
300 | 191 | class MockSources(object): | 49 | class MockSources(object): |
301 | 192 | 50 | ||
302 | 193 | def __init__(self, versions): | 51 | def __init__(self, versions): |
303 | @@ -227,202 +85,6 @@ | |||
304 | 227 | return self.sources | 85 | return self.sources |
305 | 228 | 86 | ||
306 | 229 | 87 | ||
307 | 230 | class UpstreamProviderTests(TestCaseWithTransport): | ||
308 | 231 | |||
309 | 232 | def setUp(self): | ||
310 | 233 | super(UpstreamProviderTests, self).setUp() | ||
311 | 234 | self.tree = self.make_branch_and_tree(".") | ||
312 | 235 | self.branch = self.tree.branch | ||
313 | 236 | self.package = "package" | ||
314 | 237 | self.version = Version("0.1-1") | ||
315 | 238 | self.upstream_version = self.version.upstream_version | ||
316 | 239 | self.desired_tarball_name = tarball_name(self.package, | ||
317 | 240 | self.upstream_version) | ||
318 | 241 | self.tarball_base = "%s-%s" % (self.package, self.upstream_version) | ||
319 | 242 | self.store_dir = "store" | ||
320 | 243 | self.provider = UpstreamProvider(self.tree, self.branch, | ||
321 | 244 | self.package, self.version, self.store_dir) | ||
322 | 245 | self.provider._sources = [] | ||
323 | 246 | self.providers = {} | ||
324 | 247 | self.providers["apt"] = MockAptProvider() | ||
325 | 248 | self.provider._sources.append(self.providers["apt"]) | ||
326 | 249 | self.providers["uscan"] = MockUscanProvider() | ||
327 | 250 | self.provider._sources.append(self.providers["uscan"]) | ||
328 | 251 | self.providers["pristine"] = MockPristineProvider() | ||
329 | 252 | self.provider._sources.append(self.providers["pristine"]) | ||
330 | 253 | self.providers["orig"] = MockOrigSourceProvider() | ||
331 | 254 | self.provider._sources.append(self.providers["orig"]) | ||
332 | 255 | self.providers["upstream"] = MockOtherBranchProvider() | ||
333 | 256 | self.provider._sources.append(self.providers["upstream"]) | ||
334 | 257 | self.provider._upstream_branch_provider = \ | ||
335 | 258 | self.providers["upstream"].provide | ||
336 | 259 | self.providers["split"] = MockSplitProvider() | ||
337 | 260 | self.provider._sources.append(self.providers["split"]) | ||
338 | 261 | self.target_dir = "target" | ||
339 | 262 | self.target_filename = os.path.join(self.target_dir, | ||
340 | 263 | self.desired_tarball_name) | ||
341 | 264 | self.store_filename = os.path.join(self.store_dir, | ||
342 | 265 | tarball_name(self.package, self.version.upstream_version)) | ||
343 | 266 | |||
344 | 267 | def assertProvidersCalled(self, providers): | ||
345 | 268 | for provider_name, provider in self.providers.items(): | ||
346 | 269 | if provider_name in providers: | ||
347 | 270 | self.assertCalledCorrectly(provider_name) | ||
348 | 271 | else: | ||
349 | 272 | self.assertEqual(provider.called_times, 0, | ||
350 | 273 | "%s wasn't expected to be called" % provider_name) | ||
351 | 274 | |||
352 | 275 | def call_provider(self): | ||
353 | 276 | self.assertEqual(self.provider.provide(self.target_dir), | ||
354 | 277 | self.target_filename) | ||
355 | 278 | |||
356 | 279 | def test_already_in_target(self): | ||
357 | 280 | os.makedirs(self.target_dir) | ||
358 | 281 | f = open(self.target_filename, "wb") | ||
359 | 282 | f.close() | ||
360 | 283 | self.call_provider() | ||
361 | 284 | self.failUnlessExists(self.target_filename) | ||
362 | 285 | # Should this be copied across? | ||
363 | 286 | self.failIfExists(self.store_filename) | ||
364 | 287 | self.assertProvidersCalled({}) | ||
365 | 288 | |||
366 | 289 | def test_already_in_store(self): | ||
367 | 290 | os.makedirs(self.store_dir) | ||
368 | 291 | f = open(self.store_filename, "wb") | ||
369 | 292 | f.close() | ||
370 | 293 | self.call_provider() | ||
371 | 294 | self.failUnlessExists(self.target_filename) | ||
372 | 295 | self.failUnlessExists(self.store_filename) | ||
373 | 296 | self.assertProvidersCalled({}) | ||
374 | 297 | |||
375 | 298 | def assertCalledCorrectly(self, provider_name): | ||
376 | 299 | provider = self.providers[provider_name] | ||
377 | 300 | for attr_name in provider.__dict__: | ||
378 | 301 | if attr_name in ("find", "provide", "source_dir"): | ||
379 | 302 | continue | ||
380 | 303 | if attr_name == "called_times": | ||
381 | 304 | self.assertEqual(provider.called_times, 1, | ||
382 | 305 | "%s was not called" % provider_name) | ||
383 | 306 | continue | ||
384 | 307 | if attr_name == "target_filename": | ||
385 | 308 | self.assertEqual(provider.target_filename, | ||
386 | 309 | self.store_filename) | ||
387 | 310 | continue | ||
388 | 311 | if attr_name == "target_dir": | ||
389 | 312 | self.assertEqual(provider.target_dir, | ||
390 | 313 | self.store_dir) | ||
391 | 314 | continue | ||
392 | 315 | if attr_name == "fetch_dir": | ||
393 | 316 | self.assertEqual(provider.fetch_dir, | ||
394 | 317 | os.path.dirname(provider.source_dir)) | ||
395 | 318 | continue | ||
396 | 319 | attr = getattr(provider, attr_name) | ||
397 | 320 | correct_attr = getattr(self, attr_name) | ||
398 | 321 | self.assertEqual(correct_attr, attr, | ||
399 | 322 | "%s doesn't match\nexpected: %s\ngot: %s" | ||
400 | 323 | % (attr_name, correct_attr, attr)) | ||
401 | 324 | |||
402 | 325 | def assertSuccesfulCall(self, provider, other_providers): | ||
403 | 326 | self.providers[provider].find = True | ||
404 | 327 | self.call_provider() | ||
405 | 328 | self.failUnlessExists(self.target_filename) | ||
406 | 329 | self.failUnlessExists(self.store_filename) | ||
407 | 330 | self.assertProvidersCalled([provider] + other_providers) | ||
408 | 331 | |||
409 | 332 | def test_from_pristine_tar(self): | ||
410 | 333 | self.assertSuccesfulCall("pristine", []) | ||
411 | 334 | |||
412 | 335 | def test_from_apt(self): | ||
413 | 336 | self.assertSuccesfulCall("apt", ["pristine"]) | ||
414 | 337 | |||
415 | 338 | def test_from_uscan(self): | ||
416 | 339 | self.build_tree(["watch", "debian/", "debian/watch"]) | ||
417 | 340 | self.tree.add(["watch", "debian/", "debian/watch"]) | ||
418 | 341 | self.watch_file_contents = "contents of debian/watch\n" | ||
419 | 342 | self.assertSuccesfulCall("uscan", ["pristine", "apt"]) | ||
420 | 343 | |||
421 | 344 | def test_uscan_not_called_if_not_watch(self): | ||
422 | 345 | self.build_tree(["watch"]) | ||
423 | 346 | self.tree.add(["watch"]) | ||
424 | 347 | self.assertRaises(MissingUpstreamTarball, self.provider.provide, | ||
425 | 348 | self.target_dir) | ||
426 | 349 | self.failIfExists(self.target_filename) | ||
427 | 350 | self.failIfExists(self.store_filename) | ||
428 | 351 | self.assertProvidersCalled(["pristine", "apt"]) | ||
429 | 352 | |||
430 | 353 | def test_uscan_in_larstiq(self): | ||
431 | 354 | self.build_tree(["watch", "debian/", "debian/watch"]) | ||
432 | 355 | self.tree.add(["watch", "debian/", "debian/watch"]) | ||
433 | 356 | self.watch_file_contents = "contents of watch\n" | ||
434 | 357 | self.provider.larstiq = True | ||
435 | 358 | self.assertSuccesfulCall("uscan", ["pristine", "apt"]) | ||
436 | 359 | |||
437 | 360 | def test_from_get_orig_source(self): | ||
438 | 361 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
439 | 362 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
440 | 363 | self.watch_file_contents = "contents of debian/rules\n" | ||
441 | 364 | self.assertSuccesfulCall("orig", ["pristine", "apt"]) | ||
442 | 365 | |||
443 | 366 | def test_get_orig_source_not_called_if_no_rules(self): | ||
444 | 367 | self.build_tree(["rules"]) | ||
445 | 368 | self.tree.add(["rules"]) | ||
446 | 369 | self.assertRaises(MissingUpstreamTarball, self.provider.provide, | ||
447 | 370 | self.target_dir) | ||
448 | 371 | self.failIfExists(self.target_filename) | ||
449 | 372 | self.failIfExists(self.store_filename) | ||
450 | 373 | self.assertProvidersCalled(["pristine", "apt"]) | ||
451 | 374 | |||
452 | 375 | def test_get_orig_source_in_larstiq(self): | ||
453 | 376 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
454 | 377 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
455 | 378 | self.watch_file_contents = "contents of rules\n" | ||
456 | 379 | self.provider.larstiq = True | ||
457 | 380 | self.assertSuccesfulCall("orig", ["pristine", "apt"]) | ||
458 | 381 | |||
459 | 382 | def test_from_upstream_branch(self): | ||
460 | 383 | upstream_tree = self.make_branch_and_tree("upstream") | ||
461 | 384 | self.build_tree(["upstream/foo"]) | ||
462 | 385 | upstream_tree.add(["foo"]) | ||
463 | 386 | self.upstream_branch = upstream_tree.branch | ||
464 | 387 | self.upstream_revision = upstream_tree.commit("upstream one") | ||
465 | 388 | self.provider.upstream_revision = self.upstream_revision | ||
466 | 389 | self.provider.upstream_branch = self.upstream_branch | ||
467 | 390 | self.assertSuccesfulCall("upstream", ["pristine", "apt"]) | ||
468 | 391 | |||
469 | 392 | def test_from_split(self): | ||
470 | 393 | self.provider.allow_split = True | ||
471 | 394 | self.assertSuccesfulCall("split", ["pristine", "apt"]) | ||
472 | 395 | |||
473 | 396 | def test_upstream_before_orig_source(self): | ||
474 | 397 | upstream_tree = self.make_branch_and_tree("upstream") | ||
475 | 398 | self.build_tree(["upstream/foo"]) | ||
476 | 399 | upstream_tree.add(["foo"]) | ||
477 | 400 | self.upstream_branch = upstream_tree.branch | ||
478 | 401 | self.upstream_revision = upstream_tree.commit("upstream one") | ||
479 | 402 | self.provider.upstream_revision = self.upstream_revision | ||
480 | 403 | self.provider.upstream_branch = self.upstream_branch | ||
481 | 404 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
482 | 405 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
483 | 406 | self.watch_file_contents = "contents of debian/rules\n" | ||
484 | 407 | self.assertSuccesfulCall("upstream", ["pristine", "apt"]) | ||
485 | 408 | |||
486 | 409 | def test_get_orig_source_before_uscan(self): | ||
487 | 410 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
488 | 411 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
489 | 412 | self.watch_file_contents = "contents of debian/rules\n" | ||
490 | 413 | self.build_tree(["watch", "debian/watch"]) | ||
491 | 414 | self.tree.add(["watch", "debian/watch"]) | ||
492 | 415 | self.watch_file_contents = "contents of debian/watch\n" | ||
493 | 416 | self.assertSuccesfulCall("orig", ["pristine", "apt"]) | ||
494 | 417 | |||
495 | 418 | def test_uscan_before_split(self): | ||
496 | 419 | self.build_tree(["watch", "debian/", "debian/watch"]) | ||
497 | 420 | self.tree.add(["watch", "debian/", "debian/watch"]) | ||
498 | 421 | self.watch_file_contents = "contents of debian/watch\n" | ||
499 | 422 | self.provider.allow_split = True | ||
500 | 423 | self.assertSuccesfulCall("uscan", ["pristine", "apt"]) | ||
501 | 424 | |||
502 | 425 | |||
503 | 426 | class MockAptCaller(object): | 88 | class MockAptCaller(object): |
504 | 427 | 89 | ||
505 | 428 | def __init__(self, work=False): | 90 | def __init__(self, work=False): |
506 | @@ -451,8 +113,10 @@ | |||
507 | 451 | caller = MockAptCaller() | 113 | caller = MockAptCaller() |
508 | 452 | sources = MockSources([]) | 114 | sources = MockSources([]) |
509 | 453 | apt_pkg = MockAptPkg(sources) | 115 | apt_pkg = MockAptPkg(sources) |
512 | 454 | self.assertEqual(False, AptSource().get_specific_version( | 116 | src = AptSource() |
513 | 455 | "apackage", "0.2", "target", _apt_pkg=apt_pkg, _apt_caller=caller)) | 117 | src._run_apt_source = caller.call |
514 | 118 | self.assertRaises(PackageVersionNotPresent, src.get_specific_version, | ||
515 | 119 | "apackage", "0.2", "target", _apt_pkg=apt_pkg) | ||
516 | 456 | self.assertEqual(1, apt_pkg.init_called_times) | 120 | self.assertEqual(1, apt_pkg.init_called_times) |
517 | 457 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 121 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
518 | 458 | self.assertEqual(1, sources.restart_called_times) | 122 | self.assertEqual(1, sources.restart_called_times) |
519 | @@ -464,8 +128,10 @@ | |||
520 | 464 | caller = MockAptCaller() | 128 | caller = MockAptCaller() |
521 | 465 | sources = MockSources(["0.1-1"]) | 129 | sources = MockSources(["0.1-1"]) |
522 | 466 | apt_pkg = MockAptPkg(sources) | 130 | apt_pkg = MockAptPkg(sources) |
525 | 467 | self.assertEqual(False, AptSource().get_specific_version( | 131 | src = AptSource() |
526 | 468 | "apackage", "0.2", "target", _apt_pkg=apt_pkg, _apt_caller=caller)) | 132 | src._run_apt_source = caller.call |
527 | 133 | self.assertRaises(PackageVersionNotPresent, src.get_specific_version, | ||
528 | 134 | "apackage", "0.2", "target", _apt_pkg=apt_pkg) | ||
529 | 469 | self.assertEqual(1, apt_pkg.init_called_times) | 135 | self.assertEqual(1, apt_pkg.init_called_times) |
530 | 470 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 136 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
531 | 471 | self.assertEqual(1, sources.restart_called_times) | 137 | self.assertEqual(1, sources.restart_called_times) |
532 | @@ -477,9 +143,10 @@ | |||
533 | 477 | caller = MockAptCaller(work=True) | 143 | caller = MockAptCaller(work=True) |
534 | 478 | sources = MockSources(["0.1-1", "0.2-1"]) | 144 | sources = MockSources(["0.1-1", "0.2-1"]) |
535 | 479 | apt_pkg = MockAptPkg(sources) | 145 | apt_pkg = MockAptPkg(sources) |
539 | 480 | self.assertEqual(True, AptSource().get_specific_version( | 146 | src = AptSource() |
540 | 481 | "apackage", "0.2", "target", | 147 | src._run_apt_source = caller.call |
541 | 482 | _apt_pkg=apt_pkg, _apt_caller=caller.call)) | 148 | src.get_specific_version("apackage", "0.2", "target", |
542 | 149 | _apt_pkg=apt_pkg) | ||
543 | 483 | self.assertEqual(1, apt_pkg.init_called_times) | 150 | self.assertEqual(1, apt_pkg.init_called_times) |
544 | 484 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 151 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
545 | 485 | self.assertEqual(1, sources.restart_called_times) | 152 | self.assertEqual(1, sources.restart_called_times) |
546 | @@ -495,9 +162,11 @@ | |||
547 | 495 | caller = MockAptCaller() | 162 | caller = MockAptCaller() |
548 | 496 | sources = MockSources(["0.1-1", "0.2-1"]) | 163 | sources = MockSources(["0.1-1", "0.2-1"]) |
549 | 497 | apt_pkg = MockAptPkg(sources) | 164 | apt_pkg = MockAptPkg(sources) |
551 | 498 | self.assertEqual(False, AptSource().get_specific_version( | 165 | src = AptSource() |
552 | 166 | src._run_apt_source = caller.call | ||
553 | 167 | self.assertRaises(PackageVersionNotPresent, src.get_specific_version, | ||
554 | 499 | "apackage", "0.2", "target", | 168 | "apackage", "0.2", "target", |
556 | 500 | _apt_pkg=apt_pkg, _apt_caller=caller.call)) | 169 | _apt_pkg=apt_pkg) |
557 | 501 | self.assertEqual(1, apt_pkg.init_called_times) | 170 | self.assertEqual(1, apt_pkg.init_called_times) |
558 | 502 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 171 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
559 | 503 | self.assertEqual(1, sources.restart_called_times) | 172 | self.assertEqual(1, sources.restart_called_times) |
560 | @@ -508,3 +177,71 @@ | |||
561 | 508 | self.assertEqual("apackage", caller.package) | 177 | self.assertEqual("apackage", caller.package) |
562 | 509 | self.assertEqual("0.2-1", caller.version_str) | 178 | self.assertEqual("0.2-1", caller.version_str) |
563 | 510 | self.assertEqual("target", caller.target_dir) | 179 | self.assertEqual("target", caller.target_dir) |
564 | 180 | |||
565 | 181 | |||
566 | 182 | class RecordingSource(object): | ||
567 | 183 | |||
568 | 184 | def __init__(self, succeed): | ||
569 | 185 | self._succeed = succeed | ||
570 | 186 | self._specific_versions = [] | ||
571 | 187 | |||
572 | 188 | def get_specific_version(self, package, version, target_dir): | ||
573 | 189 | self._specific_versions.append((package, version, target_dir)) | ||
574 | 190 | if not self._succeed: | ||
575 | 191 | raise PackageVersionNotPresent(package, version, self) | ||
576 | 192 | |||
577 | 193 | def __repr__(self): | ||
578 | 194 | return "%s()" % self.__class__.__name__ | ||
579 | 195 | |||
580 | 196 | |||
581 | 197 | class StackedUpstreamSourceTests(TestCase): | ||
582 | 198 | |||
583 | 199 | def test_first_wins(self): | ||
584 | 200 | a = RecordingSource(False) | ||
585 | 201 | b = RecordingSource(True) | ||
586 | 202 | c = RecordingSource(False) | ||
587 | 203 | stack = StackedUpstreamSource([a, b, c]) | ||
588 | 204 | stack.get_specific_version("mypkg", "1.0", "bla") | ||
589 | 205 | self.assertEquals([("mypkg", "1.0", "bla")], b._specific_versions) | ||
590 | 206 | self.assertEquals([("mypkg", "1.0", "bla")], a._specific_versions) | ||
591 | 207 | self.assertEquals([], c._specific_versions) | ||
592 | 208 | |||
593 | 209 | def test_repr(self): | ||
594 | 210 | self.assertEquals("StackedUpstreamSource([])", | ||
595 | 211 | repr(StackedUpstreamSource([]))) | ||
596 | 212 | self.assertEquals("StackedUpstreamSource([RecordingSource()])", | ||
597 | 213 | repr(StackedUpstreamSource([RecordingSource(False)]))) | ||
598 | 214 | |||
599 | 215 | def test_none(self): | ||
600 | 216 | a = RecordingSource(False) | ||
601 | 217 | b = RecordingSource(False) | ||
602 | 218 | stack = StackedUpstreamSource([a, b]) | ||
603 | 219 | self.assertRaises(PackageVersionNotPresent, | ||
604 | 220 | stack.get_specific_version, "pkg", "1.0", "bla") | ||
605 | 221 | self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions) | ||
606 | 222 | self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions) | ||
607 | 223 | |||
608 | 224 | |||
609 | 225 | class UScanSourceTests(TestCaseWithTransport): | ||
610 | 226 | |||
611 | 227 | def setUp(self): | ||
612 | 228 | super(UScanSourceTests, self).setUp() | ||
613 | 229 | self.tree = self.make_branch_and_tree('.') | ||
614 | 230 | |||
615 | 231 | def test_export_watchfile_none(self): | ||
616 | 232 | src = UScanSource(self.tree, False) | ||
617 | 233 | self.assertEquals(None, src._export_watchfile()) | ||
618 | 234 | |||
619 | 235 | def test_export_watchfile_larstiq(self): | ||
620 | 236 | src = UScanSource(self.tree, True) | ||
621 | 237 | self.build_tree(['watch']) | ||
622 | 238 | self.assertEquals(None, src._export_watchfile()) | ||
623 | 239 | self.tree.add(['watch']) | ||
624 | 240 | self.assertTrue(src._export_watchfile() is not None) | ||
625 | 241 | |||
626 | 242 | def test_export_watchfile(self): | ||
627 | 243 | src = UScanSource(self.tree, False) | ||
628 | 244 | self.build_tree(['debian/', 'debian/watch']) | ||
629 | 245 | self.assertEquals(None, src._export_watchfile()) | ||
630 | 246 | self.tree.smart_add(['debian/watch']) | ||
631 | 247 | self.assertTrue(src._export_watchfile() is not None) | ||
632 | 511 | 248 | ||
633 | === modified file 'upstream.py' | |||
634 | --- upstream.py 2009-07-26 08:05:34 +0000 | |||
635 | +++ upstream.py 2009-07-26 18:21:49 +0000 | |||
636 | @@ -1,5 +1,6 @@ | |||
637 | 1 | # upstream.py -- Providers of upstream source | 1 | # upstream.py -- Providers of upstream source |
638 | 2 | # Copyright (C) 2009 Canonical Ltd. | 2 | # Copyright (C) 2009 Canonical Ltd. |
639 | 3 | # Copyright (C) 2009 Jelmer Vernooij <jelmer@debian.org> | ||
640 | 3 | # | 4 | # |
641 | 4 | # This file is part of bzr-builddeb. | 5 | # This file is part of bzr-builddeb. |
642 | 5 | # | 6 | # |
643 | @@ -29,7 +30,10 @@ | |||
644 | 29 | from bzrlib.revisionspec import RevisionSpec | 30 | from bzrlib.revisionspec import RevisionSpec |
645 | 30 | from bzrlib.trace import info | 31 | from bzrlib.trace import info |
646 | 31 | 32 | ||
648 | 32 | from bzrlib.plugins.builddeb.errors import MissingUpstreamTarball | 33 | from bzrlib.plugins.builddeb.errors import ( |
649 | 34 | MissingUpstreamTarball, | ||
650 | 35 | PackageVersionNotPresent, | ||
651 | 36 | ) | ||
652 | 33 | from bzrlib.plugins.builddeb.import_dsc import DistributionBranch | 37 | from bzrlib.plugins.builddeb.import_dsc import DistributionBranch |
653 | 34 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball | 38 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball |
654 | 35 | from bzrlib.plugins.builddeb.util import ( | 39 | from bzrlib.plugins.builddeb.util import ( |
655 | @@ -55,7 +59,6 @@ | |||
656 | 55 | :param package: Name of the package | 59 | :param package: Name of the package |
657 | 56 | :param version: Version string of the version to fetch | 60 | :param version: Version string of the version to fetch |
658 | 57 | :param target_dir: Directory in which to store the tarball | 61 | :param target_dir: Directory in which to store the tarball |
659 | 58 | :return: Boolean indicating whether a tarball was fetched | ||
660 | 59 | """ | 62 | """ |
661 | 60 | raise NotImplemented(self.get_specific_version) | 63 | raise NotImplemented(self.get_specific_version) |
662 | 61 | 64 | ||
663 | @@ -70,32 +73,28 @@ | |||
664 | 70 | self.branch = branch | 73 | self.branch = branch |
665 | 71 | self.tree = tree | 74 | self.tree = tree |
666 | 72 | 75 | ||
669 | 73 | def get_specific_version(self, package, upstream_version, target_dir): | 76 | def get_specific_version(self, package, version, target_dir): |
670 | 74 | target_filename = self._tarball_path(package, upstream_version, | 77 | target_filename = self._tarball_path(package, version, |
671 | 75 | target_dir) | 78 | target_dir) |
672 | 76 | db = DistributionBranch(self.branch, None, tree=self.tree) | 79 | db = DistributionBranch(self.branch, None, tree=self.tree) |
676 | 77 | if not db.has_upstream_version_in_packaging_branch(upstream_version): | 80 | if not db.has_upstream_version_in_packaging_branch(version): |
677 | 78 | return False | 81 | raise PackageVersionNotPresent(package, version, self) |
678 | 79 | revid = db._revid_of_upstream_version_from_branch(upstream_version) | 82 | revid = db._revid_of_upstream_version_from_branch(version) |
679 | 80 | if not db.has_pristine_tar_delta(revid): | 83 | if not db.has_pristine_tar_delta(revid): |
681 | 81 | return False | 84 | raise PackageVersionNotPresent(package, version, self) |
682 | 82 | info("Using pristine-tar to reconstruct the needed tarball.") | 85 | info("Using pristine-tar to reconstruct the needed tarball.") |
686 | 83 | db.reconstruct_pristine_tar(revid, package, upstream_version, | 86 | db.reconstruct_pristine_tar(revid, package, version, target_filename) |
684 | 84 | target_filename) | ||
685 | 85 | return True | ||
687 | 86 | 87 | ||
688 | 87 | 88 | ||
689 | 88 | class AptSource(UpstreamSource): | 89 | class AptSource(UpstreamSource): |
690 | 89 | """Upstream source that uses apt-source.""" | 90 | """Upstream source that uses apt-source.""" |
691 | 90 | 91 | ||
692 | 91 | def get_specific_version(self, package, upstream_version, target_dir, | 92 | def get_specific_version(self, package, upstream_version, target_dir, |
694 | 92 | _apt_pkg=None, _apt_caller=None): | 93 | _apt_pkg=None): |
695 | 93 | if _apt_pkg is None: | 94 | if _apt_pkg is None: |
696 | 94 | import apt_pkg | 95 | import apt_pkg |
697 | 95 | else: | 96 | else: |
698 | 96 | apt_pkg = _apt_pkg | 97 | apt_pkg = _apt_pkg |
699 | 97 | if _apt_caller is None: | ||
700 | 98 | _apt_caller = self._run_apt_source | ||
701 | 99 | apt_pkg.init() | 98 | apt_pkg.init() |
702 | 100 | sources = apt_pkg.GetPkgSrcRecords() | 99 | sources = apt_pkg.GetPkgSrcRecords() |
703 | 101 | sources.Restart() | 100 | sources.Restart() |
704 | @@ -103,11 +102,11 @@ | |||
705 | 103 | while sources.Lookup(package): | 102 | while sources.Lookup(package): |
706 | 104 | if upstream_version \ | 103 | if upstream_version \ |
707 | 105 | == Version(sources.Version).upstream_version: | 104 | == Version(sources.Version).upstream_version: |
710 | 106 | if _apt_caller(package, sources.Version, target_dir): | 105 | if self._run_apt_source(package, sources.Version, target_dir): |
711 | 107 | return True | 106 | return |
712 | 108 | break | 107 | break |
713 | 109 | info("apt could not find the needed tarball.") | 108 | info("apt could not find the needed tarball.") |
715 | 110 | return False | 109 | raise PackageVersionNotPresent(package, upstream_version, self) |
716 | 111 | 110 | ||
717 | 112 | def _get_command(self, package, version_str): | 111 | def _get_command(self, package, version_str): |
718 | 113 | return 'apt-get source -y --only-source --tar-only %s=%s' % \ | 112 | return 'apt-get source -y --only-source --tar-only %s=%s' % \ |
719 | @@ -153,7 +152,6 @@ | |||
720 | 153 | tarball_base = "%s-%s" % (package, version) | 152 | tarball_base = "%s-%s" % (package, version) |
721 | 154 | rev_tree = self.upstream_branch.repository.revision_tree(revid) | 153 | rev_tree = self.upstream_branch.repository.revision_tree(revid) |
722 | 155 | export(rev_tree, target_filename, 'tgz', tarball_base) | 154 | export(rev_tree, target_filename, 'tgz', tarball_base) |
723 | 156 | return True | ||
724 | 157 | finally: | 155 | finally: |
725 | 158 | self.upstream_branch.unlock() | 156 | self.upstream_branch.unlock() |
726 | 159 | 157 | ||
727 | @@ -198,13 +196,14 @@ | |||
728 | 198 | os.mkdir(export_dir) | 196 | os.mkdir(export_dir) |
729 | 199 | export_dir = os.path.join(export_dir, "debian") | 197 | export_dir = os.path.join(export_dir, "debian") |
730 | 200 | export(self.tree, export_dir, format="dir") | 198 | export(self.tree, export_dir, format="dir") |
733 | 201 | return self._get_orig_source(base_export_dir, | 199 | if not self._get_orig_source(base_export_dir, |
734 | 202 | desired_tarball_name, target_dir) | 200 | desired_tarball_name, target_dir): |
735 | 201 | raise PackageVersionNotPresent(package, version, self) | ||
736 | 202 | return | ||
737 | 203 | finally: | 203 | finally: |
738 | 204 | shutil.rmtree(tmpdir) | 204 | shutil.rmtree(tmpdir) |
742 | 205 | info("No debian/rules file to try and use for a get-orig-source " | 205 | info("No debian/rules file to try and use for a get-orig-source rule") |
743 | 206 | "rule") | 206 | raise PackageVersionNotPresent(package, version, self) |
741 | 207 | return False | ||
744 | 208 | 207 | ||
745 | 209 | 208 | ||
746 | 210 | class UScanSource(UpstreamSource): | 209 | class UScanSource(UpstreamSource): |
747 | @@ -226,7 +225,7 @@ | |||
748 | 226 | return False | 225 | return False |
749 | 227 | return True | 226 | return True |
750 | 228 | 227 | ||
752 | 229 | def get_specific_version(self, package, version, target_dir): | 228 | def _export_watchfile(self): |
753 | 230 | if self.larstiq: | 229 | if self.larstiq: |
754 | 231 | watchfile = 'watch' | 230 | watchfile = 'watch' |
755 | 232 | else: | 231 | else: |
756 | @@ -234,7 +233,7 @@ | |||
757 | 234 | watch_id = self.tree.path2id(watchfile) | 233 | watch_id = self.tree.path2id(watchfile) |
758 | 235 | if watch_id is None: | 234 | if watch_id is None: |
759 | 236 | info("No watch file to use to retrieve upstream tarball.") | 235 | info("No watch file to use to retrieve upstream tarball.") |
761 | 237 | return False | 236 | return None |
762 | 238 | (tmp, tempfilename) = tempfile.mkstemp() | 237 | (tmp, tempfilename) = tempfile.mkstemp() |
763 | 239 | try: | 238 | try: |
764 | 240 | tmp = os.fdopen(tmp, 'wb') | 239 | tmp = os.fdopen(tmp, 'wb') |
765 | @@ -242,9 +241,16 @@ | |||
766 | 242 | tmp.write(watch) | 241 | tmp.write(watch) |
767 | 243 | finally: | 242 | finally: |
768 | 244 | tmp.close() | 243 | tmp.close() |
769 | 244 | return tempfilename | ||
770 | 245 | |||
771 | 246 | def get_specific_version(self, package, version, target_dir): | ||
772 | 247 | tempfilename = self._export_watchfile() | ||
773 | 248 | if tempfilename is None: | ||
774 | 249 | raise PackageVersionNotPresent(package, version, self) | ||
775 | 245 | try: | 250 | try: |
778 | 246 | return self._uscan(package, version, tempfilename, | 251 | if not self._uscan(package, version, tempfilename, |
779 | 247 | target_dir) | 252 | target_dir): |
780 | 253 | raise PackageVersionNotPresent(package, version, self) | ||
781 | 248 | finally: | 254 | finally: |
782 | 249 | os.unlink(tempfilename) | 255 | os.unlink(tempfilename) |
783 | 250 | 256 | ||
784 | @@ -266,15 +272,14 @@ | |||
785 | 266 | tar.add(export_dir, "%s-%s" % (package, upstream_version)) | 272 | tar.add(export_dir, "%s-%s" % (package, upstream_version)) |
786 | 267 | finally: | 273 | finally: |
787 | 268 | tar.close() | 274 | tar.close() |
788 | 269 | return True | ||
789 | 270 | finally: | 275 | finally: |
790 | 271 | shutil.rmtree(tmpdir) | 276 | shutil.rmtree(tmpdir) |
791 | 272 | 277 | ||
792 | 273 | def get_specific_version(self, package, version, target_dir): | 278 | def get_specific_version(self, package, version, target_dir): |
793 | 274 | info("Using the current branch without the 'debian' directory " | 279 | info("Using the current branch without the 'debian' directory " |
794 | 275 | "to create the tarball") | 280 | "to create the tarball") |
797 | 276 | return self._split(package, | 281 | self._split(package, version, |
798 | 277 | version, self._tarball_path(package, version, target_dir)) | 282 | self._tarball_path(package, version, target_dir)) |
799 | 278 | 283 | ||
800 | 279 | 284 | ||
801 | 280 | class StackedUpstreamSource(UpstreamSource): | 285 | class StackedUpstreamSource(UpstreamSource): |
802 | @@ -286,11 +291,47 @@ | |||
803 | 286 | def __init__(self, sources): | 291 | def __init__(self, sources): |
804 | 287 | self._sources = sources | 292 | self._sources = sources |
805 | 288 | 293 | ||
806 | 294 | def __repr__(self): | ||
807 | 295 | return "%s(%r)" % (self.__class__.__name__, self._sources) | ||
808 | 296 | |||
809 | 289 | def get_specific_version(self, package, version, target_dir): | 297 | def get_specific_version(self, package, version, target_dir): |
810 | 290 | for source in self._sources: | 298 | for source in self._sources: |
814 | 291 | if source.get_specific_version(package, version, target_dir): | 299 | try: |
815 | 292 | return True | 300 | return source.get_specific_version(package, version, target_dir) |
816 | 293 | return False | 301 | except PackageVersionNotPresent: |
817 | 302 | pass | ||
818 | 303 | raise PackageVersionNotPresent(package, version, self) | ||
819 | 304 | |||
820 | 305 | |||
821 | 306 | def get_upstream_sources(tree, branch, larstiq=False, upstream_branch=None, | ||
822 | 307 | upstream_revision=None, allow_split=False): | ||
823 | 308 | """Get the list of upstream sources to retrieve upstream versions from. | ||
824 | 309 | |||
825 | 310 | :param tree: The tree that is being built from. | ||
826 | 311 | :param branch: The branch that is being built from. | ||
827 | 312 | :param larstiq: Whether the tree versions the root of ./debian. | ||
828 | 313 | :param upstream_branch: An upstream branch that can be exported | ||
829 | 314 | if needed. | ||
830 | 315 | :param upstream_revision: The revision to use of the upstream branch | ||
831 | 316 | if it is used. | ||
832 | 317 | :param allow_split: Whether the provider can provide the tarball | ||
833 | 318 | by exporting the branch and removing the "debian" dir. | ||
834 | 319 | |||
835 | 320 | """ | ||
836 | 321 | sources = [ | ||
837 | 322 | PristineTarSource(tree, branch), | ||
838 | 323 | AptSource(), | ||
839 | 324 | ] | ||
840 | 325 | if upstream_branch is not None: | ||
841 | 326 | sources.append( | ||
842 | 327 | UpstreamBranchSource(upstream_branch, upstream_revision)) | ||
843 | 328 | sources.extend([ | ||
844 | 329 | GetOrigSourceSource(tree, larstiq), | ||
845 | 330 | UScanSource(tree, larstiq), | ||
846 | 331 | ]) | ||
847 | 332 | if allow_split: | ||
848 | 333 | sources.append(SelfSplitSource(tree)) | ||
849 | 334 | return sources | ||
850 | 294 | 335 | ||
851 | 295 | 336 | ||
852 | 296 | class UpstreamProvider(object): | 337 | class UpstreamProvider(object): |
853 | @@ -300,40 +341,16 @@ | |||
854 | 300 | instance using pristine-tar, or using apt. | 341 | instance using pristine-tar, or using apt. |
855 | 301 | """ | 342 | """ |
856 | 302 | 343 | ||
860 | 303 | def __init__(self, tree, branch, package, version, store_dir, | 344 | def __init__(self, package, version, store_dir, sources): |
858 | 304 | larstiq=False, upstream_branch=None, upstream_revision=None, | ||
859 | 305 | allow_split=False): | ||
861 | 306 | """Create an UpstreamProvider. | 345 | """Create an UpstreamProvider. |
862 | 307 | 346 | ||
863 | 308 | :param tree: The tree that is being built from. | ||
864 | 309 | :param branch: The branch that is being built from. | ||
865 | 310 | :param package: the name of the source package that is being built. | 347 | :param package: the name of the source package that is being built. |
866 | 311 | :param version: the Version of the package that is being built. | 348 | :param version: the Version of the package that is being built. |
867 | 312 | :param store_dir: A directory to cache the tarballs. | 349 | :param store_dir: A directory to cache the tarballs. |
868 | 313 | :param larstiq: Whether the tree versions the root of ./debian. | ||
869 | 314 | :param upstream_branch: An upstream branch that can be exported | ||
870 | 315 | if needed. | ||
871 | 316 | :param upstream_revision: The revision to use of the upstream branch | ||
872 | 317 | if it is used. | ||
873 | 318 | :param allow_split: Whether the provider can provide the tarball | ||
874 | 319 | by exporting the branch and removing the "debian" dir. | ||
875 | 320 | """ | 350 | """ |
876 | 321 | self.package = package | 351 | self.package = package |
877 | 322 | self.version = Version(version) | 352 | self.version = Version(version) |
878 | 323 | self.store_dir = store_dir | 353 | self.store_dir = store_dir |
879 | 324 | sources = [ | ||
880 | 325 | PristineTarSource(tree, branch), | ||
881 | 326 | AptSource(), | ||
882 | 327 | ] | ||
883 | 328 | if upstream_branch is not None: | ||
884 | 329 | sources.append( | ||
885 | 330 | UpstreamBranchSource(upstream_branch, upstream_revision)) | ||
886 | 331 | sources.extend([ | ||
887 | 332 | GetOrigSourceSource(tree, larstiq), | ||
888 | 333 | UScanSource(tree, larstiq), | ||
889 | 334 | ]) | ||
890 | 335 | if allow_split: | ||
891 | 336 | sources.append(SelfSplitSource(tree)) | ||
892 | 337 | self.source = StackedUpstreamSource(sources) | 354 | self.source = StackedUpstreamSource(sources) |
893 | 338 | 355 | ||
894 | 339 | def provide(self, target_dir): | 356 | def provide(self, target_dir): |
895 | @@ -367,15 +384,16 @@ | |||
896 | 367 | if not self.already_exists_in_store(): | 384 | if not self.already_exists_in_store(): |
897 | 368 | if not os.path.exists(self.store_dir): | 385 | if not os.path.exists(self.store_dir): |
898 | 369 | os.makedirs(self.store_dir) | 386 | os.makedirs(self.store_dir) |
902 | 370 | self.source.get_specific_version(self.package, | 387 | try: |
903 | 371 | self.version.upstream_version, | 388 | self.source.get_specific_version(self.package, |
904 | 372 | target_dir) | 389 | self.version.upstream_version, target_dir) |
905 | 390 | except PackageVersionNotPresent: | ||
906 | 391 | raise MissingUpstreamTarball(self._tarball_name()) | ||
907 | 373 | else: | 392 | else: |
908 | 374 | info("Using the upstream tarball that is present in " | 393 | info("Using the upstream tarball that is present in " |
909 | 375 | "%s" % self.store_dir) | 394 | "%s" % self.store_dir) |
913 | 376 | if self.provide_from_store_dir(target_dir): | 395 | assert self.provide_from_store_dir(target_dir) |
914 | 377 | return os.path.join(target_dir, self._tarball_name()) | 396 | return os.path.join(target_dir, self._tarball_name()) |
912 | 378 | raise MissingUpstreamTarball(self._tarball_name()) | ||
915 | 379 | 397 | ||
916 | 380 | def already_exists_in_target(self, target_dir): | 398 | def already_exists_in_target(self, target_dir): |
917 | 381 | return os.path.exists(os.path.join(target_dir, self._tarball_name())) | 399 | return os.path.exists(os.path.join(target_dir, self._tarball_name())) |
Trivial patch to recommend python-launchpadlib since it's used by bzr-builddeb but optional.