1
# Copyright (C) 2005 Canonical Ltd
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.
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.
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
18
## XXX: This is pretty slow on high-latency connections because it
19
## doesn't keep the HTTP connection alive. If you have a smart local
20
## proxy it may be much better. Eventually I want to switch to
21
## urlgrabber which should use HTTP much more efficiently.
24
import urllib2, gzip, zlib
26
from cStringIO import StringIO
28
from errors import BzrError
29
from revision import Revision
30
from inventory import Inventory
32
# h = HTTPConnection('localhost:8000')
33
# h = HTTPConnection('bazaar-ng.org')
35
# velocitynet.com.au transparently proxies connections and thereby
36
# breaks keep-alive -- sucks!
39
import urlgrabber.keepalive
40
urlgrabber.keepalive.DEBUG = 2
44
prefix = 'http://localhost:8000'
45
# prefix = 'http://bazaar-ng.org/bzr/main/'
47
def get_url(path, compressed=False):
52
url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
56
return gzip.GzipFile(fileobj=StringIO(url_f.read()))
57
except urllib2.URLError, e:
58
raise BzrError("remote fetch failed: %r: %s" % (url, e))
65
history = get_url('/.bzr/revision-history').readlines()
66
num_revs = len(history)
67
for i, rev_id in enumerate(history):
68
rev_id = rev_id.rstrip()
69
print 'read revision %d/%d' % (i, num_revs)
71
# python gzip needs a seekable file (!!) but the HTTP response
72
# isn't, so we need to buffer it
74
rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
77
rev = Revision.read_xml(rev_f)
79
inv_id = rev.inventory_id
80
if inv_id not in got_invs:
81
print 'get inventory %s' % inv_id
82
inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
84
inv = Inventory.read_xml(inv_f)
85
print '%4d inventory entries' % len(inv)
87
for path, ie in inv.iter_entries():
91
if text_id in got_texts:
93
print ' fetch %s text {%s}' % (path, text_id)
94
text_f = get_url('/.bzr/text-store/%s' % text_id,
96
got_texts.add(text_id)