Merge lp:~jelmer/bzr-builddeb/obj into lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old
- obj
- Merge into trunk-old
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/bzr-builddeb/obj |
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/obj |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby | Approve | ||
Review via email: mp+5607@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote : | # |
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-04-15 11:50:06 +0000 | |||
3 | +++ cmds.py 2009-04-16 10:42:12 +0000 | |||
4 | @@ -74,7 +74,11 @@ | |||
5 | 74 | MergeModeDistiller, | 74 | MergeModeDistiller, |
6 | 75 | NativeSourceDistiller, | 75 | NativeSourceDistiller, |
7 | 76 | ) | 76 | ) |
9 | 77 | from bzrlib.plugins.builddeb.upstream import UpstreamProvider | 77 | from bzrlib.plugins.builddeb.upstream import ( |
10 | 78 | UpstreamProvider, | ||
11 | 79 | UpstreamBranchSource, | ||
12 | 80 | get_upstream_sources, | ||
13 | 81 | ) | ||
14 | 78 | from bzrlib.plugins.builddeb.util import (find_changelog, | 82 | from bzrlib.plugins.builddeb.util import (find_changelog, |
15 | 79 | lookup_distribution, | 83 | lookup_distribution, |
16 | 80 | suite_to_distribution, | 84 | suite_to_distribution, |
17 | @@ -362,10 +366,11 @@ | |||
18 | 362 | self._get_upstream_branch(merge, export_upstream, | 366 | self._get_upstream_branch(merge, export_upstream, |
19 | 363 | export_upstream_revision, config) | 367 | export_upstream_revision, config) |
20 | 364 | 368 | ||
22 | 365 | upstream_provider = UpstreamProvider(tree, branch, | 369 | upstream_provider = UpstreamProvider( |
23 | 366 | changelog.package, changelog.version.upstream_version, | 370 | changelog.package, changelog.version.upstream_version, |
26 | 367 | orig_dir, larstiq=larstiq, upstream_branch=upstream_branch, | 371 | orig_dir, get_upstream_sources(tree, branch, |
27 | 368 | upstream_revision=upstream_revision, allow_split=split) | 372 | larstiq=larstiq, upstream_branch=upstream_branch, |
28 | 373 | upstream_revision=upstream_revision, allow_split=split)) | ||
29 | 369 | 374 | ||
30 | 370 | if merge: | 375 | if merge: |
31 | 371 | distiller_cls = MergeModeDistiller | 376 | distiller_cls = MergeModeDistiller |
32 | @@ -379,8 +384,8 @@ | |||
33 | 379 | is_working_tree=working_tree) | 384 | is_working_tree=working_tree) |
34 | 380 | 385 | ||
35 | 381 | build_source_dir = os.path.join(build_dir, | 386 | build_source_dir = os.path.join(build_dir, |
38 | 382 | changelog.package + "-" | 387 | "%s-%s" % (changelog.package, |
39 | 383 | + changelog.version.upstream_version) | 388 | changelog.version.upstream_version)) |
40 | 384 | 389 | ||
41 | 385 | builder = DebBuild(distiller, build_source_dir, build_cmd, | 390 | builder = DebBuild(distiller, build_source_dir, build_cmd, |
42 | 386 | use_existing=use_existing) | 391 | use_existing=use_existing) |
43 | @@ -565,11 +570,10 @@ | |||
44 | 565 | tarball_filename = os.path.join(orig_dir, dest_name) | 570 | tarball_filename = os.path.join(orig_dir, dest_name) |
45 | 566 | 571 | ||
46 | 567 | if upstream_branch and no_tarball: | 572 | if upstream_branch and no_tarball: |
49 | 568 | info("Exporting the upstream branch to create the tarball") | 573 | upstream = UpstreamBranchSource(upstream_branch, |
48 | 569 | rev_tree = upstream_branch.repository.revision_tree( | ||
50 | 570 | upstream_revision) | 574 | upstream_revision) |
53 | 571 | export(rev_tree, tarball_filename, format='tgz', | 575 | upstream.get_specific_version(package, version.upstream_version, |
54 | 572 | root="%s-%s" % (package, version.upstream_version)) | 576 | orig_dir) |
55 | 573 | else: | 577 | else: |
56 | 574 | try: | 578 | try: |
57 | 575 | repack_tarball(location, dest_name, target_dir=orig_dir) | 579 | repack_tarball(location, dest_name, target_dir=orig_dir) |
58 | @@ -764,9 +768,9 @@ | |||
59 | 764 | orig_dir = config.orig_dir | 768 | orig_dir = config.orig_dir |
60 | 765 | if orig_dir is None: | 769 | if orig_dir is None: |
61 | 766 | orig_dir = default_orig_dir | 770 | orig_dir = default_orig_dir |
65 | 767 | upstream_provider = UpstreamProvider(t, t.branch, | 771 | upstream_provider = UpstreamProvider(changelog.package, |
66 | 768 | changelog.package, changelog.version.upstream_version, | 772 | changelog.version.upstream_version, orig_dir, |
67 | 769 | orig_dir, larstiq=larstiq) | 773 | get_upstream_sources(t, t.branch, larstiq=larstiq)) |
68 | 770 | 774 | ||
69 | 771 | distiller = MergeModeDistiller(t, upstream_provider, | 775 | distiller = MergeModeDistiller(t, upstream_provider, |
70 | 772 | larstiq=larstiq) | 776 | larstiq=larstiq) |
71 | 773 | 777 | ||
72 | === modified file 'errors.py' | |||
73 | --- errors.py 2009-03-02 22:36:36 +0000 | |||
74 | +++ errors.py 2009-04-16 09:30:49 +0000 | |||
75 | @@ -153,6 +153,14 @@ | |||
76 | 153 | _fmt = "You did not specify a package version." | 153 | _fmt = "You did not specify a package version." |
77 | 154 | 154 | ||
78 | 155 | 155 | ||
79 | 156 | class PackageVersionNotPresent(BzrError): | ||
80 | 157 | _fmt = "%(package)s %(version)s was not found in %(upstream)s." | ||
81 | 158 | |||
82 | 159 | def __init__(self, package, version, upstream): | ||
83 | 160 | BzrError.__init__(self, package=package, version=version, | ||
84 | 161 | upstream=upstream) | ||
85 | 162 | |||
86 | 163 | |||
87 | 156 | class UnsupportedRepackFormat(BzrError): | 164 | class UnsupportedRepackFormat(BzrError): |
88 | 157 | _fmt = ('Either the file extension of "%(location)s" indicates that ' | 165 | _fmt = ('Either the file extension of "%(location)s" indicates that ' |
89 | 158 | 'it is a format unsupported for repacking or it is a ' | 166 | 'it is a format unsupported for repacking or it is a ' |
90 | 159 | 167 | ||
91 | === modified file 'import_dsc.py' | |||
92 | --- import_dsc.py 2009-03-11 07:23:20 +0000 | |||
93 | +++ import_dsc.py 2009-04-15 23:17:50 +0000 | |||
94 | @@ -57,6 +57,7 @@ | |||
95 | 57 | ) | 57 | ) |
96 | 58 | from bzrlib.export import export | 58 | from bzrlib.export import export |
97 | 59 | from bzrlib.osutils import file_iterator, isdir, basename, splitpath | 59 | from bzrlib.osutils import file_iterator, isdir, basename, splitpath |
98 | 60 | from bzrlib.revisionspec import RevisionSpec | ||
99 | 60 | from bzrlib.revision import NULL_REVISION | 61 | from bzrlib.revision import NULL_REVISION |
100 | 61 | from bzrlib.trace import warning, info, mutter | 62 | from bzrlib.trace import warning, info, mutter |
101 | 62 | from bzrlib.transform import TreeTransform, cook_conflicts, resolve_conflicts | 63 | from bzrlib.transform import TreeTransform, cook_conflicts, resolve_conflicts |
102 | @@ -73,7 +74,7 @@ | |||
103 | 73 | UpstreamAlreadyImported, | 74 | UpstreamAlreadyImported, |
104 | 74 | UpstreamBranchAlreadyMerged, | 75 | UpstreamBranchAlreadyMerged, |
105 | 75 | ) | 76 | ) |
107 | 76 | from bzrlib.plugins.builddeb.util import get_commit_info_from_changelog | 77 | from bzrlib.plugins.builddeb.util import get_commit_info_from_changelog, get_snapshot_revision |
108 | 77 | 78 | ||
109 | 78 | 79 | ||
110 | 79 | files_to_ignore = set(['.cvsignore', '.arch-inventory', '.bzrignore', | 80 | files_to_ignore = set(['.cvsignore', '.arch-inventory', '.bzrignore', |
111 | @@ -1534,16 +1535,23 @@ | |||
112 | 1534 | "Should use self.upstream_branch if set" | 1535 | "Should use self.upstream_branch if set" |
113 | 1535 | tempdir = tempfile.mkdtemp(dir=os.path.join(self.tree.basedir, '..')) | 1536 | tempdir = tempfile.mkdtemp(dir=os.path.join(self.tree.basedir, '..')) |
114 | 1536 | try: | 1537 | try: |
115 | 1538 | previous_upstream_revision = get_snapshot_revision(previous_version.upstream_version) | ||
116 | 1537 | if previous_version is not None: | 1539 | if previous_version is not None: |
118 | 1538 | if not self.has_upstream_version_in_packaging_branch( | 1540 | if self.has_upstream_version_in_packaging_branch( |
119 | 1539 | previous_version): | 1541 | previous_version): |
120 | 1542 | upstream_tip = self._revid_of_upstream_version_from_branch( | ||
121 | 1543 | previous_version) | ||
122 | 1544 | self._extract_upstream_tree(upstream_tip, tempdir) | ||
123 | 1545 | elif (upstream_branch is not None and | ||
124 | 1546 | previous_upstream_revision is not None): | ||
125 | 1547 | upstream_tip = RevisionSpec.from_string(previous_upstream_revision).as_revision_id(upstream_branch) | ||
126 | 1548 | assert isinstance(upstream_tip, str) | ||
127 | 1549 | self._extract_upstream_tree(upstream_tip, tempdir) | ||
128 | 1550 | else: | ||
129 | 1540 | raise BzrCommandError("Unable to find the tag for the " | 1551 | raise BzrCommandError("Unable to find the tag for the " |
130 | 1541 | "previous upstream version, %s, in the branch: " | 1552 | "previous upstream version, %s, in the branch: " |
131 | 1542 | "%s" % (previous_version, | 1553 | "%s" % (previous_version, |
132 | 1543 | self.upstream_tag_name(previous_version))) | 1554 | self.upstream_tag_name(previous_version))) |
133 | 1544 | upstream_tip = self._revid_of_upstream_version_from_branch( | ||
134 | 1545 | previous_version) | ||
135 | 1546 | self._extract_upstream_tree(upstream_tip, tempdir) | ||
136 | 1547 | else: | 1555 | else: |
137 | 1548 | self._create_empty_upstream_tree(tempdir) | 1556 | self._create_empty_upstream_tree(tempdir) |
138 | 1549 | if self.has_upstream_version_in_packaging_branch(version): | 1557 | if self.has_upstream_version_in_packaging_branch(version): |
139 | 1550 | 1558 | ||
140 | === modified file 'tests/test_upstream.py' | |||
141 | --- tests/test_upstream.py 2009-03-08 23:18:01 +0000 | |||
142 | +++ tests/test_upstream.py 2009-04-16 10:42:12 +0000 | |||
143 | @@ -24,14 +24,21 @@ | |||
144 | 24 | 24 | ||
145 | 25 | from debian_bundle.changelog import Version | 25 | from debian_bundle.changelog import Version |
146 | 26 | 26 | ||
148 | 27 | from bzrlib.tests import TestCaseWithTransport | 27 | from bzrlib.tests import ( |
149 | 28 | TestCase, | ||
150 | 29 | TestCaseWithTransport, | ||
151 | 30 | ) | ||
152 | 28 | from bzrlib.plugins.builddeb.errors import ( | 31 | from bzrlib.plugins.builddeb.errors import ( |
153 | 29 | MissingUpstreamTarball, | 32 | MissingUpstreamTarball, |
154 | 33 | PackageVersionNotPresent, | ||
155 | 30 | ) | 34 | ) |
156 | 31 | from bzrlib.plugins.builddeb.upstream import ( | 35 | from bzrlib.plugins.builddeb.upstream import ( |
157 | 36 | AptSource, | ||
158 | 37 | PristineTarSource, | ||
159 | 38 | StackedUpstreamSource, | ||
160 | 32 | UpstreamProvider, | 39 | UpstreamProvider, |
163 | 33 | get_apt_command_for_source, | 40 | UpstreamSource, |
164 | 34 | provide_with_apt, | 41 | UScanSource, |
165 | 35 | ) | 42 | ) |
166 | 36 | from bzrlib.plugins.builddeb.util import ( | 43 | from bzrlib.plugins.builddeb.util import ( |
167 | 37 | get_parent_dir, | 44 | get_parent_dir, |
168 | @@ -39,156 +46,6 @@ | |||
169 | 39 | ) | 46 | ) |
170 | 40 | 47 | ||
171 | 41 | 48 | ||
172 | 42 | class MockProvider(object): | ||
173 | 43 | |||
174 | 44 | def create_target(self, path): | ||
175 | 45 | parent_dir = get_parent_dir(path) | ||
176 | 46 | if parent_dir != '' and not os.path.exists(parent_dir): | ||
177 | 47 | os.makedirs(parent_dir) | ||
178 | 48 | f = open(path, "wb") | ||
179 | 49 | try: | ||
180 | 50 | f.write('') | ||
181 | 51 | finally: | ||
182 | 52 | f.close() | ||
183 | 53 | |||
184 | 54 | def tarball_name(self, package, upstream_version): | ||
185 | 55 | return tarball_name(package, upstream_version) | ||
186 | 56 | |||
187 | 57 | |||
188 | 58 | class MockAptProvider(MockProvider): | ||
189 | 59 | |||
190 | 60 | def __init__(self, find=False): | ||
191 | 61 | self.find = find | ||
192 | 62 | self.called_times = 0 | ||
193 | 63 | self.package = None | ||
194 | 64 | self.upstream_version = None | ||
195 | 65 | self.target_dir = None | ||
196 | 66 | |||
197 | 67 | def provide(self, package, upstream_version, target_dir): | ||
198 | 68 | self.called_times += 1 | ||
199 | 69 | self.package = package | ||
200 | 70 | self.upstream_version = upstream_version | ||
201 | 71 | self.target_dir = target_dir | ||
202 | 72 | if self.find: | ||
203 | 73 | self.create_target(os.path.join(target_dir, | ||
204 | 74 | self.tarball_name(package, upstream_version))) | ||
205 | 75 | return self.find | ||
206 | 76 | |||
207 | 77 | |||
208 | 78 | class MockUscanProvider(MockProvider): | ||
209 | 79 | |||
210 | 80 | def __init__(self, find=False): | ||
211 | 81 | self.find = find | ||
212 | 82 | self.called_times = 0 | ||
213 | 83 | self.package = None | ||
214 | 84 | self.upstream_version = None | ||
215 | 85 | self.watch_file_contents = None | ||
216 | 86 | self.target_dir = None | ||
217 | 87 | |||
218 | 88 | def provide(self, package, upstream_version, watch_file, target_dir): | ||
219 | 89 | self.called_times += 1 | ||
220 | 90 | self.package = package | ||
221 | 91 | self.upstream_version = upstream_version | ||
222 | 92 | f = open(watch_file, "rb") | ||
223 | 93 | try: | ||
224 | 94 | self.watch_file_contents = f.read() | ||
225 | 95 | finally: | ||
226 | 96 | f.close() | ||
227 | 97 | self.target_dir = target_dir | ||
228 | 98 | if self.find: | ||
229 | 99 | self.create_target(os.path.join(target_dir, | ||
230 | 100 | self.tarball_name(package, upstream_version))) | ||
231 | 101 | return self.find | ||
232 | 102 | |||
233 | 103 | |||
234 | 104 | class MockPristineProvider(MockProvider): | ||
235 | 105 | |||
236 | 106 | def __init__(self, find=False): | ||
237 | 107 | self.find = find | ||
238 | 108 | self.called_times = 0 | ||
239 | 109 | self.tree = None | ||
240 | 110 | self.branch = None | ||
241 | 111 | self.package = None | ||
242 | 112 | self.version = None | ||
243 | 113 | self.target_filename = None | ||
244 | 114 | |||
245 | 115 | def provide(self, tree, branch, package, version, target_filename): | ||
246 | 116 | self.called_times += 1 | ||
247 | 117 | self.tree = tree | ||
248 | 118 | self.branch = branch | ||
249 | 119 | self.package = package | ||
250 | 120 | self.version = version | ||
251 | 121 | self.target_filename = target_filename | ||
252 | 122 | if self.find: | ||
253 | 123 | self.create_target(target_filename) | ||
254 | 124 | return self.find | ||
255 | 125 | |||
256 | 126 | |||
257 | 127 | class MockOrigSourceProvider(MockProvider): | ||
258 | 128 | |||
259 | 129 | def __init__(self, find=False): | ||
260 | 130 | self.find = find | ||
261 | 131 | self.called_times = 0 | ||
262 | 132 | self.source_dir = None | ||
263 | 133 | self.fetch_dir = None | ||
264 | 134 | self.desired_tarball_name = None | ||
265 | 135 | self.target_dir = None | ||
266 | 136 | |||
267 | 137 | def provide(self, source_dir, fetch_dir, desired_tarball_name, | ||
268 | 138 | target_dir): | ||
269 | 139 | self.called_times += 1 | ||
270 | 140 | self.source_dir = source_dir | ||
271 | 141 | self.fetch_dir = fetch_dir | ||
272 | 142 | self.desired_tarball_name = desired_tarball_name | ||
273 | 143 | self.target_dir = target_dir | ||
274 | 144 | if self.find: | ||
275 | 145 | self.create_target(os.path.join(target_dir, desired_tarball_name)) | ||
276 | 146 | return self.find | ||
277 | 147 | |||
278 | 148 | |||
279 | 149 | class MockOtherBranchProvider(MockProvider): | ||
280 | 150 | |||
281 | 151 | def __init__(self, find=False): | ||
282 | 152 | self.find = find | ||
283 | 153 | self.called_times = 0 | ||
284 | 154 | self.upstream_branch = None | ||
285 | 155 | self.upstream_revision = None | ||
286 | 156 | self.target_filename = None | ||
287 | 157 | self.tarball_base = None | ||
288 | 158 | |||
289 | 159 | def provide(self, upstream_branch, upstream_revision, target_filename, | ||
290 | 160 | tarball_base): | ||
291 | 161 | self.called_times += 1 | ||
292 | 162 | self.upstream_branch = upstream_branch | ||
293 | 163 | self.upstream_revision = upstream_revision | ||
294 | 164 | self.target_filename = target_filename | ||
295 | 165 | self.tarball_base = tarball_base | ||
296 | 166 | if self.find: | ||
297 | 167 | self.create_target(target_filename) | ||
298 | 168 | return self.find | ||
299 | 169 | |||
300 | 170 | |||
301 | 171 | class MockSplitProvider(MockProvider): | ||
302 | 172 | |||
303 | 173 | def __init__(self, find=False): | ||
304 | 174 | self.find = find | ||
305 | 175 | self.called_times = 0 | ||
306 | 176 | self.tree = None | ||
307 | 177 | self.package = None | ||
308 | 178 | self.upstream_version = None | ||
309 | 179 | self.target_filename = None | ||
310 | 180 | |||
311 | 181 | def provide(self, tree, package, upstream_version, target_filename): | ||
312 | 182 | self.called_times += 1 | ||
313 | 183 | self.tree = tree | ||
314 | 184 | self.package = package | ||
315 | 185 | self.upstream_version = upstream_version | ||
316 | 186 | self.target_filename = target_filename | ||
317 | 187 | if self.find: | ||
318 | 188 | self.create_target(self.target_filename) | ||
319 | 189 | return self.find | ||
320 | 190 | |||
321 | 191 | |||
322 | 192 | class MockSources(object): | 49 | class MockSources(object): |
323 | 193 | 50 | ||
324 | 194 | def __init__(self, versions): | 51 | def __init__(self, versions): |
325 | @@ -245,210 +102,21 @@ | |||
326 | 245 | return self.work | 102 | return self.work |
327 | 246 | 103 | ||
328 | 247 | 104 | ||
521 | 248 | class UpstreamProviderTests(TestCaseWithTransport): | 105 | class AptSourceTests(TestCase): |
330 | 249 | |||
331 | 250 | def setUp(self): | ||
332 | 251 | super(UpstreamProviderTests, self).setUp() | ||
333 | 252 | self.tree = self.make_branch_and_tree(".") | ||
334 | 253 | self.branch = self.tree.branch | ||
335 | 254 | self.package = "package" | ||
336 | 255 | self.version = Version("0.1-1") | ||
337 | 256 | self.upstream_version = self.version.upstream_version | ||
338 | 257 | self.desired_tarball_name = tarball_name(self.package, | ||
339 | 258 | self.upstream_version) | ||
340 | 259 | self.tarball_base = "%s-%s" % (self.package, self.upstream_version) | ||
341 | 260 | self.store_dir = "store" | ||
342 | 261 | self.provider = UpstreamProvider(self.tree, self.branch, | ||
343 | 262 | self.package, self.version, self.store_dir) | ||
344 | 263 | self.providers = {} | ||
345 | 264 | self.providers["apt"]= MockAptProvider() | ||
346 | 265 | self.provider._apt_provider = self.providers["apt"].provide | ||
347 | 266 | self.providers["uscan"] = MockUscanProvider() | ||
348 | 267 | self.provider._uscan_provider = self.providers["uscan"].provide | ||
349 | 268 | self.providers["pristine"] = MockPristineProvider() | ||
350 | 269 | self.provider._pristine_provider = self.providers["pristine"].provide | ||
351 | 270 | self.providers["orig"] = MockOrigSourceProvider() | ||
352 | 271 | self.provider._orig_source_provider = self.providers["orig"].provide | ||
353 | 272 | self.providers["upstream"] = MockOtherBranchProvider() | ||
354 | 273 | self.provider._upstream_branch_provider = \ | ||
355 | 274 | self.providers["upstream"].provide | ||
356 | 275 | self.providers["split"] = MockSplitProvider() | ||
357 | 276 | self.provider._split_provider = self.providers["split"].provide | ||
358 | 277 | self.target_dir = "target" | ||
359 | 278 | self.target_filename = os.path.join(self.target_dir, | ||
360 | 279 | self.desired_tarball_name) | ||
361 | 280 | self.store_filename = os.path.join(self.store_dir, | ||
362 | 281 | tarball_name(self.package, self.version.upstream_version)) | ||
363 | 282 | |||
364 | 283 | def assertProvidersCalled(self, providers): | ||
365 | 284 | for provider_name, provider in self.providers.items(): | ||
366 | 285 | if provider_name in providers: | ||
367 | 286 | self.assertCalledCorrectly(provider_name) | ||
368 | 287 | else: | ||
369 | 288 | self.assertEqual(provider.called_times, 0, | ||
370 | 289 | "%s wasn't expected to be called" % provider_name) | ||
371 | 290 | |||
372 | 291 | def call_provider(self): | ||
373 | 292 | self.assertEqual(self.provider.provide(self.target_dir), | ||
374 | 293 | self.target_filename) | ||
375 | 294 | |||
376 | 295 | def test_already_in_target(self): | ||
377 | 296 | os.makedirs(self.target_dir) | ||
378 | 297 | f = open(self.target_filename, "wb") | ||
379 | 298 | f.close() | ||
380 | 299 | self.call_provider() | ||
381 | 300 | self.failUnlessExists(self.target_filename) | ||
382 | 301 | # Should this be copied across? | ||
383 | 302 | self.failIfExists(self.store_filename) | ||
384 | 303 | self.assertProvidersCalled({}) | ||
385 | 304 | |||
386 | 305 | def test_already_in_store(self): | ||
387 | 306 | os.makedirs(self.store_dir) | ||
388 | 307 | f = open(self.store_filename, "wb") | ||
389 | 308 | f.close() | ||
390 | 309 | self.call_provider() | ||
391 | 310 | self.failUnlessExists(self.target_filename) | ||
392 | 311 | self.failUnlessExists(self.store_filename) | ||
393 | 312 | self.assertProvidersCalled({}) | ||
394 | 313 | |||
395 | 314 | def assertCalledCorrectly(self, provider_name): | ||
396 | 315 | provider = self.providers[provider_name] | ||
397 | 316 | for attr_name in provider.__dict__: | ||
398 | 317 | if attr_name in ("find", "provide", "source_dir"): | ||
399 | 318 | continue | ||
400 | 319 | if attr_name == "called_times": | ||
401 | 320 | self.assertEqual(provider.called_times, 1, | ||
402 | 321 | "%s was not called" % provider_name) | ||
403 | 322 | continue | ||
404 | 323 | if attr_name == "target_filename": | ||
405 | 324 | self.assertEqual(provider.target_filename, | ||
406 | 325 | self.store_filename) | ||
407 | 326 | continue | ||
408 | 327 | if attr_name == "target_dir": | ||
409 | 328 | self.assertEqual(provider.target_dir, | ||
410 | 329 | self.store_dir) | ||
411 | 330 | continue | ||
412 | 331 | if attr_name == "fetch_dir": | ||
413 | 332 | self.assertEqual(provider.fetch_dir, | ||
414 | 333 | os.path.dirname(provider.source_dir)) | ||
415 | 334 | continue | ||
416 | 335 | attr = getattr(provider, attr_name) | ||
417 | 336 | correct_attr = getattr(self, attr_name) | ||
418 | 337 | self.assertEqual(correct_attr, attr, | ||
419 | 338 | "%s doesn't match\nexpected: %s\ngot: %s" | ||
420 | 339 | % (attr_name, correct_attr, attr)) | ||
421 | 340 | |||
422 | 341 | def assertSuccesfulCall(self, provider, other_providers): | ||
423 | 342 | self.providers[provider].find = True | ||
424 | 343 | self.call_provider() | ||
425 | 344 | self.failUnlessExists(self.target_filename) | ||
426 | 345 | self.failUnlessExists(self.store_filename) | ||
427 | 346 | self.assertProvidersCalled([provider] + other_providers) | ||
428 | 347 | |||
429 | 348 | def test_from_pristine_tar(self): | ||
430 | 349 | self.assertSuccesfulCall("pristine", []) | ||
431 | 350 | |||
432 | 351 | def test_from_apt(self): | ||
433 | 352 | self.assertSuccesfulCall("apt", ["pristine"]) | ||
434 | 353 | |||
435 | 354 | def test_from_uscan(self): | ||
436 | 355 | self.build_tree(["watch", "debian/", "debian/watch"]) | ||
437 | 356 | self.tree.add(["watch", "debian/", "debian/watch"]) | ||
438 | 357 | self.watch_file_contents = "contents of debian/watch\n" | ||
439 | 358 | self.assertSuccesfulCall("uscan", ["pristine", "apt"]) | ||
440 | 359 | |||
441 | 360 | def test_uscan_not_called_if_not_watch(self): | ||
442 | 361 | self.build_tree(["watch"]) | ||
443 | 362 | self.tree.add(["watch"]) | ||
444 | 363 | self.assertRaises(MissingUpstreamTarball, self.provider.provide, | ||
445 | 364 | self.target_dir) | ||
446 | 365 | self.failIfExists(self.target_filename) | ||
447 | 366 | self.failIfExists(self.store_filename) | ||
448 | 367 | self.assertProvidersCalled(["pristine", "apt"]) | ||
449 | 368 | |||
450 | 369 | def test_uscan_in_larstiq(self): | ||
451 | 370 | self.build_tree(["watch", "debian/", "debian/watch"]) | ||
452 | 371 | self.tree.add(["watch", "debian/", "debian/watch"]) | ||
453 | 372 | self.watch_file_contents = "contents of watch\n" | ||
454 | 373 | self.provider.larstiq = True | ||
455 | 374 | self.assertSuccesfulCall("uscan", ["pristine", "apt"]) | ||
456 | 375 | |||
457 | 376 | def test_from_get_orig_source(self): | ||
458 | 377 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
459 | 378 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
460 | 379 | self.watch_file_contents = "contents of debian/rules\n" | ||
461 | 380 | self.assertSuccesfulCall("orig", ["pristine", "apt"]) | ||
462 | 381 | |||
463 | 382 | def test_get_orig_source_not_called_if_no_rules(self): | ||
464 | 383 | self.build_tree(["rules"]) | ||
465 | 384 | self.tree.add(["rules"]) | ||
466 | 385 | self.assertRaises(MissingUpstreamTarball, self.provider.provide, | ||
467 | 386 | self.target_dir) | ||
468 | 387 | self.failIfExists(self.target_filename) | ||
469 | 388 | self.failIfExists(self.store_filename) | ||
470 | 389 | self.assertProvidersCalled(["pristine", "apt"]) | ||
471 | 390 | |||
472 | 391 | def test_get_orig_source_in_larstiq(self): | ||
473 | 392 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
474 | 393 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
475 | 394 | self.watch_file_contents = "contents of rules\n" | ||
476 | 395 | self.provider.larstiq = True | ||
477 | 396 | self.assertSuccesfulCall("orig", ["pristine", "apt"]) | ||
478 | 397 | |||
479 | 398 | def test_from_upstream_branch(self): | ||
480 | 399 | upstream_tree = self.make_branch_and_tree("upstream") | ||
481 | 400 | self.build_tree(["upstream/foo"]) | ||
482 | 401 | upstream_tree.add(["foo"]) | ||
483 | 402 | self.upstream_branch = upstream_tree.branch | ||
484 | 403 | self.upstream_revision = upstream_tree.commit("upstream one") | ||
485 | 404 | self.provider.upstream_revision = self.upstream_revision | ||
486 | 405 | self.provider.upstream_branch = self.upstream_branch | ||
487 | 406 | self.assertSuccesfulCall("upstream", ["pristine", "apt"]) | ||
488 | 407 | |||
489 | 408 | def test_from_split(self): | ||
490 | 409 | self.provider.allow_split = True | ||
491 | 410 | self.assertSuccesfulCall("split", ["pristine", "apt"]) | ||
492 | 411 | |||
493 | 412 | def test_upstream_before_orig_source(self): | ||
494 | 413 | upstream_tree = self.make_branch_and_tree("upstream") | ||
495 | 414 | self.build_tree(["upstream/foo"]) | ||
496 | 415 | upstream_tree.add(["foo"]) | ||
497 | 416 | self.upstream_branch = upstream_tree.branch | ||
498 | 417 | self.upstream_revision = upstream_tree.commit("upstream one") | ||
499 | 418 | self.provider.upstream_revision = self.upstream_revision | ||
500 | 419 | self.provider.upstream_branch = self.upstream_branch | ||
501 | 420 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
502 | 421 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
503 | 422 | self.watch_file_contents = "contents of debian/rules\n" | ||
504 | 423 | self.assertSuccesfulCall("upstream", ["pristine", "apt"]) | ||
505 | 424 | |||
506 | 425 | def test_get_orig_source_before_uscan(self): | ||
507 | 426 | self.build_tree(["rules", "debian/", "debian/rules"]) | ||
508 | 427 | self.tree.add(["rules", "debian/", "debian/rules"]) | ||
509 | 428 | self.watch_file_contents = "contents of debian/rules\n" | ||
510 | 429 | self.build_tree(["watch", "debian/watch"]) | ||
511 | 430 | self.tree.add(["watch", "debian/watch"]) | ||
512 | 431 | self.watch_file_contents = "contents of debian/watch\n" | ||
513 | 432 | self.assertSuccesfulCall("orig", ["pristine", "apt"]) | ||
514 | 433 | |||
515 | 434 | def test_uscan_before_split(self): | ||
516 | 435 | self.build_tree(["watch", "debian/", "debian/watch"]) | ||
517 | 436 | self.tree.add(["watch", "debian/", "debian/watch"]) | ||
518 | 437 | self.watch_file_contents = "contents of debian/watch\n" | ||
519 | 438 | self.provider.allow_split = True | ||
520 | 439 | self.assertSuccesfulCall("uscan", ["pristine", "apt"]) | ||
522 | 440 | 106 | ||
523 | 441 | def test_get_apt_command_for_source(self): | 107 | def test_get_apt_command_for_source(self): |
524 | 442 | self.assertEqual("apt-get source -y --only-source --tar-only " | 108 | self.assertEqual("apt-get source -y --only-source --tar-only " |
525 | 443 | "apackage=someversion", | 109 | "apackage=someversion", |
527 | 444 | get_apt_command_for_source("apackage", "someversion")) | 110 | AptSource()._get_command("apackage", "someversion")) |
528 | 445 | 111 | ||
529 | 446 | def test_apt_provider_no_package(self): | 112 | def test_apt_provider_no_package(self): |
530 | 447 | caller = MockAptCaller() | 113 | caller = MockAptCaller() |
531 | 448 | sources = MockSources([]) | 114 | sources = MockSources([]) |
532 | 449 | apt_pkg = MockAptPkg(sources) | 115 | apt_pkg = MockAptPkg(sources) |
535 | 450 | self.assertEqual(False, provide_with_apt("apackage", "0.2", | 116 | src = AptSource() |
536 | 451 | "target", _apt_pkg=apt_pkg, _apt_caller=caller)) | 117 | src._run_apt_source = caller.call |
537 | 118 | self.assertRaises(PackageVersionNotPresent, src.get_specific_version, | ||
538 | 119 | "apackage", "0.2", "target", _apt_pkg=apt_pkg) | ||
539 | 452 | self.assertEqual(1, apt_pkg.init_called_times) | 120 | self.assertEqual(1, apt_pkg.init_called_times) |
540 | 453 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 121 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
541 | 454 | self.assertEqual(1, sources.restart_called_times) | 122 | self.assertEqual(1, sources.restart_called_times) |
542 | @@ -460,8 +128,10 @@ | |||
543 | 460 | caller = MockAptCaller() | 128 | caller = MockAptCaller() |
544 | 461 | sources = MockSources(["0.1-1"]) | 129 | sources = MockSources(["0.1-1"]) |
545 | 462 | apt_pkg = MockAptPkg(sources) | 130 | apt_pkg = MockAptPkg(sources) |
548 | 463 | self.assertEqual(False, provide_with_apt("apackage", "0.2", | 131 | src = AptSource() |
549 | 464 | "target", _apt_pkg=apt_pkg, _apt_caller=caller)) | 132 | src._run_apt_source = caller.call |
550 | 133 | self.assertRaises(PackageVersionNotPresent, src.get_specific_version, | ||
551 | 134 | "apackage", "0.2", "target", _apt_pkg=apt_pkg) | ||
552 | 465 | self.assertEqual(1, apt_pkg.init_called_times) | 135 | self.assertEqual(1, apt_pkg.init_called_times) |
553 | 466 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 136 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
554 | 467 | self.assertEqual(1, sources.restart_called_times) | 137 | self.assertEqual(1, sources.restart_called_times) |
555 | @@ -473,8 +143,10 @@ | |||
556 | 473 | caller = MockAptCaller(work=True) | 143 | caller = MockAptCaller(work=True) |
557 | 474 | sources = MockSources(["0.1-1", "0.2-1"]) | 144 | sources = MockSources(["0.1-1", "0.2-1"]) |
558 | 475 | apt_pkg = MockAptPkg(sources) | 145 | apt_pkg = MockAptPkg(sources) |
561 | 476 | self.assertEqual(True, provide_with_apt("apackage", "0.2", | 146 | src = AptSource() |
562 | 477 | "target", _apt_pkg=apt_pkg, _apt_caller=caller.call)) | 147 | src._run_apt_source = caller.call |
563 | 148 | src.get_specific_version("apackage", "0.2", "target", | ||
564 | 149 | _apt_pkg=apt_pkg) | ||
565 | 478 | self.assertEqual(1, apt_pkg.init_called_times) | 150 | self.assertEqual(1, apt_pkg.init_called_times) |
566 | 479 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 151 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
567 | 480 | self.assertEqual(1, sources.restart_called_times) | 152 | self.assertEqual(1, sources.restart_called_times) |
568 | @@ -490,8 +162,11 @@ | |||
569 | 490 | caller = MockAptCaller() | 162 | caller = MockAptCaller() |
570 | 491 | sources = MockSources(["0.1-1", "0.2-1"]) | 163 | sources = MockSources(["0.1-1", "0.2-1"]) |
571 | 492 | apt_pkg = MockAptPkg(sources) | 164 | apt_pkg = MockAptPkg(sources) |
574 | 493 | self.assertEqual(False, provide_with_apt("apackage", "0.2", | 165 | src = AptSource() |
575 | 494 | "target", _apt_pkg=apt_pkg, _apt_caller=caller.call)) | 166 | src._run_apt_source = caller.call |
576 | 167 | self.assertRaises(PackageVersionNotPresent, src.get_specific_version, | ||
577 | 168 | "apackage", "0.2", "target", | ||
578 | 169 | _apt_pkg=apt_pkg) | ||
579 | 495 | self.assertEqual(1, apt_pkg.init_called_times) | 170 | self.assertEqual(1, apt_pkg.init_called_times) |
580 | 496 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) | 171 | self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times) |
581 | 497 | self.assertEqual(1, sources.restart_called_times) | 172 | self.assertEqual(1, sources.restart_called_times) |
582 | @@ -502,3 +177,71 @@ | |||
583 | 502 | self.assertEqual("apackage", caller.package) | 177 | self.assertEqual("apackage", caller.package) |
584 | 503 | self.assertEqual("0.2-1", caller.version_str) | 178 | self.assertEqual("0.2-1", caller.version_str) |
585 | 504 | self.assertEqual("target", caller.target_dir) | 179 | self.assertEqual("target", caller.target_dir) |
586 | 180 | |||
587 | 181 | |||
588 | 182 | class RecordingSource(object): | ||
589 | 183 | |||
590 | 184 | def __init__(self, succeed): | ||
591 | 185 | self._succeed = succeed | ||
592 | 186 | self._specific_versions = [] | ||
593 | 187 | |||
594 | 188 | def get_specific_version(self, package, version, target_dir): | ||
595 | 189 | self._specific_versions.append((package, version, target_dir)) | ||
596 | 190 | if not self._succeed: | ||
597 | 191 | raise PackageVersionNotPresent(package, version, self) | ||
598 | 192 | |||
599 | 193 | def __repr__(self): | ||
600 | 194 | return "%s()" % self.__class__.__name__ | ||
601 | 195 | |||
602 | 196 | |||
603 | 197 | class StackedUpstreamSourceTests(TestCase): | ||
604 | 198 | |||
605 | 199 | def test_first_wins(self): | ||
606 | 200 | a = RecordingSource(False) | ||
607 | 201 | b = RecordingSource(True) | ||
608 | 202 | c = RecordingSource(False) | ||
609 | 203 | stack = StackedUpstreamSource([a, b, c]) | ||
610 | 204 | stack.get_specific_version("mypkg", "1.0", "bla") | ||
611 | 205 | self.assertEquals([("mypkg", "1.0", "bla")], b._specific_versions) | ||
612 | 206 | self.assertEquals([("mypkg", "1.0", "bla")], a._specific_versions) | ||
613 | 207 | self.assertEquals([], c._specific_versions) | ||
614 | 208 | |||
615 | 209 | def test_repr(self): | ||
616 | 210 | self.assertEquals("StackedUpstreamSource([])", | ||
617 | 211 | repr(StackedUpstreamSource([]))) | ||
618 | 212 | self.assertEquals("StackedUpstreamSource([RecordingSource()])", | ||
619 | 213 | repr(StackedUpstreamSource([RecordingSource(False)]))) | ||
620 | 214 | |||
621 | 215 | def test_none(self): | ||
622 | 216 | a = RecordingSource(False) | ||
623 | 217 | b = RecordingSource(False) | ||
624 | 218 | stack = StackedUpstreamSource([a, b]) | ||
625 | 219 | self.assertRaises(PackageVersionNotPresent, | ||
626 | 220 | stack.get_specific_version, "pkg", "1.0", "bla") | ||
627 | 221 | self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions) | ||
628 | 222 | self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions) | ||
629 | 223 | |||
630 | 224 | |||
631 | 225 | class UScanSourceTests(TestCaseWithTransport): | ||
632 | 226 | |||
633 | 227 | def setUp(self): | ||
634 | 228 | super(UScanSourceTests, self).setUp() | ||
635 | 229 | self.tree = self.make_branch_and_tree('.') | ||
636 | 230 | |||
637 | 231 | def test_export_watchfile_none(self): | ||
638 | 232 | src = UScanSource(self.tree, False) | ||
639 | 233 | self.assertEquals(None, src._export_watchfile()) | ||
640 | 234 | |||
641 | 235 | def test_export_watchfile_larstiq(self): | ||
642 | 236 | src = UScanSource(self.tree, True) | ||
643 | 237 | self.build_tree(['watch']) | ||
644 | 238 | self.assertEquals(None, src._export_watchfile()) | ||
645 | 239 | self.tree.add(['watch']) | ||
646 | 240 | self.assertTrue(src._export_watchfile() is not None) | ||
647 | 241 | |||
648 | 242 | def test_export_watchfile(self): | ||
649 | 243 | src = UScanSource(self.tree, False) | ||
650 | 244 | self.build_tree(['debian/', 'debian/watch']) | ||
651 | 245 | self.assertEquals(None, src._export_watchfile()) | ||
652 | 246 | self.tree.smart_add(['debian/watch']) | ||
653 | 247 | self.assertTrue(src._export_watchfile() is not None) | ||
654 | 505 | 248 | ||
655 | === modified file 'upstream.py' | |||
656 | --- upstream.py 2009-03-07 23:54:46 +0000 | |||
657 | +++ upstream.py 2009-04-16 10:06:01 +0000 | |||
658 | @@ -1,5 +1,6 @@ | |||
659 | 1 | # upstream.py -- Providers of upstream source | 1 | # upstream.py -- Providers of upstream source |
660 | 2 | # Copyright (C) 2009 Canonical Ltd. | 2 | # Copyright (C) 2009 Canonical Ltd. |
661 | 3 | # Copyright (C) 2009 Jelmer Vernooij <jelmer@debian.org> | ||
662 | 3 | # | 4 | # |
663 | 4 | # This file is part of bzr-builddeb. | 5 | # This file is part of bzr-builddeb. |
664 | 5 | # | 6 | # |
665 | @@ -26,119 +27,313 @@ | |||
666 | 26 | from debian_bundle.changelog import Version | 27 | from debian_bundle.changelog import Version |
667 | 27 | 28 | ||
668 | 28 | from bzrlib.export import export | 29 | from bzrlib.export import export |
669 | 30 | from bzrlib.revisionspec import RevisionSpec | ||
670 | 29 | from bzrlib.trace import info | 31 | from bzrlib.trace import info |
671 | 30 | 32 | ||
673 | 31 | from bzrlib.plugins.builddeb.errors import MissingUpstreamTarball | 33 | from bzrlib.plugins.builddeb.errors import ( |
674 | 34 | MissingUpstreamTarball, | ||
675 | 35 | PackageVersionNotPresent, | ||
676 | 36 | ) | ||
677 | 32 | from bzrlib.plugins.builddeb.import_dsc import DistributionBranch | 37 | from bzrlib.plugins.builddeb.import_dsc import DistributionBranch |
678 | 33 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball | 38 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball |
787 | 34 | 39 | from bzrlib.plugins.builddeb.util import ( | |
788 | 35 | 40 | get_snapshot_revision, | |
789 | 36 | def get_apt_command_for_source(package, version_str): | 41 | tarball_name, |
790 | 37 | return 'apt-get source -y --only-source --tar-only %s=%s' % \ | 42 | ) |
791 | 38 | (package, version_str) | 43 | |
792 | 39 | 44 | ||
793 | 40 | 45 | class UpstreamSource(object): | |
794 | 41 | def call_apt_for_source(package, version_str, target_dir): | 46 | """A source for upstream versions (uscan, get-orig-source, etc).""" |
795 | 42 | command = get_apt_command_for_source(package, version_str) | 47 | |
796 | 43 | proc = subprocess.Popen(command, shell=True, cwd=target_dir) | 48 | def get_latest_version(self, package, target_dir): |
797 | 44 | proc.wait() | 49 | """Fetch the source tarball for the latest available version. |
798 | 45 | if proc.returncode != 0: | 50 | |
799 | 46 | return False | 51 | :param package: Name of the package |
800 | 47 | return True | 52 | :param target_dir: Directory in which to store the tarball |
801 | 48 | 53 | """ | |
802 | 49 | 54 | raise NotImplemented(self.get_latest_version) | |
803 | 50 | def provide_with_apt(package, upstream_version, target_dir, _apt_pkg=None, | 55 | |
804 | 51 | _apt_caller=None): | 56 | def get_specific_version(self, package, version, target_dir): |
805 | 52 | if _apt_pkg is None: | 57 | """Fetch the source tarball for a particular version. |
806 | 53 | import apt_pkg | 58 | |
807 | 54 | else: | 59 | :param package: Name of the package |
808 | 55 | apt_pkg = _apt_pkg | 60 | :param version: Version string of the version to fetch |
809 | 56 | if _apt_caller is None: | 61 | :param target_dir: Directory in which to store the tarball |
810 | 57 | _apt_caller = call_apt_for_source | 62 | """ |
811 | 58 | apt_pkg.init() | 63 | raise NotImplemented(self.get_specific_version) |
812 | 59 | sources = apt_pkg.GetPkgSrcRecords() | 64 | |
813 | 60 | sources.Restart() | 65 | def _tarball_path(self, package, version, target_dir): |
814 | 61 | info("Using apt to look for the upstream tarball.") | 66 | return os.path.join(target_dir, tarball_name(package, version)) |
815 | 62 | while sources.Lookup(package): | 67 | |
816 | 63 | if upstream_version \ | 68 | |
817 | 64 | == Version(sources.Version).upstream_version: | 69 | class PristineTarSource(UpstreamSource): |
818 | 65 | if _apt_caller(package, sources.Version, target_dir): | 70 | """Source that uses the pristine-tar revisions in the packaging branch.""" |
819 | 66 | return True | 71 | |
820 | 67 | break | 72 | def __init__(self, tree, branch): |
821 | 68 | info("apt could not find the needed tarball.") | 73 | self.branch = branch |
822 | 69 | return False | 74 | self.tree = tree |
823 | 70 | 75 | ||
824 | 71 | 76 | def get_specific_version(self, package, upstream_version, target_dir): | |
825 | 72 | def provide_with_uscan(package, upstream_version, watch_file, target_dir): | 77 | # FIXME: Make provide_with_pristine_tar take a upstream |
826 | 73 | info("Using uscan to look for the upstream tarball.") | 78 | # version string; it doesn't need the debian-specific data |
827 | 74 | r = os.system("uscan --upstream-version %s --force-download --rename " | 79 | version = Version("%s-1" % upstream_version) |
828 | 75 | "--package %s --watchfile %s --check-dirname-level 0 " | 80 | target_filename = self._tarball_path(package, upstream_version, |
829 | 76 | "--download --repack --destdir %s" % | 81 | target_dir) |
830 | 77 | (upstream_version, package, watch_file, target_dir)) | 82 | db = DistributionBranch(self.branch, None, tree=self.tree) |
831 | 78 | if r != 0: | 83 | if not db.has_upstream_version_in_packaging_branch(version): |
832 | 79 | info("uscan could not find the needed tarball.") | 84 | raise PackageVersionNotPresent(package, upstream_version, self) |
833 | 80 | return False | 85 | revid = db._revid_of_upstream_version_from_branch(version) |
834 | 81 | return True | 86 | if not db.has_pristine_tar_delta(revid): |
835 | 82 | 87 | raise PackageVersionNotPresent(package, upstream_version, self) | |
836 | 83 | 88 | info("Using pristine-tar to reconstruct the needed tarball.") | |
837 | 84 | def provide_with_pristine_tar(tree, branch, package, version, | 89 | db.reconstruct_pristine_tar(revid, package, version, target_filename) |
838 | 85 | target_filename): | 90 | |
839 | 86 | db = DistributionBranch(branch, None, tree=tree) | 91 | |
840 | 87 | if not db.has_upstream_version_in_packaging_branch(version): | 92 | class AptSource(UpstreamSource): |
841 | 88 | return False | 93 | """Upstream source that uses apt-source.""" |
842 | 89 | revid = db._revid_of_upstream_version_from_branch(version) | 94 | |
843 | 90 | if not db.has_pristine_tar_delta(revid): | 95 | def get_specific_version(self, package, upstream_version, target_dir, |
844 | 91 | return False | 96 | _apt_pkg=None): |
845 | 92 | info("Using pristine-tar to reconstruct the needed tarball.") | 97 | if _apt_pkg is None: |
846 | 93 | db.reconstruct_pristine_tar(revid, package, version, target_filename) | 98 | import apt_pkg |
847 | 94 | return True | 99 | else: |
848 | 95 | 100 | apt_pkg = _apt_pkg | |
849 | 96 | 101 | apt_pkg.init() | |
850 | 97 | def provide_with_get_orig_source(source_dir, fetch_dir, desired_tarball_name, | 102 | sources = apt_pkg.GetPkgSrcRecords() |
851 | 98 | target_dir): | 103 | sources.Restart() |
852 | 99 | info("Trying to use get-orig-source to retrieve needed tarball.") | 104 | info("Using apt to look for the upstream tarball.") |
853 | 100 | command = ["/usr/bin/make", "-f", "debian/rules", "get-orig-source"] | 105 | while sources.Lookup(package): |
854 | 101 | proc = subprocess.Popen(command, cwd=source_dir) | 106 | if upstream_version \ |
855 | 102 | ret = proc.wait() | 107 | == Version(sources.Version).upstream_version: |
856 | 103 | if ret != 0: | 108 | if self._run_apt_source(package, sources.Version, target_dir): |
857 | 104 | info("Trying to run get-orig-source rule failed") | 109 | return |
858 | 105 | return False | 110 | break |
859 | 106 | fetched_tarball = os.path.join(fetch_dir, desired_tarball_name) | 111 | info("apt could not find the needed tarball.") |
860 | 107 | if not os.path.exists(fetched_tarball): | 112 | raise PackageVersionNotPresent(package, upstream_version, self) |
861 | 108 | info("get-orig-source did not create %s" | 113 | |
862 | 109 | % desired_tarball_name) | 114 | def _get_command(self, package, version_str): |
863 | 110 | return False | 115 | return 'apt-get source -y --only-source --tar-only %s=%s' % \ |
864 | 111 | repack_tarball(fetched_tarball, desired_tarball_name, | 116 | (package, version_str) |
865 | 112 | target_dir=target_dir) | 117 | |
866 | 113 | return True | 118 | def _run_apt_source(self, package, version_str, target_dir): |
867 | 114 | 119 | command = self._get_command(package, version_str) | |
868 | 115 | 120 | proc = subprocess.Popen(command, shell=True, cwd=target_dir) | |
869 | 116 | def provide_from_other_branch(branch, revision, target_filename, | 121 | proc.wait() |
870 | 117 | tarball_base): | 122 | if proc.returncode != 0: |
871 | 118 | branch.lock_read() | 123 | return False |
872 | 119 | try: | 124 | return True |
873 | 120 | rev_tree = branch.repository.revision_tree(revision) | 125 | |
874 | 121 | export(rev_tree, target_filename, 'tgz', tarball_base) | 126 | |
875 | 122 | return True | 127 | class UpstreamBranchSource(UpstreamSource): |
876 | 123 | finally: | 128 | """Upstream source that uses the upstream branch.""" |
877 | 124 | branch.unlock() | 129 | |
878 | 125 | 130 | def __init__(self, upstream_branch, upstream_revision=None, | |
879 | 126 | 131 | fallback_revspec=None): | |
880 | 127 | def provide_by_split(tree, package, upstream_version, target_filename): | 132 | self.upstream_branch = upstream_branch |
881 | 128 | tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-") | 133 | self.upstream_revision = upstream_revision |
882 | 129 | try: | 134 | self.fallback_revspec = fallback_revspec |
883 | 130 | export_dir = os.path.join(tmpdir, | 135 | |
884 | 131 | "%s-%s" % (package, upstream_version)) | 136 | def _get_revision_id(self, version): |
885 | 132 | export(tree, export_dir, format="dir") | 137 | if self.upstream_revision is not None: |
886 | 133 | shutil.rmtree(os.path.join(export_dir, "debian")) | 138 | # Explicit revision id to use set |
887 | 134 | tar = tarfile.open(target_filename, "w:gz") | 139 | return self.upstream_revision |
888 | 135 | try: | 140 | revspec = get_snapshot_revision(version) |
889 | 136 | tar.add(export_dir, "%s-%s" % (package, upstream_version)) | 141 | if revspec is None: |
890 | 137 | finally: | 142 | revspec = self.fallback_revspec |
891 | 138 | tar.close() | 143 | if revspec is not None: |
892 | 139 | return True | 144 | return RevisionSpec.from_string( |
893 | 140 | finally: | 145 | revspec).as_revision_id(self.upstream_branch) |
894 | 141 | shutil.rmtree(tmpdir) | 146 | return self.upstream_branch.last_revision() |
895 | 147 | |||
896 | 148 | def get_specific_version(self, package, version, target_dir): | ||
897 | 149 | self.upstream_branch.lock_read() | ||
898 | 150 | try: | ||
899 | 151 | revid = self._get_revision_id(version) | ||
900 | 152 | info("Exporting upstream branch revision %s to create the tarball", | ||
901 | 153 | revid) | ||
902 | 154 | target_filename = self._tarball_path(package, version, target_dir) | ||
903 | 155 | tarball_base = "%s-%s" % (package, version) | ||
904 | 156 | rev_tree = self.upstream_branch.repository.revision_tree(revid) | ||
905 | 157 | export(rev_tree, target_filename, 'tgz', tarball_base) | ||
906 | 158 | finally: | ||
907 | 159 | self.upstream_branch.unlock() | ||
908 | 160 | |||
909 | 161 | |||
910 | 162 | class GetOrigSourceSource(UpstreamSource): | ||
911 | 163 | """Upstream source that uses the get-orig-source rule in debian/rules.""" | ||
912 | 164 | |||
913 | 165 | def __init__(self, tree, larstiq): | ||
914 | 166 | self.tree = tree | ||
915 | 167 | self.larstiq = larstiq | ||
916 | 168 | |||
917 | 169 | def _get_orig_source(self, source_dir, fetch_dir, desired_tarball_name, | ||
918 | 170 | target_dir): | ||
919 | 171 | info("Trying to use get-orig-source to retrieve needed tarball.") | ||
920 | 172 | command = ["/usr/bin/make", "-f", "debian/rules", "get-orig-source"] | ||
921 | 173 | proc = subprocess.Popen(command, cwd=source_dir) | ||
922 | 174 | ret = proc.wait() | ||
923 | 175 | if ret != 0: | ||
924 | 176 | info("Trying to run get-orig-source rule failed") | ||
925 | 177 | return False | ||
926 | 178 | fetched_tarball = os.path.join(fetch_dir, desired_tarball_name) | ||
927 | 179 | if not os.path.exists(fetched_tarball): | ||
928 | 180 | info("get-orig-source did not create %s", desired_tarball_name) | ||
929 | 181 | return False | ||
930 | 182 | repack_tarball(fetched_tarball, desired_tarball_name, | ||
931 | 183 | target_dir=target_dir) | ||
932 | 184 | return True | ||
933 | 185 | |||
934 | 186 | def get_specific_version(self, package, version, target_dir): | ||
935 | 187 | if self.larstiq: | ||
936 | 188 | rules_name = 'rules' | ||
937 | 189 | else: | ||
938 | 190 | rules_name = 'debian/rules' | ||
939 | 191 | rules_id = self.tree.path2id(rules_name) | ||
940 | 192 | if rules_id is not None: | ||
941 | 193 | desired_tarball_name = tarball_name(package, version) | ||
942 | 194 | tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-") | ||
943 | 195 | try: | ||
944 | 196 | base_export_dir = os.path.join(tmpdir, "export") | ||
945 | 197 | export_dir = base_export_dir | ||
946 | 198 | if self.larstiq: | ||
947 | 199 | os.mkdir(export_dir) | ||
948 | 200 | export_dir = os.path.join(export_dir, "debian") | ||
949 | 201 | export(self.tree, export_dir, format="dir") | ||
950 | 202 | if not self._get_orig_source(base_export_dir, tmpdir, | ||
951 | 203 | desired_tarball_name, target_dir): | ||
952 | 204 | raise PackageVersionNotPresent(package, version, self) | ||
953 | 205 | return | ||
954 | 206 | finally: | ||
955 | 207 | shutil.rmtree(tmpdir) | ||
956 | 208 | info("No debian/rules file to try and use for a get-orig-source rule") | ||
957 | 209 | raise PackageVersionNotPresent(package, version, self) | ||
958 | 210 | |||
959 | 211 | |||
960 | 212 | class UScanSource(UpstreamSource): | ||
961 | 213 | """Upstream source that uses uscan.""" | ||
962 | 214 | |||
963 | 215 | def __init__(self, tree, larstiq): | ||
964 | 216 | self.tree = tree | ||
965 | 217 | self.larstiq = larstiq | ||
966 | 218 | |||
967 | 219 | def _uscan(self, package, upstream_version, watch_file, target_dir): | ||
968 | 220 | info("Using uscan to look for the upstream tarball.") | ||
969 | 221 | r = os.system("uscan --upstream-version %s --force-download --rename " | ||
970 | 222 | "--package %s --watchfile %s --check-dirname-level 0 " | ||
971 | 223 | "--download --repack --destdir %s" % | ||
972 | 224 | (upstream_version, package, watch_file, target_dir)) | ||
973 | 225 | if r != 0: | ||
974 | 226 | info("uscan could not find the needed tarball.") | ||
975 | 227 | return False | ||
976 | 228 | return True | ||
977 | 229 | |||
978 | 230 | def _export_watchfile(self): | ||
979 | 231 | if self.larstiq: | ||
980 | 232 | watchfile = 'watch' | ||
981 | 233 | else: | ||
982 | 234 | watchfile = 'debian/watch' | ||
983 | 235 | watch_id = self.tree.path2id(watchfile) | ||
984 | 236 | if watch_id is None: | ||
985 | 237 | info("No watch file to use to retrieve upstream tarball.") | ||
986 | 238 | return None | ||
987 | 239 | (tmp, tempfilename) = tempfile.mkstemp() | ||
988 | 240 | try: | ||
989 | 241 | tmp = os.fdopen(tmp, 'wb') | ||
990 | 242 | watch = self.tree.get_file_text(watch_id) | ||
991 | 243 | tmp.write(watch) | ||
992 | 244 | finally: | ||
993 | 245 | tmp.close() | ||
994 | 246 | return tempfilename | ||
995 | 247 | |||
996 | 248 | def get_specific_version(self, package, version, target_dir): | ||
997 | 249 | tempfilename = self._export_watchfile() | ||
998 | 250 | if tempfilename is None: | ||
999 | 251 | raise PackageVersionNotPresent(package, version, self) | ||
1000 | 252 | try: | ||
1001 | 253 | if not self._uscan(package, version, tempfilename, | ||
1002 | 254 | target_dir): | ||
1003 | 255 | raise PackageVersionNotPresent(package, version, self) | ||
1004 | 256 | finally: | ||
1005 | 257 | os.unlink(tempfilename) | ||
1006 | 258 | |||
1007 | 259 | |||
1008 | 260 | class SelfSplitSource(UpstreamSource): | ||
1009 | 261 | |||
1010 | 262 | def __init__(self, tree): | ||
1011 | 263 | self.tree = tree | ||
1012 | 264 | |||
1013 | 265 | def _split(self, package, upstream_version, target_filename): | ||
1014 | 266 | tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-") | ||
1015 | 267 | try: | ||
1016 | 268 | export_dir = os.path.join(tmpdir, | ||
1017 | 269 | "%s-%s" % (package, upstream_version)) | ||
1018 | 270 | export(self.tree, export_dir, format="dir") | ||
1019 | 271 | shutil.rmtree(os.path.join(export_dir, "debian")) | ||
1020 | 272 | tar = tarfile.open(target_filename, "w:gz") | ||
1021 | 273 | try: | ||
1022 | 274 | tar.add(export_dir, "%s-%s" % (package, upstream_version)) | ||
1023 | 275 | finally: | ||
1024 | 276 | tar.close() | ||
1025 | 277 | finally: | ||
1026 | 278 | shutil.rmtree(tmpdir) | ||
1027 | 279 | |||
1028 | 280 | def get_specific_version(self, package, version, target_dir): | ||
1029 | 281 | info("Using the current branch without the 'debian' directory " | ||
1030 | 282 | "to create the tarball") | ||
1031 | 283 | self._split(package, version, | ||
1032 | 284 | self._tarball_path(package, version, target_dir)) | ||
1033 | 285 | |||
1034 | 286 | |||
1035 | 287 | class StackedUpstreamSource(UpstreamSource): | ||
1036 | 288 | """An upstream source that checks a list of other upstream sources. | ||
1037 | 289 | |||
1038 | 290 | The first source that can provide a tarball, wins. | ||
1039 | 291 | """ | ||
1040 | 292 | |||
1041 | 293 | def __init__(self, sources): | ||
1042 | 294 | self._sources = sources | ||
1043 | 295 | |||
1044 | 296 | def __repr__(self): | ||
1045 | 297 | return "%s(%r)" % (self.__class__.__name__, self._sources) | ||
1046 | 298 | |||
1047 | 299 | def get_specific_version(self, package, version, target_dir): | ||
1048 | 300 | for source in self._sources: | ||
1049 | 301 | try: | ||
1050 | 302 | return source.get_specific_version(package, version, target_dir) | ||
1051 | 303 | except PackageVersionNotPresent: | ||
1052 | 304 | pass | ||
1053 | 305 | raise PackageVersionNotPresent(package, version, self) | ||
1054 | 306 | |||
1055 | 307 | |||
1056 | 308 | def get_upstream_sources(tree, branch, larstiq=False, upstream_branch=None, | ||
1057 | 309 | upstream_revision=None, allow_split=False): | ||
1058 | 310 | """Get the list of upstream sources to retrieve upstream versions from. | ||
1059 | 311 | |||
1060 | 312 | :param tree: The tree that is being built from. | ||
1061 | 313 | :param branch: The branch that is being built from. | ||
1062 | 314 | :param larstiq: Whether the tree versions the root of ./debian. | ||
1063 | 315 | :param upstream_branch: An upstream branch that can be exported | ||
1064 | 316 | if needed. | ||
1065 | 317 | :param upstream_revision: The revision to use of the upstream branch | ||
1066 | 318 | if it is used. | ||
1067 | 319 | :param allow_split: Whether the provider can provide the tarball | ||
1068 | 320 | by exporting the branch and removing the "debian" dir. | ||
1069 | 321 | |||
1070 | 322 | """ | ||
1071 | 323 | sources = [ | ||
1072 | 324 | PristineTarSource(tree, branch), | ||
1073 | 325 | AptSource(), | ||
1074 | 326 | ] | ||
1075 | 327 | if upstream_branch is not None: | ||
1076 | 328 | sources.append( | ||
1077 | 329 | UpstreamBranchSource(upstream_branch, upstream_revision)) | ||
1078 | 330 | sources.extend([ | ||
1079 | 331 | GetOrigSourceSource(tree, larstiq), | ||
1080 | 332 | UScanSource(tree, larstiq), | ||
1081 | 333 | ]) | ||
1082 | 334 | if allow_split: | ||
1083 | 335 | sources.append(SelfSplitSource(tree)) | ||
1084 | 336 | return sources | ||
1085 | 142 | 337 | ||
1086 | 143 | 338 | ||
1087 | 144 | class UpstreamProvider(object): | 339 | class UpstreamProvider(object): |
1088 | @@ -148,40 +343,17 @@ | |||
1089 | 148 | instance using pristine-tar, or using apt. | 343 | instance using pristine-tar, or using apt. |
1090 | 149 | """ | 344 | """ |
1091 | 150 | 345 | ||
1095 | 151 | def __init__(self, tree, branch, package, version, store_dir, | 346 | def __init__(self, package, version, store_dir, sources): |
1093 | 152 | larstiq=False, upstream_branch=None, upstream_revision=None, | ||
1094 | 153 | allow_split=False): | ||
1096 | 154 | """Create an UpstreamProvider. | 347 | """Create an UpstreamProvider. |
1097 | 155 | 348 | ||
1098 | 156 | :param tree: The tree that is being built from. | ||
1099 | 157 | :param branch: The branch that is being built from. | ||
1100 | 158 | :param package: the name of the source package that is being built. | 349 | :param package: the name of the source package that is being built. |
1101 | 159 | :param version: the Version of the package that is being built. | 350 | :param version: the Version of the package that is being built. |
1102 | 160 | :param store_dir: A directory to cache the tarballs. | 351 | :param store_dir: A directory to cache the tarballs. |
1103 | 161 | :param larstiq: Whether the tree versions the root of ./debian. | ||
1104 | 162 | :param upstream_branch: An upstream branch that can be exported | ||
1105 | 163 | if needed. | ||
1106 | 164 | :param upstream_revision: The revision to use of the upstream branch | ||
1107 | 165 | if it is used. | ||
1108 | 166 | :param allow_split: Whether the provider can provide the tarball | ||
1109 | 167 | by exporting the branch and removing the "debian" dir. | ||
1110 | 168 | """ | 352 | """ |
1111 | 169 | self.tree = tree | ||
1112 | 170 | self.branch = branch | ||
1113 | 171 | self.package = package | 353 | self.package = package |
1114 | 172 | self.version = Version(version) | 354 | self.version = Version(version) |
1115 | 173 | self.store_dir = store_dir | 355 | self.store_dir = store_dir |
1127 | 174 | self.larstiq = larstiq | 356 | self.source = StackedUpstreamSource(sources) |
1117 | 175 | self.upstream_branch = upstream_branch | ||
1118 | 176 | self.upstream_revision = upstream_revision | ||
1119 | 177 | self.allow_split = allow_split | ||
1120 | 178 | # for testing | ||
1121 | 179 | self._apt_provider = provide_with_apt | ||
1122 | 180 | self._uscan_provider = provide_with_uscan | ||
1123 | 181 | self._pristine_provider = provide_with_pristine_tar | ||
1124 | 182 | self._orig_source_provider = provide_with_get_orig_source | ||
1125 | 183 | self._upstream_branch_provider = provide_from_other_branch | ||
1126 | 184 | self._split_provider = provide_by_split | ||
1128 | 185 | 357 | ||
1129 | 186 | def provide(self, target_dir): | 358 | def provide(self, target_dir): |
1130 | 187 | """Provide the upstream tarball any way possible. | 359 | """Provide the upstream tarball any way possible. |
1131 | @@ -214,24 +386,16 @@ | |||
1132 | 214 | if not self.already_exists_in_store(): | 386 | if not self.already_exists_in_store(): |
1133 | 215 | if not os.path.exists(self.store_dir): | 387 | if not os.path.exists(self.store_dir): |
1134 | 216 | os.makedirs(self.store_dir) | 388 | os.makedirs(self.store_dir) |
1147 | 217 | if self.provide_with_pristine_tar(self.store_dir): | 389 | try: |
1148 | 218 | pass | 390 | self.source.get_specific_version(self.package, |
1149 | 219 | elif self.provide_with_apt(self.store_dir): | 391 | self.version.upstream_version, target_dir) |
1150 | 220 | pass | 392 | except PackageVersionNotPresent: |
1151 | 221 | elif self.provide_from_upstream_branch(self.store_dir): | 393 | raise MissingUpstreamTarball(self._tarball_name()) |
1140 | 222 | pass | ||
1141 | 223 | elif self.provide_with_get_orig_source(self.store_dir): | ||
1142 | 224 | pass | ||
1143 | 225 | elif self.provide_with_uscan(self.store_dir): | ||
1144 | 226 | pass | ||
1145 | 227 | elif self.provide_from_self_by_split(self.store_dir): | ||
1146 | 228 | pass | ||
1152 | 229 | else: | 394 | else: |
1153 | 230 | info("Using the upstream tarball that is present in " | 395 | info("Using the upstream tarball that is present in " |
1154 | 231 | "%s" % self.store_dir) | 396 | "%s" % self.store_dir) |
1158 | 232 | if self.provide_from_store_dir(target_dir): | 397 | assert self.provide_from_store_dir(target_dir) |
1159 | 233 | return os.path.join(target_dir, self._tarball_name()) | 398 | return os.path.join(target_dir, self._tarball_name()) |
1157 | 234 | raise MissingUpstreamTarball(self._tarball_name()) | ||
1160 | 235 | 399 | ||
1161 | 236 | def already_exists_in_target(self, target_dir): | 400 | def already_exists_in_target(self, target_dir): |
1162 | 237 | return os.path.exists(os.path.join(target_dir, self._tarball_name())) | 401 | return os.path.exists(os.path.join(target_dir, self._tarball_name())) |
1163 | @@ -247,83 +411,8 @@ | |||
1164 | 247 | return True | 411 | return True |
1165 | 248 | return False | 412 | return False |
1166 | 249 | 413 | ||
1167 | 250 | def provide_with_apt(self, target_dir): | ||
1168 | 251 | return self._apt_provider(self.package, self.version.upstream_version, | ||
1169 | 252 | target_dir) | ||
1170 | 253 | |||
1171 | 254 | def provide_with_uscan(self, target_dir): | ||
1172 | 255 | if self.larstiq: | ||
1173 | 256 | watchfile = 'watch' | ||
1174 | 257 | else: | ||
1175 | 258 | watchfile = 'debian/watch' | ||
1176 | 259 | watch_id = self.tree.path2id(watchfile) | ||
1177 | 260 | if watch_id is None: | ||
1178 | 261 | info("No watch file to use to retrieve upstream tarball.") | ||
1179 | 262 | return False | ||
1180 | 263 | (tmp, tempfilename) = tempfile.mkstemp() | ||
1181 | 264 | try: | ||
1182 | 265 | tmp = os.fdopen(tmp, 'wb') | ||
1183 | 266 | watch = self.tree.get_file_text(watch_id) | ||
1184 | 267 | tmp.write(watch) | ||
1185 | 268 | finally: | ||
1186 | 269 | tmp.close() | ||
1187 | 270 | try: | ||
1188 | 271 | return self._uscan_provider(self.package, | ||
1189 | 272 | self.version.upstream_version, tempfilename, target_dir) | ||
1190 | 273 | finally: | ||
1191 | 274 | os.unlink(tempfilename) | ||
1192 | 275 | |||
1193 | 276 | def provide_with_pristine_tar(self, target_dir): | ||
1194 | 277 | target_filename = os.path.join(target_dir, self._tarball_name()) | ||
1195 | 278 | return self._pristine_provider(self.tree, self.branch, self.package, | ||
1196 | 279 | self.version, target_filename) | ||
1197 | 280 | |||
1198 | 281 | def provide_with_get_orig_source(self, target_dir): | ||
1199 | 282 | if self.larstiq: | ||
1200 | 283 | rules_name = 'rules' | ||
1201 | 284 | else: | ||
1202 | 285 | rules_name = 'debian/rules' | ||
1203 | 286 | rules_id = self.tree.path2id(rules_name) | ||
1204 | 287 | if rules_id is not None: | ||
1205 | 288 | desired_tarball_name = self._tarball_name() | ||
1206 | 289 | tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-") | ||
1207 | 290 | try: | ||
1208 | 291 | base_export_dir = os.path.join(tmpdir, "export") | ||
1209 | 292 | export_dir = base_export_dir | ||
1210 | 293 | if self.larstiq: | ||
1211 | 294 | os.mkdir(export_dir) | ||
1212 | 295 | export_dir = os.path.join(export_dir, "debian") | ||
1213 | 296 | export(self.tree, export_dir, format="dir") | ||
1214 | 297 | return self._orig_source_provider(base_export_dir, tmpdir, | ||
1215 | 298 | desired_tarball_name, target_dir) | ||
1216 | 299 | finally: | ||
1217 | 300 | shutil.rmtree(tmpdir) | ||
1218 | 301 | info("No debian/rules file to try and use for a get-orig-source " | ||
1219 | 302 | "rule") | ||
1220 | 303 | return False | ||
1221 | 304 | |||
1222 | 305 | def _tarball_name(self): | 414 | def _tarball_name(self): |
1244 | 306 | return "%s_%s.orig.tar.gz" % (self.package, | 415 | return tarball_name(self.package, self.version.upstream_version) |
1224 | 307 | self.version.upstream_version) | ||
1225 | 308 | |||
1226 | 309 | def provide_from_upstream_branch(self, target_dir): | ||
1227 | 310 | if self.upstream_branch is None: | ||
1228 | 311 | return False | ||
1229 | 312 | assert self.upstream_revision is not None | ||
1230 | 313 | info("Exporting the upstream branch to create the tarball") | ||
1231 | 314 | target_filename = os.path.join(target_dir, self._tarball_name()) | ||
1232 | 315 | tarball_base = "%s-%s" % (self.package, self.version.upstream_version) | ||
1233 | 316 | return self._upstream_branch_provider(self.upstream_branch, | ||
1234 | 317 | self.upstream_revision, target_filename, tarball_base) | ||
1235 | 318 | |||
1236 | 319 | def provide_from_self_by_split(self, target_dir): | ||
1237 | 320 | if not self.allow_split: | ||
1238 | 321 | return False | ||
1239 | 322 | info("Using the current branch without the 'debian' directory " | ||
1240 | 323 | "to create the tarball") | ||
1241 | 324 | target_filename = os.path.join(target_dir, self._tarball_name()) | ||
1242 | 325 | return self._split_provider(self.tree, self.package, | ||
1243 | 326 | self.version.upstream_version, target_filename) | ||
1245 | 327 | 416 | ||
1246 | 328 | 417 | ||
1247 | 329 | class _MissingUpstreamProvider(UpstreamProvider): | 418 | class _MissingUpstreamProvider(UpstreamProvider): |
1248 | @@ -347,6 +436,7 @@ | |||
1249 | 347 | f.write("I am a tarball, honest\n") | 436 | f.write("I am a tarball, honest\n") |
1250 | 348 | f.close() | 437 | f.close() |
1251 | 349 | 438 | ||
1252 | 439 | |||
1253 | 350 | class _SimpleUpstreamProvider(UpstreamProvider): | 440 | class _SimpleUpstreamProvider(UpstreamProvider): |
1254 | 351 | """For tests""" | 441 | """For tests""" |
1255 | 352 | 442 |
The attached patch adds a new class UpstreamSource (for lack of a applicable) :
better name) that represents a source of upstream tarballs.
UpstreamSources currently only can retrieve specific version tarballs,
but the idea is that they'll in the future also be able to (where
possible/
* retrieve the last upstream version string
* retrieve the last upstream version tarball
* return the revid matching a particular upstream version
* list the available upstream versions
It also makes bzr-builddeb support retrieval of upstream snapshot
versions again ("1.0~bzr13").
Cheers,
Jelmer