~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: Martin Pool
  • Date: 2005-05-09 05:59:53 UTC
  • Revision ID: mbp@sourcefrog.net-20050509055953-5860b2761632a4ad
- RemoteBranch displays the log of a remote branch.
- Use the urllib2 library which comes with Python rather than the 
  urlgrabber extension.

  For the way we use it at the moment urlgrabber is not much faster
  or better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
 
 
20
"""Proxy object for access to remote branches.
 
21
 
 
22
At the moment remote branches are only for HTTP and only for read
 
23
access.
 
24
 
 
25
"""
 
26
 
 
27
 
20
28
## XXX: This is pretty slow on high-latency connections because it
21
29
## doesn't keep the HTTP connection alive.  If you have a smart local
22
30
## proxy it may be much better.  Eventually I want to switch to
23
31
## urlgrabber which should use HTTP much more efficiently.
24
32
 
25
33
 
26
 
import urllib2, gzip, zlib
 
34
import gzip
27
35
from sets import Set
28
36
from cStringIO import StringIO
29
37
 
30
 
from errors import BzrError
 
38
from errors import BzrError, BzrCheckError
31
39
from revision import Revision
32
40
from branch import Branch
33
41
from inventory import Inventory
39
47
# breaks keep-alive -- sucks!
40
48
 
41
49
 
42
 
import urlgrabber.keepalive
43
 
urlgrabber.keepalive.DEBUG = 2
44
50
 
45
 
import urlgrabber
46
51
 
47
52
# prefix = 'http://localhost:8000'
48
53
BASE_URL = 'http://bazaar-ng.org/bzr/bzr.dev/'
49
54
 
50
 
def get_url(path, compressed=False):
51
 
    try:
52
 
        url = path
53
 
        if compressed:
54
 
            url += '.gz'
55
 
        url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
56
 
        if not compressed:
57
 
            return url_f
58
 
        else:
59
 
            return gzip.GzipFile(fileobj=StringIO(url_f.read()))
60
 
    except urllib2.URLError, e:
61
 
        raise BzrError("remote fetch failed: %r: %s" % (url, e))
 
55
ENABLE_URLGRABBER = False
 
56
 
 
57
def get_url(url, compressed=False):
 
58
    import urllib2
 
59
    if compressed:
 
60
        url += '.gz'
 
61
    url_f = urllib2.urlopen(url)
 
62
    if compressed:
 
63
        return gzip.GzipFile(fileobj=StringIO(url_f.read()))
 
64
    else:
 
65
        return url_f
 
66
 
 
67
if ENABLE_URLGRABBER:
 
68
    import urlgrabber
 
69
    import urlgrabber.keepalive
 
70
    urlgrabber.keepalive.DEBUG = 0
 
71
    def get_url(path, compressed=False):
 
72
        try:
 
73
            url = path
 
74
            if compressed:
 
75
                url += '.gz'
 
76
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
 
77
            if not compressed:
 
78
                return url_f
 
79
            else:
 
80
                return gzip.GzipFile(fileobj=StringIO(url_f.read()))
 
81
        except urllib2.URLError, e:
 
82
            raise BzrError("remote fetch failed: %r: %s" % (url, e))
62
83
 
63
84
 
64
85
class RemoteBranch(Branch):
67
88
        self.baseurl = baseurl
68
89
        self._check_format()
69
90
 
70
 
 
71
91
    def controlfile(self, filename, mode):
72
92
        if mode not in ('rb', 'rt', 'r'):
73
93
            raise BzrError("file mode %r not supported for remote branches" % mode)
79
99
 
80
100
    def _need_writelock(self):
81
101
        raise BzrError("cannot get write lock on HTTP remote branch")
 
102
 
 
103
    def get_revision(self, revision_id):
 
104
        from revision import Revision
 
105
        revf = get_url(self.baseurl + '/.bzr/revision-store/' + revision_id,
 
106
                       True)
 
107
        r = Revision.read_xml(revf)
 
108
        if r.revision_id != revision_id:
 
109
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
 
110
                                % (revision_id, r.revision_id))
 
111
        return r
82
112
    
83
113
 
84
 
 
85
114
def simple_walk():
86
115
    got_invs = Set()
87
116
    got_texts = Set()
127
156
 
128
157
def try_me():
129
158
    b = RemoteBranch(BASE_URL)
130
 
    print '\n'.join(b.revision_history())
 
159
    ## print '\n'.join(b.revision_history())
 
160
    from log import show_log
 
161
    show_log(b)
131
162
 
132
163
 
133
164
if __name__ == '__main__':