/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
1
# Copyright (C) 2006 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
17
# TODO: At some point, handle upgrades by just passing the whole request
18
# across to run on the server.
19
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
20
1752.2.33 by Martin Pool
[broken] more hpss methods and adapt to bzrdir tests
21
from bzrlib import bzrdir, branch, errors, repository
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
22
from bzrlib.bzrdir import BzrDir, BzrDirFormat
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
23
from bzrlib.branch import Branch, BranchFormat
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
24
from bzrlib.trace import mutter
25
from bzrlib.transport.smart import SmartTransport
26
27
1752.2.33 by Martin Pool
[broken] more hpss methods and adapt to bzrdir tests
28
class RemoteBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
29
    """Format representing bzrdirs accessed via a smart server"""
30
    
31
    def probe_transport(self, transport):
32
        mutter("%r probe for bzrdir in %r" % (self, transport))
33
        if isinstance(transport, SmartTransport):
34
            return self
35
        else:
36
            raise errors.NoSmartServer(transport.base)
37
38
    def _open(self, transport):
39
        return RemoteBzrDir(transport)
40
41
42
class RemoteBzrDir(BzrDir):
43
    """Control directory on a remote server, accessed by HPSS."""
44
45
    def __init__(self, transport):
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
46
        BzrDir.__init__(self, transport, RemoteBzrDirFormat())
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
47
        self.client = transport.get_smart_client()
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
48
        # this object holds a delegated bzrdir that uses file-level operations
49
        # to talk to the other side
50
        self._real_bzrdir = BzrDirFormat.get_default_format().open(transport, _found=True)
51
        self._repository = None
52
        self._branch = None
53
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
54
    def create_repository(self, shared=False):
55
        return self._real_bzrdir.create_repository(shared=shared)
56
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
57
    def open_repository(self):
58
        # OK just very fake response for now
59
        if not self._repository:
60
            self._repository = self._real_bzrdir.open_repository()
61
        return self._repository
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
62
63
    def open_branch(self):
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
64
        # Very fake - use file-level transport
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
65
        return RemoteBranch(self, self.client)
66
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
67
    def get_branch_transport(self, branch_format):
68
        return self._real_bzrdir.get_branch_transport(branch_format)
69
1752.2.39 by Martin Pool
[broken] implement upgrade apis on remote bzrdirs
70
    def can_convert_format(self):
71
        """Upgrading of remote bzrdirs is not supported yet."""
72
        return False
73
74
    def needs_format_conversion(self, format=None):
75
        """Upgrading of remote bzrdirs is not supported yet."""
76
        return False
77
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
78
79
class RemoteRepositoryFormat(repository.RepositoryFormatKnit1):
80
    """Format for repositories accessed over rpc.
81
82
    Instances of this repository are represented by RemoteRepository 
83
    instances.
84
    """
85
86
    _matchingbzrdir = RemoteBzrDirFormat
87
88
89
class RemoteRepository(repository.Repository):
90
    """Repository accessed over rpc.
91
92
    For the moment everything is delegated to IO-like operations over 
93
    the transport.
94
    """
95
96
97
class RemoteBranchFormat(branch.BranchFormat):
98
99
    def open(self, a_bzrdir):
100
        return RemoteBranch(a_bzrdir, a_bzrdir.client)
101
102
103
class RemoteBranch(branch.Branch):
104
    """Branch stored on a server accessed by HPSS RPC.
105
106
    At the moment most operations are mapped down to simple file operations.
107
    """
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
108
109
    def __init__(self, my_bzrdir, smart_client):
110
        self.bzrdir = my_bzrdir
111
        self.client = smart_client
1752.2.31 by Martin Pool
[broken] some support for write operations over hpss
112
        self.transport = my_bzrdir.transport
113
        self.repository = self.bzrdir.open_repository()
114
        real_format = BranchFormat.get_default_format()
115
        self._real_branch = real_format.open(my_bzrdir, _found=True)
116
117
    def lock_read(self):
118
        pass
119
120
    def unlock(self):
121
        # TODO: implement write locking, passed through to the other end?  Or
122
        # perhaps we should not lock but rather do higher-level operations?
123
        pass
124
125
    def revision_history(self):
126
        return self._real_branch.revision_history()
1752.2.30 by Martin Pool
Start adding a RemoteBzrDir, etc
127
128
129
# when first loaded, register this format.
130
#
131
# TODO: Actually this needs to be done earlier; we can hold off on loading
132
# this code until it's needed though.
133
134
# We can't use register_control_format because it adds it at a lower priority
135
# than the existing branches, whereas this should take priority.
136
BzrDirFormat._control_formats.insert(0, RemoteBzrDirFormat())