Merge lp:~jelmer/bzr-builddeb/pristine-tar-refactor into lp:bzr-builddeb
- pristine-tar-refactor
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | James Westby |
Approved revision: | no longer in the source branch. |
Merged at revision: | 563 |
Proposed branch: | lp:~jelmer/bzr-builddeb/pristine-tar-refactor |
Merge into: | lp:bzr-builddeb |
Diff against target: |
688 lines (+281/-233) 7 files modified
cmds.py (+3/-1) errors.py (+0/-7) import_dsc.py (+7/-30) tests/test_upstream.py (+3/-2) upstream/__init__.py (+0/-141) upstream/pristinetar.py (+267/-0) util.py (+1/-52) |
To merge this branch: | bzr merge lp:~jelmer/bzr-builddeb/pristine-tar-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby | Approve | ||
Review via email: mp+63381@code.launchpad.net |
Commit message
Description of the change
Move all pristine-tar related code into upstream/
This makes import_dsc.py a bit smaller, and makes it a bit easier to understand how pristine tar is involved. I'm looking at this so we can use pristine tar in bzr-builder too.
To post a comment you must log in.
Revision history for this message
James Westby (james-w) : | # |
review:
Approve
- 563. By Jelmer Vernooij
-
Merge refactoring of pristine tar upstream source.
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 2011-05-16 14:21:31 +0000 |
3 | +++ cmds.py 2011-06-03 13:28:25 +0000 |
4 | @@ -93,7 +93,6 @@ |
5 | from bzrlib.plugins.builddeb.upstream import ( |
6 | AptSource, |
7 | GetOrigSourceSource, |
8 | - PristineTarSource, |
9 | SelfSplitSource, |
10 | TarfileSource, |
11 | UScanSource, |
12 | @@ -103,6 +102,9 @@ |
13 | LazyUpstreamBranchSource, |
14 | UpstreamBranchSource, |
15 | ) |
16 | +from bzrlib.plugins.builddeb.upstream.pristinetar import ( |
17 | + PristineTarSource, |
18 | + ) |
19 | from bzrlib.plugins.builddeb.util import ( |
20 | FORMAT_3_0_QUILT, |
21 | FORMAT_3_0_NATIVE, |
22 | |
23 | === modified file 'errors.py' |
24 | --- errors.py 2011-05-15 17:21:54 +0000 |
25 | +++ errors.py 2011-06-03 13:28:25 +0000 |
26 | @@ -163,13 +163,6 @@ |
27 | BzrError.__init__(self, location=location) |
28 | |
29 | |
30 | -class PristineTarError(BzrError): |
31 | - _fmt = 'There was an error using pristine-tar: %(error)s.' |
32 | - |
33 | - def __init__(self, error): |
34 | - BzrError.__init__(self, error=error) |
35 | - |
36 | - |
37 | class SharedUpstreamConflictsWithTargetPackaging(BzrError): |
38 | _fmt = ('The upstream branches for the merge source and target have ' |
39 | 'diverged. Unfortunately, the attempt to fix this problem ' |
40 | |
41 | === modified file 'import_dsc.py' |
42 | --- import_dsc.py 2011-04-29 12:54:58 +0000 |
43 | +++ import_dsc.py 2011-06-03 13:28:25 +0000 |
44 | @@ -25,9 +25,6 @@ |
45 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
46 | # |
47 | |
48 | -from base64 import ( |
49 | - standard_b64encode, |
50 | - ) |
51 | |
52 | import os |
53 | import re |
54 | @@ -74,19 +71,18 @@ |
55 | FORMAT_3_0_NATIVE, |
56 | export, |
57 | get_commit_info_from_changelog, |
58 | - make_pristine_tar_delta, |
59 | md5sum_filename, |
60 | open_file_via_transport, |
61 | open_transport, |
62 | safe_decode, |
63 | subprocess_setup, |
64 | ) |
65 | -from bzrlib.plugins.builddeb.upstream import ( |
66 | - PristineTarSource, |
67 | - ) |
68 | from bzrlib.plugins.builddeb.upstream.branch import ( |
69 | UpstreamBranchSource, |
70 | ) |
71 | +from bzrlib.plugins.builddeb.upstream.pristinetar import ( |
72 | + PristineTarSource, |
73 | + ) |
74 | |
75 | |
76 | class DscCache(object): |
77 | @@ -912,16 +908,12 @@ |
78 | self.upstream_tree.set_parent_ids(upstream_parents) |
79 | revprops = {"deb-md5": md5} |
80 | if upstream_tarball is not None: |
81 | - delta = self.make_pristine_tar_delta( |
82 | + delta_revprops = self.pristine_tar_source.create_delta_revprops( |
83 | self.upstream_tree, upstream_tarball) |
84 | - uuencoded = standard_b64encode(delta) |
85 | - if upstream_tarball.endswith(".tar.bz2"): |
86 | - revprops["deb-pristine-delta-bz2"] = uuencoded |
87 | - else: |
88 | - revprops["deb-pristine-delta"] = uuencoded |
89 | + revprops.update(delta_revprops) |
90 | if author is not None: |
91 | revprops['authors'] = author |
92 | - timezone=None |
93 | + timezone = None |
94 | if timestamp is not None: |
95 | timezone = timestamp[1] |
96 | timestamp = timestamp[0] |
97 | @@ -1075,7 +1067,7 @@ |
98 | if message is None: |
99 | message = 'Import packaging changes for version %s' % \ |
100 | (str(version),) |
101 | - revprops={"deb-md5":md5} |
102 | + revprops={"deb-md5": md5} |
103 | if native: |
104 | revprops['deb-native'] = "True" |
105 | if authors: |
106 | @@ -1470,21 +1462,6 @@ |
107 | finally: |
108 | shutil.rmtree(tempdir) |
109 | |
110 | - def make_pristine_tar_delta(self, tree, tarball_path): |
111 | - tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-") |
112 | - try: |
113 | - dest = os.path.join(tmpdir, "orig") |
114 | - tree.lock_read() |
115 | - try: |
116 | - for (dp, ie) in tree.inventory.iter_entries(): |
117 | - ie._read_tree_state(dp, tree) |
118 | - export(tree, dest, format='dir') |
119 | - finally: |
120 | - tree.unlock() |
121 | - return make_pristine_tar_delta(dest, tarball_path) |
122 | - finally: |
123 | - shutil.rmtree(tmpdir) |
124 | - |
125 | |
126 | class SourceExtractor(object): |
127 | """A class to extract a source package to its constituent parts""" |
128 | |
129 | === modified file 'tests/test_upstream.py' |
130 | --- tests/test_upstream.py 2011-04-29 12:34:12 +0000 |
131 | +++ tests/test_upstream.py 2011-06-03 13:28:25 +0000 |
132 | @@ -48,13 +48,11 @@ |
133 | ) |
134 | from bzrlib.plugins.builddeb.upstream import ( |
135 | AptSource, |
136 | - PristineTarSource, |
137 | StackedUpstreamSource, |
138 | TarfileSource, |
139 | UpstreamProvider, |
140 | UpstreamSource, |
141 | UScanSource, |
142 | - Version, |
143 | extract_tarball_version, |
144 | ) |
145 | from bzrlib.plugins.builddeb.upstream.branch import ( |
146 | @@ -66,6 +64,9 @@ |
147 | upstream_tag_to_version, |
148 | upstream_version_add_revision |
149 | ) |
150 | +from bzrlib.plugins.builddeb.upstream.pristinetar import ( |
151 | + PristineTarSource, |
152 | + ) |
153 | |
154 | |
155 | # Unless bug #712474 is fixed and available in the minimum bzrlib required, we |
156 | |
157 | === modified file 'upstream/__init__.py' |
158 | --- upstream/__init__.py 2011-04-29 12:34:12 +0000 |
159 | +++ upstream/__init__.py 2011-06-03 13:28:25 +0000 |
160 | @@ -25,21 +25,12 @@ |
161 | import tarfile |
162 | import tempfile |
163 | |
164 | -from base64 import ( |
165 | - standard_b64decode, |
166 | - ) |
167 | - |
168 | - |
169 | try: |
170 | from debian.changelog import Version |
171 | except ImportError: |
172 | # Prior to 0.1.15 the debian module was called debian_bundle |
173 | from debian_bundle.changelog import Version |
174 | |
175 | -from bzrlib.errors import ( |
176 | - NoSuchRevision, |
177 | - NoSuchTag, |
178 | - ) |
179 | from bzrlib.trace import ( |
180 | note, |
181 | warning, |
182 | @@ -48,14 +39,11 @@ |
183 | from bzrlib.plugins.builddeb.errors import ( |
184 | MissingUpstreamTarball, |
185 | PackageVersionNotPresent, |
186 | - PerFileTimestampsNotSupported, |
187 | - PristineTarError, |
188 | WatchFileMissing, |
189 | ) |
190 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball |
191 | from bzrlib.plugins.builddeb.util import ( |
192 | export, |
193 | - reconstruct_pristine_tar, |
194 | tarball_name, |
195 | ) |
196 | |
197 | @@ -106,135 +94,6 @@ |
198 | format=format)) |
199 | |
200 | |
201 | -class PristineTarSource(UpstreamSource): |
202 | - """Source that uses the pristine-tar revisions in the packaging branch.""" |
203 | - |
204 | - def __init__(self, tree, branch): |
205 | - self.branch = branch |
206 | - self.tree = tree |
207 | - |
208 | - def tag_name(self, version, distro=None): |
209 | - """Gets the tag name for the upstream part of version. |
210 | - |
211 | - :param version: the Version object to extract the upstream |
212 | - part of the version number from. |
213 | - :return: a String with the name of the tag. |
214 | - """ |
215 | - assert isinstance(version, str) |
216 | - if distro is None: |
217 | - return "upstream-" + version |
218 | - return "upstream-%s-%s" % (distro, version) |
219 | - |
220 | - def fetch_tarball(self, package, version, target_dir): |
221 | - revid = self.version_as_revision(package, version) |
222 | - try: |
223 | - rev = self.branch.repository.get_revision(revid) |
224 | - except NoSuchRevision: |
225 | - raise PackageVersionNotPresent(package, version, self) |
226 | - note("Using pristine-tar to reconstruct the needed tarball.") |
227 | - if self.has_pristine_tar_delta(rev): |
228 | - format = self.pristine_tar_format(rev) |
229 | - else: |
230 | - format = 'gz' |
231 | - target_filename = self._tarball_path(package, version, |
232 | - target_dir, format=format) |
233 | - try: |
234 | - self.reconstruct_pristine_tar(revid, package, version, target_filename) |
235 | - except PristineTarError: |
236 | - raise PackageVersionNotPresent(package, version, self) |
237 | - except PerFileTimestampsNotSupported: |
238 | - raise PackageVersionNotPresent(package, version, self) |
239 | - return target_filename |
240 | - |
241 | - def _has_version(self, tag_name, md5=None): |
242 | - if not self.branch.tags.has_tag(tag_name): |
243 | - return False |
244 | - revid = self.branch.tags.lookup_tag(tag_name) |
245 | - self.branch.lock_read() |
246 | - try: |
247 | - graph = self.branch.repository.get_graph() |
248 | - if not graph.is_ancestor(revid, self.branch.last_revision()): |
249 | - return False |
250 | - finally: |
251 | - self.branch.unlock() |
252 | - if md5 is None: |
253 | - return True |
254 | - rev = self.branch.repository.get_revision(revid) |
255 | - try: |
256 | - return rev.properties['deb-md5'] == md5 |
257 | - except KeyError: |
258 | - warning("tag %s present in branch, but there is no " |
259 | - "associated 'deb-md5' property" % tag_name) |
260 | - return True |
261 | - |
262 | - def version_as_revision(self, package, version): |
263 | - assert isinstance(version, str) |
264 | - for tag_name in self.possible_tag_names(version): |
265 | - if self._has_version(tag_name): |
266 | - return self.branch.tags.lookup_tag(tag_name) |
267 | - tag_name = self.tag_name(version) |
268 | - try: |
269 | - return self.branch.tags.lookup_tag(tag_name) |
270 | - except NoSuchTag: |
271 | - raise PackageVersionNotPresent(package, version, self) |
272 | - |
273 | - def has_version(self, package, version, md5=None): |
274 | - assert isinstance(version, str), str(type(version)) |
275 | - for tag_name in self.possible_tag_names(version): |
276 | - if self._has_version(tag_name, md5=md5): |
277 | - return True |
278 | - return False |
279 | - |
280 | - def possible_tag_names(self, version): |
281 | - assert isinstance(version, str) |
282 | - tags = [self.tag_name(version), |
283 | - self.tag_name(version, distro="debian"), |
284 | - self.tag_name(version, distro="ubuntu"), |
285 | - "upstream/%s" % version] |
286 | - return tags |
287 | - |
288 | - def has_pristine_tar_delta(self, rev): |
289 | - return ('deb-pristine-delta' in rev.properties |
290 | - or 'deb-pristine-delta-bz2' in rev.properties) |
291 | - |
292 | - def pristine_tar_format(self, rev): |
293 | - if 'deb-pristine-delta' in rev.properties: |
294 | - return 'gz' |
295 | - elif 'deb-pristine-delta-bz2' in rev.properties: |
296 | - return 'bz2' |
297 | - assert self.has_pristine_tar_delta(rev) |
298 | - raise AssertionError("Not handled new delta type in " |
299 | - "pristine_tar_format") |
300 | - |
301 | - def pristine_tar_delta(self, rev): |
302 | - if 'deb-pristine-delta' in rev.properties: |
303 | - uuencoded = rev.properties['deb-pristine-delta'] |
304 | - elif 'deb-pristine-delta-bz2' in rev.properties: |
305 | - uuencoded = rev.properties['deb-pristine-delta-bz2'] |
306 | - else: |
307 | - assert self.has_pristine_tar_delta(rev) |
308 | - raise AssertionError("Not handled new delta type in " |
309 | - "pristine_tar_delta") |
310 | - return standard_b64decode(uuencoded) |
311 | - |
312 | - def reconstruct_pristine_tar(self, revid, package, version, |
313 | - dest_filename): |
314 | - """Reconstruct a pristine-tar tarball from a bzr revision.""" |
315 | - tree = self.branch.repository.revision_tree(revid) |
316 | - tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-") |
317 | - try: |
318 | - dest = os.path.join(tmpdir, "orig") |
319 | - rev = self.branch.repository.get_revision(revid) |
320 | - if self.has_pristine_tar_delta(rev): |
321 | - export(tree, dest, format='dir') |
322 | - delta = self.pristine_tar_delta(rev) |
323 | - reconstruct_pristine_tar(dest, delta, dest_filename) |
324 | - else: |
325 | - export(tree, dest_filename, require_per_file_timestamps=True) |
326 | - finally: |
327 | - shutil.rmtree(tmpdir) |
328 | - |
329 | - |
330 | class AptSource(UpstreamSource): |
331 | """Upstream source that uses apt-source.""" |
332 | |
333 | |
334 | === added file 'upstream/pristinetar.py' |
335 | --- upstream/pristinetar.py 1970-01-01 00:00:00 +0000 |
336 | +++ upstream/pristinetar.py 2011-06-03 13:28:25 +0000 |
337 | @@ -0,0 +1,267 @@ |
338 | +# pristinetar.py -- Providers of upstream source |
339 | +# Copyright (C) 2009-2011 Canonical Ltd. |
340 | +# Copyright (C) 2009 Jelmer Vernooij <jelmer@debian.org> |
341 | +# |
342 | +# This file is part of bzr-builddeb. |
343 | +# |
344 | +# bzr-builddeb is free software; you can redistribute it and/or modify |
345 | +# it under the terms of the GNU General Public License as published by |
346 | +# the Free Software Foundation; either version 2 of the License, or |
347 | +# (at your option) any later version. |
348 | +# |
349 | +# bzr-builddeb is distributed in the hope that it will be useful, |
350 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
351 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
352 | +# GNU General Public License for more details. |
353 | +# |
354 | +# You should have received a copy of the GNU General Public License |
355 | +# along with bzr-builddeb; if not, write to the Free Software |
356 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
357 | + |
358 | +from base64 import ( |
359 | + standard_b64decode, |
360 | + standard_b64encode, |
361 | + ) |
362 | +import errno |
363 | +import os |
364 | +import shutil |
365 | +import subprocess |
366 | +import tempfile |
367 | + |
368 | +from bzrlib.plugins.builddeb.errors import ( |
369 | + PackageVersionNotPresent, |
370 | + PerFileTimestampsNotSupported, |
371 | + ) |
372 | +from bzrlib.plugins.builddeb.upstream import UpstreamSource |
373 | +from bzrlib.plugins.builddeb.util import ( |
374 | + export, |
375 | + subprocess_setup, |
376 | + ) |
377 | + |
378 | +from bzrlib import osutils |
379 | +from bzrlib.errors import ( |
380 | + BzrError, |
381 | + NoSuchRevision, |
382 | + NoSuchTag, |
383 | + ) |
384 | +from bzrlib.trace import ( |
385 | + note, |
386 | + warning, |
387 | + ) |
388 | + |
389 | + |
390 | +class PristineTarError(BzrError): |
391 | + _fmt = 'There was an error using pristine-tar: %(error)s.' |
392 | + |
393 | + def __init__(self, error): |
394 | + BzrError.__init__(self, error=error) |
395 | + |
396 | + |
397 | +def reconstruct_pristine_tar(dest, delta, dest_filename): |
398 | + """Reconstruct a pristine tarball from a directory and a delta. |
399 | + |
400 | + :param dest: Directory to pack |
401 | + :param delta: pristine-tar delta |
402 | + :param dest_filename: Destination filename |
403 | + """ |
404 | + command = ["pristine-tar", "gentar", "-", |
405 | + os.path.abspath(dest_filename)] |
406 | + try: |
407 | + proc = subprocess.Popen(command, stdin=subprocess.PIPE, |
408 | + cwd=dest, preexec_fn=subprocess_setup, |
409 | + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
410 | + except OSError, e: |
411 | + if e.errno == errno.ENOENT: |
412 | + raise PristineTarError("pristine-tar is not installed") |
413 | + else: |
414 | + raise |
415 | + (stdout, stderr) = proc.communicate(delta) |
416 | + if proc.returncode != 0: |
417 | + raise PristineTarError("Generating tar from delta failed: %s" % stdout) |
418 | + |
419 | + |
420 | +def make_pristine_tar_delta(dest, tarball_path): |
421 | + """Create a pristine-tar delta for a tarball. |
422 | + |
423 | + :param dest: Directory to generate pristine tar delta for |
424 | + :param tarball_path: Path to the tarball |
425 | + :return: pristine-tarball |
426 | + """ |
427 | + # If tarball_path is relative, the cwd=dest parameter to Popen will make |
428 | + # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we |
429 | + # assume local paths. |
430 | + tarball_path = osutils.abspath(tarball_path) |
431 | + command = ["pristine-tar", "gendelta", tarball_path, "-"] |
432 | + try: |
433 | + proc = subprocess.Popen(command, stdout=subprocess.PIPE, |
434 | + cwd=dest, preexec_fn=subprocess_setup, |
435 | + stderr=subprocess.PIPE) |
436 | + except OSError, e: |
437 | + if e.errno == errno.ENOENT: |
438 | + raise PristineTarError("pristine-tar is not installed") |
439 | + else: |
440 | + raise |
441 | + (stdout, stderr) = proc.communicate() |
442 | + if proc.returncode != 0: |
443 | + raise PristineTarError("Generating delta from tar failed: %s" % stderr) |
444 | + return stdout |
445 | + |
446 | + |
447 | +class PristineTarSource(UpstreamSource): |
448 | + """Source that uses the pristine-tar revisions in the packaging branch.""" |
449 | + |
450 | + def __init__(self, tree, branch): |
451 | + self.branch = branch |
452 | + self.tree = tree |
453 | + |
454 | + def tag_name(self, version, distro=None): |
455 | + """Gets the tag name for the upstream part of version. |
456 | + |
457 | + :param version: the Version object to extract the upstream |
458 | + part of the version number from. |
459 | + :return: a String with the name of the tag. |
460 | + """ |
461 | + assert isinstance(version, str) |
462 | + if distro is None: |
463 | + return "upstream-" + version |
464 | + return "upstream-%s-%s" % (distro, version) |
465 | + |
466 | + def fetch_tarball(self, package, version, target_dir): |
467 | + revid = self.version_as_revision(package, version) |
468 | + try: |
469 | + rev = self.branch.repository.get_revision(revid) |
470 | + except NoSuchRevision: |
471 | + raise PackageVersionNotPresent(package, version, self) |
472 | + note("Using pristine-tar to reconstruct the needed tarball.") |
473 | + if self.has_pristine_tar_delta(rev): |
474 | + format = self.pristine_tar_format(rev) |
475 | + else: |
476 | + format = 'gz' |
477 | + target_filename = self._tarball_path(package, version, |
478 | + target_dir, format=format) |
479 | + try: |
480 | + self.reconstruct_pristine_tar(revid, package, version, target_filename) |
481 | + except PristineTarError: |
482 | + raise PackageVersionNotPresent(package, version, self) |
483 | + except PerFileTimestampsNotSupported: |
484 | + raise PackageVersionNotPresent(package, version, self) |
485 | + return target_filename |
486 | + |
487 | + def _has_version(self, tag_name, md5=None): |
488 | + if not self.branch.tags.has_tag(tag_name): |
489 | + return False |
490 | + revid = self.branch.tags.lookup_tag(tag_name) |
491 | + self.branch.lock_read() |
492 | + try: |
493 | + graph = self.branch.repository.get_graph() |
494 | + if not graph.is_ancestor(revid, self.branch.last_revision()): |
495 | + return False |
496 | + finally: |
497 | + self.branch.unlock() |
498 | + if md5 is None: |
499 | + return True |
500 | + rev = self.branch.repository.get_revision(revid) |
501 | + try: |
502 | + return rev.properties['deb-md5'] == md5 |
503 | + except KeyError: |
504 | + warning("tag %s present in branch, but there is no " |
505 | + "associated 'deb-md5' property" % tag_name) |
506 | + return True |
507 | + |
508 | + def version_as_revision(self, package, version): |
509 | + assert isinstance(version, str) |
510 | + for tag_name in self.possible_tag_names(version): |
511 | + if self._has_version(tag_name): |
512 | + return self.branch.tags.lookup_tag(tag_name) |
513 | + tag_name = self.tag_name(version) |
514 | + try: |
515 | + return self.branch.tags.lookup_tag(tag_name) |
516 | + except NoSuchTag: |
517 | + raise PackageVersionNotPresent(package, version, self) |
518 | + |
519 | + def has_version(self, package, version, md5=None): |
520 | + assert isinstance(version, str), str(type(version)) |
521 | + for tag_name in self.possible_tag_names(version): |
522 | + if self._has_version(tag_name, md5=md5): |
523 | + return True |
524 | + return False |
525 | + |
526 | + def possible_tag_names(self, version): |
527 | + assert isinstance(version, str) |
528 | + tags = [self.tag_name(version), |
529 | + self.tag_name(version, distro="debian"), |
530 | + self.tag_name(version, distro="ubuntu"), |
531 | + "upstream/%s" % version] |
532 | + return tags |
533 | + |
534 | + def has_pristine_tar_delta(self, rev): |
535 | + return ('deb-pristine-delta' in rev.properties |
536 | + or 'deb-pristine-delta-bz2' in rev.properties) |
537 | + |
538 | + def pristine_tar_format(self, rev): |
539 | + if 'deb-pristine-delta' in rev.properties: |
540 | + return 'gz' |
541 | + elif 'deb-pristine-delta-bz2' in rev.properties: |
542 | + return 'bz2' |
543 | + assert self.has_pristine_tar_delta(rev) |
544 | + raise AssertionError("Not handled new delta type in " |
545 | + "pristine_tar_format") |
546 | + |
547 | + def pristine_tar_delta(self, rev): |
548 | + if 'deb-pristine-delta' in rev.properties: |
549 | + uuencoded = rev.properties['deb-pristine-delta'] |
550 | + elif 'deb-pristine-delta-bz2' in rev.properties: |
551 | + uuencoded = rev.properties['deb-pristine-delta-bz2'] |
552 | + else: |
553 | + assert self.has_pristine_tar_delta(rev) |
554 | + raise AssertionError("Not handled new delta type in " |
555 | + "pristine_tar_delta") |
556 | + return standard_b64decode(uuencoded) |
557 | + |
558 | + def reconstruct_pristine_tar(self, revid, package, version, |
559 | + dest_filename): |
560 | + """Reconstruct a pristine-tar tarball from a bzr revision.""" |
561 | + tree = self.branch.repository.revision_tree(revid) |
562 | + tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-") |
563 | + try: |
564 | + dest = os.path.join(tmpdir, "orig") |
565 | + rev = self.branch.repository.get_revision(revid) |
566 | + if self.has_pristine_tar_delta(rev): |
567 | + export(tree, dest, format='dir') |
568 | + delta = self.pristine_tar_delta(rev) |
569 | + reconstruct_pristine_tar(dest, delta, dest_filename) |
570 | + else: |
571 | + export(tree, dest_filename, require_per_file_timestamps=True) |
572 | + finally: |
573 | + shutil.rmtree(tmpdir) |
574 | + |
575 | + def make_pristine_tar_delta(self, tree, tarball_path): |
576 | + tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-") |
577 | + try: |
578 | + dest = os.path.join(tmpdir, "orig") |
579 | + tree.lock_read() |
580 | + try: |
581 | + for (dp, ie) in tree.inventory.iter_entries(): |
582 | + ie._read_tree_state(dp, tree) |
583 | + export(tree, dest, format='dir') |
584 | + finally: |
585 | + tree.unlock() |
586 | + return make_pristine_tar_delta(dest, tarball_path) |
587 | + finally: |
588 | + shutil.rmtree(tmpdir) |
589 | + |
590 | + def create_delta_revprops(self, tree, tarball): |
591 | + """Create the revision properties with the pristine tar delta. |
592 | + |
593 | + :param tree: Bazaar Tree to diff against |
594 | + :param tarball: The pristine tarball |
595 | + :return: Dictionary with extra revision properties |
596 | + """ |
597 | + ret = {} |
598 | + delta = self.make_pristine_tar_delta(tree, tarball) |
599 | + uuencoded = standard_b64encode(delta) |
600 | + if tarball.endswith(".tar.bz2"): |
601 | + ret["deb-pristine-delta-bz2"] = uuencoded |
602 | + else: |
603 | + ret["deb-pristine-delta"] = uuencoded |
604 | + return ret |
605 | |
606 | === modified file 'util.py' |
607 | --- util.py 2011-04-08 18:47:10 +0000 |
608 | +++ util.py 2011-06-03 13:28:25 +0000 |
609 | @@ -22,10 +22,8 @@ |
610 | import hashlib as md5 |
611 | except ImportError: |
612 | import md5 |
613 | -import errno |
614 | import signal |
615 | import shutil |
616 | -import subprocess |
617 | import tempfile |
618 | import os |
619 | import re |
620 | @@ -43,7 +41,6 @@ |
621 | from bzrlib import ( |
622 | bugtracker, |
623 | errors, |
624 | - osutils, |
625 | urlutils, |
626 | version_info as bzr_version_info, |
627 | ) |
628 | @@ -69,7 +66,6 @@ |
629 | AddChangelogError, |
630 | InconsistentSourceFormatError, |
631 | NoPreviousUpload, |
632 | - PristineTarError, |
633 | UnableToFindPreviousUpload, |
634 | UnparseableChangelog, |
635 | ) |
636 | @@ -686,51 +682,4 @@ |
637 | return BUILD_TYPE_NORMAL |
638 | |
639 | |
640 | -def reconstruct_pristine_tar(dest, delta, dest_filename): |
641 | - """Reconstruct a pristine tarball from a directory and a delta. |
642 | - |
643 | - :param dest: Directory to pack |
644 | - :param delta: pristine-tar delta |
645 | - :param dest_filename: Destination filename |
646 | - """ |
647 | - command = ["pristine-tar", "gentar", "-", |
648 | - os.path.abspath(dest_filename)] |
649 | - try: |
650 | - proc = subprocess.Popen(command, stdin=subprocess.PIPE, |
651 | - cwd=dest, preexec_fn=subprocess_setup, |
652 | - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
653 | - except OSError, e: |
654 | - if e.errno == errno.ENOENT: |
655 | - raise PristineTarError("pristine-tar is not installed") |
656 | - else: |
657 | - raise |
658 | - (stdout, stderr) = proc.communicate(delta) |
659 | - if proc.returncode != 0: |
660 | - raise PristineTarError("Generating tar from delta failed: %s" % stdout) |
661 | - |
662 | - |
663 | -def make_pristine_tar_delta(dest, tarball_path): |
664 | - """Create a pristine-tar delta for a tarball. |
665 | - |
666 | - :param dest: Directory to generate pristine tar delta for |
667 | - :param tarball_path: Path to the tarball |
668 | - :return: pristine-tarball |
669 | - """ |
670 | - # If tarball_path is relative, the cwd=dest parameter to Popen will make |
671 | - # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we |
672 | - # assume local paths. |
673 | - tarball_path = osutils.abspath(tarball_path) |
674 | - command = ["pristine-tar", "gendelta", tarball_path, "-"] |
675 | - try: |
676 | - proc = subprocess.Popen(command, stdout=subprocess.PIPE, |
677 | - cwd=dest, preexec_fn=subprocess_setup, |
678 | - stderr=subprocess.PIPE) |
679 | - except OSError, e: |
680 | - if e.errno == errno.ENOENT: |
681 | - raise PristineTarError("pristine-tar is not installed") |
682 | - else: |
683 | - raise |
684 | - (stdout, stderr) = proc.communicate() |
685 | - if proc.returncode != 0: |
686 | - raise PristineTarError("Generating delta from tar failed: %s" % stderr) |
687 | - return stdout |
688 | + |