/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/smart/request.py

Tidy ups, and turn do_hello and do_get_bundle into command objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import tempfile
 
18
 
 
19
from bzrlib import bzrdir, revision
 
20
from bzrlib.bundle.serializer import write_bundle
 
21
from bzrlib.transport.smart import protocol
 
22
 
17
23
 
18
24
class SmartServerRequest(object):
19
25
    """Base class for request handlers.
30
36
    def do_body(self, body_bytes):
31
37
        raise NotImplementedError(self.do_body)
32
38
 
 
39
 
 
40
class HelloRequest(SmartServerRequest):
 
41
    """Answer a version request with my version."""
 
42
 
 
43
    method = 'hello'
 
44
 
 
45
    def do(self):
 
46
        return protocol.SmartServerResponse(('ok', '1'))
 
47
 
 
48
 
 
49
class GetBundleRequest(SmartServerRequest):
 
50
 
 
51
    method = 'get_bundle'
 
52
 
 
53
    def do(self, path, revision_id):
 
54
        # open transport relative to our base
 
55
        t = self._backing_transport.clone(path)
 
56
        control, extra_path = bzrdir.BzrDir.open_containing_from_transport(t)
 
57
        repo = control.open_repository()
 
58
        tmpf = tempfile.TemporaryFile()
 
59
        base_revision = revision.NULL_REVISION
 
60
        write_bundle(repo, revision_id, base_revision, tmpf)
 
61
        tmpf.seek(0)
 
62
        return protocol.SmartServerResponse((), tmpf.read())
 
63
 
 
64
 
 
65
# This is extended by bzrlib/transport/smart/vfs.py
 
66
version_one_commands = {
 
67
    HelloRequest.method: HelloRequest,
 
68
    GetBundleRequest.method: GetBundleRequest,
 
69
}
 
70
 
 
71