17
17
"""Server-side repository related request implmentations."""
20
23
from bzrlib import errors
21
24
from bzrlib.bzrdir import BzrDir
22
25
from bzrlib.smart.request import SmartServerRequest, SmartServerResponse
26
from bzrlib.transport.local import LocalTransport
25
29
class SmartServerRepositoryRequest(SmartServerRequest):
177
181
class SmartServerRepositoryTarball(SmartServerRepositoryRequest):
178
"""Get the raw repository files as one big tarball
182
"""Get the raw repository files as one big tarball.
184
The tarball contains one directory 'repository' which contains all the
185
files found in that directory.
187
At the moment this is only supported when the repository is on a
180
This takes one parameter, format, which currently must be
190
This takes one parameter, compression, which currently must be
184
def do_repository_request(self, repository, format):
185
return SmartServerResponse(('ok',))
194
def do_repository_request(self, repository, compression):
195
repo_transport = repository.control_files._transport
196
if not isinstance(repo_transport, LocalTransport):
197
raise NotImplementedError(
198
"Repository.tarball is not supported on non-local "
201
repo_dir = repo_transport.local_abspath('.')
202
temp = tempfile.NamedTemporaryFile()
204
tarball = tarfile.open(temp.name, mode='w:' + compression)
206
# The tarball module only accepts ascii names, and (i guess)
207
# packs them with their 8bit names. We know all the files
208
# within the repository have ASCII names so the should be safe
210
repo_dir = repo_dir.encode(sys.getfilesystemencoding())
211
tarball.add(repo_dir, 'repository') # recursive by default
214
# all finished; write the tempfile out to the network
216
return SmartServerResponse(('ok',), temp.read())