/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: Martin Pool
  • Date: 2005-06-28 05:33:40 UTC
  • Revision ID: mbp@sourcefrog.net-20050628053340-ea73b03fbcde9c46
- Remove XMLMixin class in favour of simple pack_xml, unpack_xml functions
  called as needed.  

- Avoid importing xml and ElementTree library unless needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
ENABLE_URLGRABBER = True
40
40
 
41
 
from bzrlib.errors import BzrError
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
48
41
 
49
42
if ENABLE_URLGRABBER:
50
43
    import urlgrabber
57
50
                url += '.gz'
58
51
            mutter("grab url %s" % url)
59
52
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
60
 
            if url_f.status != 200:
61
 
                raise GetFailed(url, url_f.status)
62
53
            if not compressed:
63
54
                return url_f
64
55
            else:
176
167
        
177
168
    def __getitem__(self, fileid):
178
169
        p = self._path(fileid)
179
 
        try:
180
 
            return get_url(p, compressed=True)
181
 
        except:
182
 
            raise KeyError(fileid)
 
170
        return get_url(p, compressed=True)
183
171
    
184
172
 
 
173
def simple_walk():
 
174
    """For experimental purposes, traverse many parts of a remote branch"""
 
175
    from bzrlib.revision import Revision
 
176
    from bzrlib.branch import Branch
 
177
    from bzrlib.inventory import Inventory
 
178
    from bzrlib.xml import unpack_xml
 
179
 
 
180
    got_invs = {}
 
181
    got_texts = {}
 
182
 
 
183
    print 'read history'
 
184
    history = get_url('/.bzr/revision-history').readlines()
 
185
    num_revs = len(history)
 
186
    for i, rev_id in enumerate(history):
 
187
        rev_id = rev_id.rstrip()
 
188
        print 'read revision %d/%d' % (i, num_revs)
 
189
 
 
190
        # python gzip needs a seekable file (!!) but the HTTP response
 
191
        # isn't, so we need to buffer it
 
192
 
 
193
        rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
 
194
                        compressed=True)
 
195
 
 
196
        rev = unpack_xml(Revision, rev_f)
 
197
        print rev.message
 
198
        inv_id = rev.inventory_id
 
199
        if inv_id not in got_invs:
 
200
            print 'get inventory %s' % inv_id
 
201
            inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
 
202
                            compressed=True)
 
203
            inv = Inventory.read_xml(inv_f)
 
204
            print '%4d inventory entries' % len(inv)
 
205
 
 
206
            for path, ie in inv.iter_entries():
 
207
                text_id = ie.text_id
 
208
                if text_id == None:
 
209
                    continue
 
210
                if text_id in got_texts:
 
211
                    continue
 
212
                print '  fetch %s text {%s}' % (path, text_id)
 
213
                text_f = get_url('/.bzr/text-store/%s' % text_id,
 
214
                                 compressed=True)
 
215
                got_texts[text_id] = True
 
216
 
 
217
            got_invs.add[inv_id] = True
 
218
 
 
219
        print '----'
 
220
 
 
221
 
 
222
def try_me():
 
223
    BASE_URL = 'http://bazaar-ng.org/bzr/bzr.dev/'
 
224
    b = RemoteBranch(BASE_URL)
 
225
    ## print '\n'.join(b.revision_history())
 
226
    from log import show_log
 
227
    show_log(b)
 
228
 
 
229
 
 
230
if __name__ == '__main__':
 
231
    try_me()
185
232