Rev 2215: Repository.tarball fixes for python2.4 in http://sourcefrog.net/bzr/hpss-faster-copy
Martin Pool
mbp at sourcefrog.net
Thu Apr 26 08:48:06 BST 2007
At http://sourcefrog.net/bzr/hpss-faster-copy
------------------------------------------------------------
revno: 2215
revision-id: mbp at sourcefrog.net-20070426074805-va53nylsxqt7ur7u
parent: mbp at sourcefrog.net-20070423120654-7k0q70jyjrvb5g38
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: hpss-faster-copy
timestamp: Thu 2007-04-26 17:48:05 +1000
message:
Repository.tarball fixes for python2.4
Use 'r|bz2' to extract since r:bz2 is not supported
Replace extractall, which is not in python2.4
RemoteRepository._get_tarball returns a TemporaryFile
-------------- This line and the following will be ignored --------------
modified:
bzrlib/remote.py
bzrlib/tests/test_remote.py
bzrlib/tests/test_smart.py
modified:
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-04-23 12:06:54 +0000
+++ b/bzrlib/remote.py 2007-04-26 07:48:05 +0000
@@ -429,7 +429,8 @@
return self._real_repository.break_lock()
def _get_tarball(self, compression):
- """See Repository.tarball()."""
+ """Return a TemporaryFile containing a repository tarball"""
+ import tempfile
path = self.bzrdir._path_for_remote_call(self._client)
response, protocol = self._client.call_expecting_body(
'Repository.tarball', path, compression)
@@ -437,8 +438,11 @@
'unexpected response code %s' % (response,)
if response[0] == 'ok':
# Extract the tarball and return it
- body = protocol.read_body_bytes()
- return body
+ t = tempfile.NamedTemporaryFile()
+ # TODO: rpc layer should read directly into it...
+ t.write(protocol.read_body_bytes())
+ t.seek(0)
+ return t
else:
raise errors.SmartServerError(error_code=response)
@@ -597,17 +601,20 @@
from StringIO import StringIO
# TODO: Maybe a progress bar while streaming the tarball?
note("Copying repository content as tarball...")
- tar_file = StringIO(self._get_tarball('bz2'))
- tar = tarfile.open('repository', fileobj=tar_file,
- mode='r:bz2')
- tmpdir = tempfile.mkdtemp()
+ tar_file = self._get_tarball('bz2')
try:
- tar.extractall(tmpdir)
- tmp_bzrdir = BzrDir.open(tmpdir)
- tmp_repo = tmp_bzrdir.open_repository()
- tmp_repo.copy_content_into(destination, revision_id)
+ tar = tarfile.open('repository', fileobj=tar_file,
+ mode='r|bz2')
+ tmpdir = tempfile.mkdtemp()
+ try:
+ _extract_tar(tar, tmpdir)
+ tmp_bzrdir = BzrDir.open(tmpdir)
+ tmp_repo = tmp_bzrdir.open_repository()
+ tmp_repo.copy_content_into(destination, revision_id)
+ finally:
+ osutils.rmtree(tmpdir)
finally:
- osutils.rmtree(tmpdir)
+ tar_file.close()
# TODO: if the server doesn't support this operation, maybe do it the
# slow way using the _real_repository?
#
@@ -1032,3 +1039,11 @@
self._branch_data_config = TreeConfig(self.branch._real_branch)
return self._branch_data_config
+
+def _extract_tar(tar, to_dir):
+ """Extract all the contents of a tarfile object.
+
+ A replacement for extractall, which is not present in python2.4
+ """
+ for tarinfo in tar:
+ tar.extract(tarinfo, to_dir)
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2007-04-23 12:06:54 +0000
+++ b/bzrlib/tests/test_remote.py 2007-04-26 07:48:05 +0000
@@ -657,9 +657,12 @@
remote_repo, client = self.setup_fake_client_and_repository(
expected_responses, transport_path)
# Now actually ask for the tarball
- tarball_data = remote_repo._get_tarball('bz2')
- self.assertEqual(expected_calls, client._calls)
- self.assertEqual(self.tarball_content, tarball_data)
+ tarball_file = remote_repo._get_tarball('bz2')
+ try:
+ self.assertEqual(expected_calls, client._calls)
+ self.assertEqual(self.tarball_content, tarball_file.read())
+ finally:
+ tarball_file.close()
def test_sprout_uses_tarball(self):
# RemoteRepository.sprout should try to use the
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2007-04-23 05:03:44 +0000
+++ b/bzrlib/tests/test_smart.py 2007-04-26 07:48:05 +0000
@@ -756,7 +756,7 @@
# body should be a tbz2
body_file = StringIO(response.body)
body_tar = tarfile.open('body_tar.tbz2', fileobj=body_file,
- mode='r:bz2')
+ mode='r|bz2')
# let's make sure there are some key repository components inside it.
# the tarfile returns directories with trailing slashes...
names = set([n.rstrip('/') for n in body_tar.getnames()])
More information about the bazaar-commits
mailing list