/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/remotebranch.py

  • Committer: Lalo Martins
  • Date: 2005-09-07 10:50:03 UTC
  • mto: (1185.1.5)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: lalo@exoweb.net-20050907105002-4e37d43b7d4060fe
unifying 'base' (from Branch) and 'baseurl' (from RemoteBranch) attributes;
this allows us to remove quite a few "dead chickens" from the code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import gzip
28
28
from cStringIO import StringIO
 
29
import os
29
30
import urllib2
30
31
 
31
 
from errors import BzrError, BzrCheckError
32
 
from branch import Branch, BZR_BRANCH_FORMAT
33
 
from trace import mutter
34
 
 
35
 
# velocitynet.com.au transparently proxies connections and thereby
36
 
# breaks keep-alive -- sucks!
37
 
 
38
 
 
39
 
ENABLE_URLGRABBER = True
40
 
 
41
 
from bzrlib.errors import BzrError
 
32
from bzrlib.errors import BzrError, BzrCheckError
 
33
from bzrlib.branch import Branch, BZR_BRANCH_FORMAT
 
34
from bzrlib.trace import mutter
 
35
from bzrlib.xml import serializer_v4
 
36
 
 
37
 
 
38
ENABLE_URLGRABBER = False
 
39
 
 
40
from bzrlib.errors import BzrError, NoSuchRevision
42
41
 
43
42
class GetFailed(BzrError):
44
43
    def __init__(self, url, status):
47
46
        self.status = status
48
47
 
49
48
if ENABLE_URLGRABBER:
50
 
    import urlgrabber
51
 
    import urlgrabber.keepalive
52
 
    urlgrabber.keepalive.DEBUG = 0
 
49
    import util.urlgrabber
 
50
    import util.urlgrabber.keepalive
 
51
    util.urlgrabber.keepalive.DEBUG = 0
53
52
    def get_url(path, compressed=False):
54
53
        try:
55
54
            url = path
56
55
            if compressed:
57
56
                url += '.gz'
58
57
            mutter("grab url %s" % url)
59
 
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
58
            url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
60
59
            if url_f.status != 200:
61
60
                raise GetFailed(url, url_f.status)
62
61
            if not compressed:
111
110
    def __init__(self, baseurl, find_root=True):
112
111
        """Create new proxy for a remote branch."""
113
112
        if find_root:
114
 
            self.baseurl = _find_remote_root(baseurl)
 
113
            self.base = _find_remote_root(baseurl)
115
114
        else:
116
 
            self.baseurl = baseurl
 
115
            self.base = baseurl
117
116
            self._check_format()
118
117
 
119
118
        self.inventory_store = RemoteStore(baseurl + '/.bzr/inventory-store/')
129
128
    def controlfile(self, filename, mode):
130
129
        if mode not in ('rb', 'rt', 'r'):
131
130
            raise BzrError("file mode %r not supported for remote branches" % mode)
132
 
        return get_url(self.baseurl + '/.bzr/' + filename, False)
 
131
        return get_url(self.base + '/.bzr/' + filename, False)
133
132
 
134
133
 
135
134
    def lock_read(self):
139
138
    def lock_write(self):
140
139
        from errors import LockError
141
140
        raise LockError("write lock not supported for remote branch %s"
142
 
                        % self.baseurl)
 
141
                        % self.base)
143
142
 
144
143
    def unlock(self):
145
144
        pass
146
145
    
147
146
 
148
147
    def relpath(self, path):
149
 
        if not path.startswith(self.baseurl):
 
148
        if not path.startswith(self.base):
150
149
            raise BzrError('path %r is not under base URL %r'
151
 
                           % (path, self.baseurl))
152
 
        pl = len(self.baseurl)
 
150
                           % (path, self.base))
 
151
        pl = len(self.base)
153
152
        return path[pl:].lstrip('/')
154
153
 
155
154
 
156
155
    def get_revision(self, revision_id):
157
 
        from bzrlib.revision import Revision
158
 
        from bzrlib.xml import unpack_xml
159
 
        revf = self.revision_store[revision_id]
160
 
        r = unpack_xml(Revision, revf)
 
156
        try:
 
157
            revf = self.revision_store[revision_id]
 
158
        except KeyError:
 
159
            raise NoSuchRevision(self, revision_id)
 
160
        r = serializer_v4.read_revision(revf)
161
161
        if r.revision_id != revision_id:
162
162
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
163
163
                                % (revision_id, r.revision_id))