~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: Martin Pool
  • Date: 2005-09-06 07:39:09 UTC
  • Revision ID: mbp@sourcefrog.net-20050906073909-234eb078dfff15d9
- improved check for branch version

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
# breaks keep-alive -- sucks!
37
37
 
38
38
 
39
 
ENABLE_URLGRABBER = True
40
 
 
 
39
ENABLE_URLGRABBER = False
 
40
 
 
41
from bzrlib.errors import BzrError, NoSuchRevision
 
42
 
 
43
class GetFailed(BzrError):
 
44
    def __init__(self, url, status):
 
45
        BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
 
46
        self.url = url
 
47
        self.status = status
41
48
 
42
49
if ENABLE_URLGRABBER:
43
 
    import urlgrabber
44
 
    import urlgrabber.keepalive
45
 
    urlgrabber.keepalive.DEBUG = 0
 
50
    import util.urlgrabber
 
51
    import util.urlgrabber.keepalive
 
52
    util.urlgrabber.keepalive.DEBUG = 0
46
53
    def get_url(path, compressed=False):
47
54
        try:
48
55
            url = path
49
56
            if compressed:
50
57
                url += '.gz'
51
58
            mutter("grab url %s" % url)
52
 
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
59
            url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
60
            if url_f.status != 200:
 
61
                raise GetFailed(url, url_f.status)
53
62
            if not compressed:
54
63
                return url_f
55
64
            else:
146
155
 
147
156
    def get_revision(self, revision_id):
148
157
        from bzrlib.revision import Revision
149
 
        from bzrlib.xml import unpack_xml
150
 
        revf = self.revision_store[revision_id]
151
 
        r = unpack_xml(Revision, revf)
 
158
        try:
 
159
            revf = self.revision_store[revision_id]
 
160
        except KeyError:
 
161
            raise NoSuchRevision(self, revision_id)
 
162
        r = serializer_v4.read_revision(revf)
152
163
        if r.revision_id != revision_id:
153
164
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
154
165
                                % (revision_id, r.revision_id))
167
178
        
168
179
    def __getitem__(self, fileid):
169
180
        p = self._path(fileid)
170
 
        return get_url(p, compressed=True)
 
181
        try:
 
182
            return get_url(p, compressed=True)
 
183
        except:
 
184
            raise KeyError(fileid)
171
185
    
172
186
 
173
187