/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: John Arbash Meinel
  • Date: 2005-09-15 21:35:53 UTC
  • mfrom: (907.1.57)
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050915213552-a6c83a5ef1e20897
(broken) Transport work is merged in. Tests do not pass yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
 
3
1
# Copyright (C) 2005 Canonical Ltd
4
2
 
5
3
# This program is free software; you can redistribute it and/or modify
26
24
 
27
25
import gzip
28
26
from cStringIO import StringIO
 
27
import os
29
28
import urllib2
30
 
 
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
 
29
import urlparse
 
30
 
 
31
from bzrlib.errors import BzrError, BzrCheckError
 
32
from bzrlib.branch import Branch, BZR_BRANCH_FORMAT
 
33
from bzrlib.trace import mutter
 
34
from bzrlib.xml import serializer_v4
 
35
 
 
36
 
 
37
ENABLE_URLGRABBER = False
 
38
 
 
39
from bzrlib.errors import BzrError, NoSuchRevision
42
40
 
43
41
class GetFailed(BzrError):
44
42
    def __init__(self, url, status):
47
45
        self.status = status
48
46
 
49
47
if ENABLE_URLGRABBER:
50
 
    import urlgrabber
51
 
    import urlgrabber.keepalive
52
 
    urlgrabber.keepalive.DEBUG = 0
 
48
    import util.urlgrabber
 
49
    import util.urlgrabber.keepalive
 
50
    util.urlgrabber.keepalive.DEBUG = 0
53
51
    def get_url(path, compressed=False):
54
52
        try:
55
53
            url = path
56
54
            if compressed:
57
55
                url += '.gz'
58
56
            mutter("grab url %s" % url)
59
 
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
57
            url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
60
58
            if url_f.status != 200:
61
59
                raise GetFailed(url, url_f.status)
62
60
            if not compressed:
84
82
    orig_url = url
85
83
    while True:
86
84
        try:
87
 
            ff = get_url(url + '/.bzr/branch-format')
88
 
 
 
85
            fmt_url = url + '/.bzr/branch-format'
 
86
            ff = get_url(fmt_url)
89
87
            fmt = ff.read()
90
88
            ff.close()
91
89
 
98
96
        except urllib2.URLError:
99
97
            pass
100
98
 
101
 
        try:
102
 
            idx = url.rindex('/')
103
 
        except ValueError:
104
 
            raise BzrError('no branch root found for URL %s' % orig_url)
105
 
 
106
 
        url = url[:idx]        
 
99
        scheme, host, path = list(urlparse.urlparse(url))[:3]
 
100
        # discard params, query, fragment
 
101
        
 
102
        # strip off one component of the path component
 
103
        idx = path.rfind('/')
 
104
        if idx == -1 or path == '/':
 
105
            raise BzrError('no branch root found for URL %s'
 
106
                           ' or enclosing directories'
 
107
                           % orig_url)
 
108
        path = path[:idx]
 
109
        url = urlparse.urlunparse((scheme, host, path, '', '', ''))
107
110
        
108
111
 
109
112
 
111
114
    def __init__(self, baseurl, find_root=True):
112
115
        """Create new proxy for a remote branch."""
113
116
        if find_root:
114
 
            self.baseurl = _find_remote_root(baseurl)
 
117
            self.base = _find_remote_root(baseurl)
115
118
        else:
116
 
            self.baseurl = baseurl
 
119
            self.base = baseurl
117
120
            self._check_format()
118
121
 
119
122
        self.inventory_store = RemoteStore(baseurl + '/.bzr/inventory-store/')
129
132
    def controlfile(self, filename, mode):
130
133
        if mode not in ('rb', 'rt', 'r'):
131
134
            raise BzrError("file mode %r not supported for remote branches" % mode)
132
 
        return get_url(self.baseurl + '/.bzr/' + filename, False)
 
135
        return get_url(self.base + '/.bzr/' + filename, False)
133
136
 
134
137
 
135
138
    def lock_read(self):
139
142
    def lock_write(self):
140
143
        from errors import LockError
141
144
        raise LockError("write lock not supported for remote branch %s"
142
 
                        % self.baseurl)
 
145
                        % self.base)
143
146
 
144
147
    def unlock(self):
145
148
        pass
146
149
    
147
150
 
148
151
    def relpath(self, path):
149
 
        if not path.startswith(self.baseurl):
 
152
        if not path.startswith(self.base):
150
153
            raise BzrError('path %r is not under base URL %r'
151
 
                           % (path, self.baseurl))
152
 
        pl = len(self.baseurl)
 
154
                           % (path, self.base))
 
155
        pl = len(self.base)
153
156
        return path[pl:].lstrip('/')
154
157
 
155
158
 
156
159
    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)
 
160
        try:
 
161
            revf = self.revision_store[revision_id]
 
162
        except KeyError:
 
163
            raise NoSuchRevision(self, revision_id)
 
164
        r = serializer_v4.read_revision(revf)
161
165
        if r.revision_id != revision_id:
162
166
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
163
167
                                % (revision_id, r.revision_id))
178
182
        p = self._path(fileid)
179
183
        try:
180
184
            return get_url(p, compressed=True)
181
 
        except:
 
185
        except urllib2.URLError:
182
186
            raise KeyError(fileid)
183
187
    
184
188