Merge lp:~jelmer/bzr-builddeb/pristine-tar-refactor into lp:bzr-builddeb

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
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+63381@code.launchpad.net

Description of the change

Move all pristine-tar related code into upstream/pristinetar.py.

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
=== modified file 'cmds.py'
--- cmds.py 2011-05-16 14:21:31 +0000
+++ cmds.py 2011-06-03 13:28:25 +0000
@@ -93,7 +93,6 @@
93from bzrlib.plugins.builddeb.upstream import (93from bzrlib.plugins.builddeb.upstream import (
94 AptSource,94 AptSource,
95 GetOrigSourceSource,95 GetOrigSourceSource,
96 PristineTarSource,
97 SelfSplitSource,96 SelfSplitSource,
98 TarfileSource,97 TarfileSource,
99 UScanSource,98 UScanSource,
@@ -103,6 +102,9 @@
103 LazyUpstreamBranchSource,102 LazyUpstreamBranchSource,
104 UpstreamBranchSource,103 UpstreamBranchSource,
105 )104 )
105from bzrlib.plugins.builddeb.upstream.pristinetar import (
106 PristineTarSource,
107 )
106from bzrlib.plugins.builddeb.util import (108from bzrlib.plugins.builddeb.util import (
107 FORMAT_3_0_QUILT,109 FORMAT_3_0_QUILT,
108 FORMAT_3_0_NATIVE,110 FORMAT_3_0_NATIVE,
109111
=== modified file 'errors.py'
--- errors.py 2011-05-15 17:21:54 +0000
+++ errors.py 2011-06-03 13:28:25 +0000
@@ -163,13 +163,6 @@
163 BzrError.__init__(self, location=location)163 BzrError.__init__(self, location=location)
164164
165165
166class PristineTarError(BzrError):
167 _fmt = 'There was an error using pristine-tar: %(error)s.'
168
169 def __init__(self, error):
170 BzrError.__init__(self, error=error)
171
172
173class SharedUpstreamConflictsWithTargetPackaging(BzrError):166class SharedUpstreamConflictsWithTargetPackaging(BzrError):
174 _fmt = ('The upstream branches for the merge source and target have '167 _fmt = ('The upstream branches for the merge source and target have '
175 'diverged. Unfortunately, the attempt to fix this problem '168 'diverged. Unfortunately, the attempt to fix this problem '
176169
=== modified file 'import_dsc.py'
--- import_dsc.py 2011-04-29 12:54:58 +0000
+++ import_dsc.py 2011-06-03 13:28:25 +0000
@@ -25,9 +25,6 @@
25# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA25# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26#26#
2727
28from base64 import (
29 standard_b64encode,
30 )
3128
32import os29import os
33import re30import re
@@ -74,19 +71,18 @@
74 FORMAT_3_0_NATIVE,71 FORMAT_3_0_NATIVE,
75 export,72 export,
76 get_commit_info_from_changelog,73 get_commit_info_from_changelog,
77 make_pristine_tar_delta,
78 md5sum_filename,74 md5sum_filename,
79 open_file_via_transport,75 open_file_via_transport,
80 open_transport,76 open_transport,
81 safe_decode,77 safe_decode,
82 subprocess_setup,78 subprocess_setup,
83 )79 )
84from bzrlib.plugins.builddeb.upstream import (
85 PristineTarSource,
86 )
87from bzrlib.plugins.builddeb.upstream.branch import (80from bzrlib.plugins.builddeb.upstream.branch import (
88 UpstreamBranchSource,81 UpstreamBranchSource,
89 )82 )
83from bzrlib.plugins.builddeb.upstream.pristinetar import (
84 PristineTarSource,
85 )
9086
9187
92class DscCache(object):88class DscCache(object):
@@ -912,16 +908,12 @@
912 self.upstream_tree.set_parent_ids(upstream_parents)908 self.upstream_tree.set_parent_ids(upstream_parents)
913 revprops = {"deb-md5": md5}909 revprops = {"deb-md5": md5}
914 if upstream_tarball is not None:910 if upstream_tarball is not None:
915 delta = self.make_pristine_tar_delta(911 delta_revprops = self.pristine_tar_source.create_delta_revprops(
916 self.upstream_tree, upstream_tarball)912 self.upstream_tree, upstream_tarball)
917 uuencoded = standard_b64encode(delta)913 revprops.update(delta_revprops)
918 if upstream_tarball.endswith(".tar.bz2"):
919 revprops["deb-pristine-delta-bz2"] = uuencoded
920 else:
921 revprops["deb-pristine-delta"] = uuencoded
922 if author is not None:914 if author is not None:
923 revprops['authors'] = author915 revprops['authors'] = author
924 timezone=None916 timezone = None
925 if timestamp is not None:917 if timestamp is not None:
926 timezone = timestamp[1]918 timezone = timestamp[1]
927 timestamp = timestamp[0]919 timestamp = timestamp[0]
@@ -1075,7 +1067,7 @@
1075 if message is None:1067 if message is None:
1076 message = 'Import packaging changes for version %s' % \1068 message = 'Import packaging changes for version %s' % \
1077 (str(version),)1069 (str(version),)
1078 revprops={"deb-md5":md5}1070 revprops={"deb-md5": md5}
1079 if native:1071 if native:
1080 revprops['deb-native'] = "True"1072 revprops['deb-native'] = "True"
1081 if authors:1073 if authors:
@@ -1470,21 +1462,6 @@
1470 finally:1462 finally:
1471 shutil.rmtree(tempdir)1463 shutil.rmtree(tempdir)
14721464
1473 def make_pristine_tar_delta(self, tree, tarball_path):
1474 tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
1475 try:
1476 dest = os.path.join(tmpdir, "orig")
1477 tree.lock_read()
1478 try:
1479 for (dp, ie) in tree.inventory.iter_entries():
1480 ie._read_tree_state(dp, tree)
1481 export(tree, dest, format='dir')
1482 finally:
1483 tree.unlock()
1484 return make_pristine_tar_delta(dest, tarball_path)
1485 finally:
1486 shutil.rmtree(tmpdir)
1487
14881465
1489class SourceExtractor(object):1466class SourceExtractor(object):
1490 """A class to extract a source package to its constituent parts"""1467 """A class to extract a source package to its constituent parts"""
14911468
=== modified file 'tests/test_upstream.py'
--- tests/test_upstream.py 2011-04-29 12:34:12 +0000
+++ tests/test_upstream.py 2011-06-03 13:28:25 +0000
@@ -48,13 +48,11 @@
48 )48 )
49from bzrlib.plugins.builddeb.upstream import (49from bzrlib.plugins.builddeb.upstream import (
50 AptSource,50 AptSource,
51 PristineTarSource,
52 StackedUpstreamSource,51 StackedUpstreamSource,
53 TarfileSource,52 TarfileSource,
54 UpstreamProvider,53 UpstreamProvider,
55 UpstreamSource,54 UpstreamSource,
56 UScanSource,55 UScanSource,
57 Version,
58 extract_tarball_version,56 extract_tarball_version,
59 )57 )
60from bzrlib.plugins.builddeb.upstream.branch import (58from bzrlib.plugins.builddeb.upstream.branch import (
@@ -66,6 +64,9 @@
66 upstream_tag_to_version,64 upstream_tag_to_version,
67 upstream_version_add_revision65 upstream_version_add_revision
68 )66 )
67from bzrlib.plugins.builddeb.upstream.pristinetar import (
68 PristineTarSource,
69 )
6970
7071
71# Unless bug #712474 is fixed and available in the minimum bzrlib required, we72# Unless bug #712474 is fixed and available in the minimum bzrlib required, we
7273
=== modified file 'upstream/__init__.py'
--- upstream/__init__.py 2011-04-29 12:34:12 +0000
+++ upstream/__init__.py 2011-06-03 13:28:25 +0000
@@ -25,21 +25,12 @@
25import tarfile25import tarfile
26import tempfile26import tempfile
2727
28from base64 import (
29 standard_b64decode,
30 )
31
32
33try:28try:
34 from debian.changelog import Version29 from debian.changelog import Version
35except ImportError:30except ImportError:
36 # Prior to 0.1.15 the debian module was called debian_bundle31 # Prior to 0.1.15 the debian module was called debian_bundle
37 from debian_bundle.changelog import Version32 from debian_bundle.changelog import Version
3833
39from bzrlib.errors import (
40 NoSuchRevision,
41 NoSuchTag,
42 )
43from bzrlib.trace import (34from bzrlib.trace import (
44 note,35 note,
45 warning,36 warning,
@@ -48,14 +39,11 @@
48from bzrlib.plugins.builddeb.errors import (39from bzrlib.plugins.builddeb.errors import (
49 MissingUpstreamTarball,40 MissingUpstreamTarball,
50 PackageVersionNotPresent,41 PackageVersionNotPresent,
51 PerFileTimestampsNotSupported,
52 PristineTarError,
53 WatchFileMissing,42 WatchFileMissing,
54 )43 )
55from bzrlib.plugins.builddeb.repack_tarball import repack_tarball44from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
56from bzrlib.plugins.builddeb.util import (45from bzrlib.plugins.builddeb.util import (
57 export,46 export,
58 reconstruct_pristine_tar,
59 tarball_name,47 tarball_name,
60 )48 )
6149
@@ -106,135 +94,6 @@
106 format=format))94 format=format))
10795
10896
109class PristineTarSource(UpstreamSource):
110 """Source that uses the pristine-tar revisions in the packaging branch."""
111
112 def __init__(self, tree, branch):
113 self.branch = branch
114 self.tree = tree
115
116 def tag_name(self, version, distro=None):
117 """Gets the tag name for the upstream part of version.
118
119 :param version: the Version object to extract the upstream
120 part of the version number from.
121 :return: a String with the name of the tag.
122 """
123 assert isinstance(version, str)
124 if distro is None:
125 return "upstream-" + version
126 return "upstream-%s-%s" % (distro, version)
127
128 def fetch_tarball(self, package, version, target_dir):
129 revid = self.version_as_revision(package, version)
130 try:
131 rev = self.branch.repository.get_revision(revid)
132 except NoSuchRevision:
133 raise PackageVersionNotPresent(package, version, self)
134 note("Using pristine-tar to reconstruct the needed tarball.")
135 if self.has_pristine_tar_delta(rev):
136 format = self.pristine_tar_format(rev)
137 else:
138 format = 'gz'
139 target_filename = self._tarball_path(package, version,
140 target_dir, format=format)
141 try:
142 self.reconstruct_pristine_tar(revid, package, version, target_filename)
143 except PristineTarError:
144 raise PackageVersionNotPresent(package, version, self)
145 except PerFileTimestampsNotSupported:
146 raise PackageVersionNotPresent(package, version, self)
147 return target_filename
148
149 def _has_version(self, tag_name, md5=None):
150 if not self.branch.tags.has_tag(tag_name):
151 return False
152 revid = self.branch.tags.lookup_tag(tag_name)
153 self.branch.lock_read()
154 try:
155 graph = self.branch.repository.get_graph()
156 if not graph.is_ancestor(revid, self.branch.last_revision()):
157 return False
158 finally:
159 self.branch.unlock()
160 if md5 is None:
161 return True
162 rev = self.branch.repository.get_revision(revid)
163 try:
164 return rev.properties['deb-md5'] == md5
165 except KeyError:
166 warning("tag %s present in branch, but there is no "
167 "associated 'deb-md5' property" % tag_name)
168 return True
169
170 def version_as_revision(self, package, version):
171 assert isinstance(version, str)
172 for tag_name in self.possible_tag_names(version):
173 if self._has_version(tag_name):
174 return self.branch.tags.lookup_tag(tag_name)
175 tag_name = self.tag_name(version)
176 try:
177 return self.branch.tags.lookup_tag(tag_name)
178 except NoSuchTag:
179 raise PackageVersionNotPresent(package, version, self)
180
181 def has_version(self, package, version, md5=None):
182 assert isinstance(version, str), str(type(version))
183 for tag_name in self.possible_tag_names(version):
184 if self._has_version(tag_name, md5=md5):
185 return True
186 return False
187
188 def possible_tag_names(self, version):
189 assert isinstance(version, str)
190 tags = [self.tag_name(version),
191 self.tag_name(version, distro="debian"),
192 self.tag_name(version, distro="ubuntu"),
193 "upstream/%s" % version]
194 return tags
195
196 def has_pristine_tar_delta(self, rev):
197 return ('deb-pristine-delta' in rev.properties
198 or 'deb-pristine-delta-bz2' in rev.properties)
199
200 def pristine_tar_format(self, rev):
201 if 'deb-pristine-delta' in rev.properties:
202 return 'gz'
203 elif 'deb-pristine-delta-bz2' in rev.properties:
204 return 'bz2'
205 assert self.has_pristine_tar_delta(rev)
206 raise AssertionError("Not handled new delta type in "
207 "pristine_tar_format")
208
209 def pristine_tar_delta(self, rev):
210 if 'deb-pristine-delta' in rev.properties:
211 uuencoded = rev.properties['deb-pristine-delta']
212 elif 'deb-pristine-delta-bz2' in rev.properties:
213 uuencoded = rev.properties['deb-pristine-delta-bz2']
214 else:
215 assert self.has_pristine_tar_delta(rev)
216 raise AssertionError("Not handled new delta type in "
217 "pristine_tar_delta")
218 return standard_b64decode(uuencoded)
219
220 def reconstruct_pristine_tar(self, revid, package, version,
221 dest_filename):
222 """Reconstruct a pristine-tar tarball from a bzr revision."""
223 tree = self.branch.repository.revision_tree(revid)
224 tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
225 try:
226 dest = os.path.join(tmpdir, "orig")
227 rev = self.branch.repository.get_revision(revid)
228 if self.has_pristine_tar_delta(rev):
229 export(tree, dest, format='dir')
230 delta = self.pristine_tar_delta(rev)
231 reconstruct_pristine_tar(dest, delta, dest_filename)
232 else:
233 export(tree, dest_filename, require_per_file_timestamps=True)
234 finally:
235 shutil.rmtree(tmpdir)
236
237
238class AptSource(UpstreamSource):97class AptSource(UpstreamSource):
239 """Upstream source that uses apt-source."""98 """Upstream source that uses apt-source."""
24099
241100
=== added file 'upstream/pristinetar.py'
--- upstream/pristinetar.py 1970-01-01 00:00:00 +0000
+++ upstream/pristinetar.py 2011-06-03 13:28:25 +0000
@@ -0,0 +1,267 @@
1# pristinetar.py -- Providers of upstream source
2# Copyright (C) 2009-2011 Canonical Ltd.
3# Copyright (C) 2009 Jelmer Vernooij <jelmer@debian.org>
4#
5# This file is part of bzr-builddeb.
6#
7# bzr-builddeb is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# bzr-builddeb is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with bzr-builddeb; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
21from base64 import (
22 standard_b64decode,
23 standard_b64encode,
24 )
25import errno
26import os
27import shutil
28import subprocess
29import tempfile
30
31from bzrlib.plugins.builddeb.errors import (
32 PackageVersionNotPresent,
33 PerFileTimestampsNotSupported,
34 )
35from bzrlib.plugins.builddeb.upstream import UpstreamSource
36from bzrlib.plugins.builddeb.util import (
37 export,
38 subprocess_setup,
39 )
40
41from bzrlib import osutils
42from bzrlib.errors import (
43 BzrError,
44 NoSuchRevision,
45 NoSuchTag,
46 )
47from bzrlib.trace import (
48 note,
49 warning,
50 )
51
52
53class PristineTarError(BzrError):
54 _fmt = 'There was an error using pristine-tar: %(error)s.'
55
56 def __init__(self, error):
57 BzrError.__init__(self, error=error)
58
59
60def reconstruct_pristine_tar(dest, delta, dest_filename):
61 """Reconstruct a pristine tarball from a directory and a delta.
62
63 :param dest: Directory to pack
64 :param delta: pristine-tar delta
65 :param dest_filename: Destination filename
66 """
67 command = ["pristine-tar", "gentar", "-",
68 os.path.abspath(dest_filename)]
69 try:
70 proc = subprocess.Popen(command, stdin=subprocess.PIPE,
71 cwd=dest, preexec_fn=subprocess_setup,
72 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
73 except OSError, e:
74 if e.errno == errno.ENOENT:
75 raise PristineTarError("pristine-tar is not installed")
76 else:
77 raise
78 (stdout, stderr) = proc.communicate(delta)
79 if proc.returncode != 0:
80 raise PristineTarError("Generating tar from delta failed: %s" % stdout)
81
82
83def make_pristine_tar_delta(dest, tarball_path):
84 """Create a pristine-tar delta for a tarball.
85
86 :param dest: Directory to generate pristine tar delta for
87 :param tarball_path: Path to the tarball
88 :return: pristine-tarball
89 """
90 # If tarball_path is relative, the cwd=dest parameter to Popen will make
91 # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we
92 # assume local paths.
93 tarball_path = osutils.abspath(tarball_path)
94 command = ["pristine-tar", "gendelta", tarball_path, "-"]
95 try:
96 proc = subprocess.Popen(command, stdout=subprocess.PIPE,
97 cwd=dest, preexec_fn=subprocess_setup,
98 stderr=subprocess.PIPE)
99 except OSError, e:
100 if e.errno == errno.ENOENT:
101 raise PristineTarError("pristine-tar is not installed")
102 else:
103 raise
104 (stdout, stderr) = proc.communicate()
105 if proc.returncode != 0:
106 raise PristineTarError("Generating delta from tar failed: %s" % stderr)
107 return stdout
108
109
110class PristineTarSource(UpstreamSource):
111 """Source that uses the pristine-tar revisions in the packaging branch."""
112
113 def __init__(self, tree, branch):
114 self.branch = branch
115 self.tree = tree
116
117 def tag_name(self, version, distro=None):
118 """Gets the tag name for the upstream part of version.
119
120 :param version: the Version object to extract the upstream
121 part of the version number from.
122 :return: a String with the name of the tag.
123 """
124 assert isinstance(version, str)
125 if distro is None:
126 return "upstream-" + version
127 return "upstream-%s-%s" % (distro, version)
128
129 def fetch_tarball(self, package, version, target_dir):
130 revid = self.version_as_revision(package, version)
131 try:
132 rev = self.branch.repository.get_revision(revid)
133 except NoSuchRevision:
134 raise PackageVersionNotPresent(package, version, self)
135 note("Using pristine-tar to reconstruct the needed tarball.")
136 if self.has_pristine_tar_delta(rev):
137 format = self.pristine_tar_format(rev)
138 else:
139 format = 'gz'
140 target_filename = self._tarball_path(package, version,
141 target_dir, format=format)
142 try:
143 self.reconstruct_pristine_tar(revid, package, version, target_filename)
144 except PristineTarError:
145 raise PackageVersionNotPresent(package, version, self)
146 except PerFileTimestampsNotSupported:
147 raise PackageVersionNotPresent(package, version, self)
148 return target_filename
149
150 def _has_version(self, tag_name, md5=None):
151 if not self.branch.tags.has_tag(tag_name):
152 return False
153 revid = self.branch.tags.lookup_tag(tag_name)
154 self.branch.lock_read()
155 try:
156 graph = self.branch.repository.get_graph()
157 if not graph.is_ancestor(revid, self.branch.last_revision()):
158 return False
159 finally:
160 self.branch.unlock()
161 if md5 is None:
162 return True
163 rev = self.branch.repository.get_revision(revid)
164 try:
165 return rev.properties['deb-md5'] == md5
166 except KeyError:
167 warning("tag %s present in branch, but there is no "
168 "associated 'deb-md5' property" % tag_name)
169 return True
170
171 def version_as_revision(self, package, version):
172 assert isinstance(version, str)
173 for tag_name in self.possible_tag_names(version):
174 if self._has_version(tag_name):
175 return self.branch.tags.lookup_tag(tag_name)
176 tag_name = self.tag_name(version)
177 try:
178 return self.branch.tags.lookup_tag(tag_name)
179 except NoSuchTag:
180 raise PackageVersionNotPresent(package, version, self)
181
182 def has_version(self, package, version, md5=None):
183 assert isinstance(version, str), str(type(version))
184 for tag_name in self.possible_tag_names(version):
185 if self._has_version(tag_name, md5=md5):
186 return True
187 return False
188
189 def possible_tag_names(self, version):
190 assert isinstance(version, str)
191 tags = [self.tag_name(version),
192 self.tag_name(version, distro="debian"),
193 self.tag_name(version, distro="ubuntu"),
194 "upstream/%s" % version]
195 return tags
196
197 def has_pristine_tar_delta(self, rev):
198 return ('deb-pristine-delta' in rev.properties
199 or 'deb-pristine-delta-bz2' in rev.properties)
200
201 def pristine_tar_format(self, rev):
202 if 'deb-pristine-delta' in rev.properties:
203 return 'gz'
204 elif 'deb-pristine-delta-bz2' in rev.properties:
205 return 'bz2'
206 assert self.has_pristine_tar_delta(rev)
207 raise AssertionError("Not handled new delta type in "
208 "pristine_tar_format")
209
210 def pristine_tar_delta(self, rev):
211 if 'deb-pristine-delta' in rev.properties:
212 uuencoded = rev.properties['deb-pristine-delta']
213 elif 'deb-pristine-delta-bz2' in rev.properties:
214 uuencoded = rev.properties['deb-pristine-delta-bz2']
215 else:
216 assert self.has_pristine_tar_delta(rev)
217 raise AssertionError("Not handled new delta type in "
218 "pristine_tar_delta")
219 return standard_b64decode(uuencoded)
220
221 def reconstruct_pristine_tar(self, revid, package, version,
222 dest_filename):
223 """Reconstruct a pristine-tar tarball from a bzr revision."""
224 tree = self.branch.repository.revision_tree(revid)
225 tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
226 try:
227 dest = os.path.join(tmpdir, "orig")
228 rev = self.branch.repository.get_revision(revid)
229 if self.has_pristine_tar_delta(rev):
230 export(tree, dest, format='dir')
231 delta = self.pristine_tar_delta(rev)
232 reconstruct_pristine_tar(dest, delta, dest_filename)
233 else:
234 export(tree, dest_filename, require_per_file_timestamps=True)
235 finally:
236 shutil.rmtree(tmpdir)
237
238 def make_pristine_tar_delta(self, tree, tarball_path):
239 tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
240 try:
241 dest = os.path.join(tmpdir, "orig")
242 tree.lock_read()
243 try:
244 for (dp, ie) in tree.inventory.iter_entries():
245 ie._read_tree_state(dp, tree)
246 export(tree, dest, format='dir')
247 finally:
248 tree.unlock()
249 return make_pristine_tar_delta(dest, tarball_path)
250 finally:
251 shutil.rmtree(tmpdir)
252
253 def create_delta_revprops(self, tree, tarball):
254 """Create the revision properties with the pristine tar delta.
255
256 :param tree: Bazaar Tree to diff against
257 :param tarball: The pristine tarball
258 :return: Dictionary with extra revision properties
259 """
260 ret = {}
261 delta = self.make_pristine_tar_delta(tree, tarball)
262 uuencoded = standard_b64encode(delta)
263 if tarball.endswith(".tar.bz2"):
264 ret["deb-pristine-delta-bz2"] = uuencoded
265 else:
266 ret["deb-pristine-delta"] = uuencoded
267 return ret
0268
=== modified file 'util.py'
--- util.py 2011-04-08 18:47:10 +0000
+++ util.py 2011-06-03 13:28:25 +0000
@@ -22,10 +22,8 @@
22 import hashlib as md522 import hashlib as md5
23except ImportError:23except ImportError:
24 import md524 import md5
25import errno
26import signal25import signal
27import shutil26import shutil
28import subprocess
29import tempfile27import tempfile
30import os28import os
31import re29import re
@@ -43,7 +41,6 @@
43from bzrlib import (41from bzrlib import (
44 bugtracker,42 bugtracker,
45 errors,43 errors,
46 osutils,
47 urlutils,44 urlutils,
48 version_info as bzr_version_info,45 version_info as bzr_version_info,
49 )46 )
@@ -69,7 +66,6 @@
69 AddChangelogError,66 AddChangelogError,
70 InconsistentSourceFormatError,67 InconsistentSourceFormatError,
71 NoPreviousUpload,68 NoPreviousUpload,
72 PristineTarError,
73 UnableToFindPreviousUpload,69 UnableToFindPreviousUpload,
74 UnparseableChangelog,70 UnparseableChangelog,
75 )71 )
@@ -686,51 +682,4 @@
686 return BUILD_TYPE_NORMAL682 return BUILD_TYPE_NORMAL
687683
688684
689def reconstruct_pristine_tar(dest, delta, dest_filename):685
690 """Reconstruct a pristine tarball from a directory and a delta.
691
692 :param dest: Directory to pack
693 :param delta: pristine-tar delta
694 :param dest_filename: Destination filename
695 """
696 command = ["pristine-tar", "gentar", "-",
697 os.path.abspath(dest_filename)]
698 try:
699 proc = subprocess.Popen(command, stdin=subprocess.PIPE,
700 cwd=dest, preexec_fn=subprocess_setup,
701 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
702 except OSError, e:
703 if e.errno == errno.ENOENT:
704 raise PristineTarError("pristine-tar is not installed")
705 else:
706 raise
707 (stdout, stderr) = proc.communicate(delta)
708 if proc.returncode != 0:
709 raise PristineTarError("Generating tar from delta failed: %s" % stdout)
710
711
712def make_pristine_tar_delta(dest, tarball_path):
713 """Create a pristine-tar delta for a tarball.
714
715 :param dest: Directory to generate pristine tar delta for
716 :param tarball_path: Path to the tarball
717 :return: pristine-tarball
718 """
719 # If tarball_path is relative, the cwd=dest parameter to Popen will make
720 # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we
721 # assume local paths.
722 tarball_path = osutils.abspath(tarball_path)
723 command = ["pristine-tar", "gendelta", tarball_path, "-"]
724 try:
725 proc = subprocess.Popen(command, stdout=subprocess.PIPE,
726 cwd=dest, preexec_fn=subprocess_setup,
727 stderr=subprocess.PIPE)
728 except OSError, e:
729 if e.errno == errno.ENOENT:
730 raise PristineTarError("pristine-tar is not installed")
731 else:
732 raise
733 (stdout, stderr) = proc.communicate()
734 if proc.returncode != 0:
735 raise PristineTarError("Generating delta from tar failed: %s" % stderr)
736 return stdout

Subscribers

People subscribed via source and target branches