~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/branch.py

  • Committer: Matt Nordhoff
  • Date: 2009-05-06 18:48:16 UTC
  • Revision ID: mnordhoff@mattnordhoff.com-20090506184816-ghjchnf35b1rqzg7
Mark as compatible with bzrlib 1.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd.
2
 
#
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.
7
 
#
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.
12
 
#
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
16
 
#
17
1
"""The WSGI application for serving a Bazaar branch."""
18
2
 
19
3
import logging
21
5
import sys
22
6
 
23
7
import bzrlib.branch
24
 
import bzrlib.errors
25
8
import bzrlib.lru_cache
26
9
 
27
10
from paste import request
53
36
        self._config = config
54
37
        self.friendly_name = friendly_name
55
38
        self.branch_link = branch_link  # Currently only used in Launchpad
56
 
        self.log = logging.getLogger('loggerhead.%s' % (friendly_name,))
 
39
        self.log = logging.getLogger('loggerhead.%s' % friendly_name)
57
40
        if graph_cache is None:
58
41
            graph_cache = bzrlib.lru_cache.LRUCache(10)
59
42
        self.graph_cache = graph_cache
87
70
        qs = []
88
71
        for k, v in kw.iteritems():
89
72
            if v is not None:
90
 
                qs.append('%s=%s' % (k, urllib.quote(v)))
 
73
                qs.append('%s=%s'%(k, urllib.quote(v)))
91
74
        qs = '&'.join(qs)
92
75
        return request.construct_url(
93
76
            self._environ, script_name=self._url_base,
126
109
        change = h.get_changes([h.last_revid])[0]
127
110
        return change.date
128
111
 
129
 
    def public_branch_url(self):
 
112
    def branch_url(self):
130
113
        return self.branch.get_config().get_user_option('public_branch')
131
114
 
132
115
    def app(self, environ, start_response):
133
 
        # Check again if the branch is blocked from being served, this is
134
 
        # mostly for tests. It's already checked in apps/transport.py
135
 
        if self.branch.get_config().get_user_option('http_serve') == 'False':
136
 
            raise httpexceptions.HTTPNotFound()
137
116
        self._url_base = environ['SCRIPT_NAME']
138
117
        self._static_url_base = environ.get('loggerhead.static.url')
139
118
        if self._static_url_base is None:
140
119
            self._static_url_base = self._url_base
141
120
        self._environ = environ
142
121
        if self.served_url is _DEFAULT:
143
 
            public_branch = self.public_branch_url()
 
122
            public_branch = self.branch_url()
144
123
            if public_branch is not None:
145
124
                self.served_url = public_branch
146
125
            else:
147
 
                # Loggerhead only supports serving .bzr/ on local branches, so
148
 
                # we shouldn't suggest something that won't work.
149
 
                try:
150
 
                    util.local_path_from_url(self.branch.base)
151
 
                    self.served_url = self.url([])
152
 
                except bzrlib.errors.InvalidURL:
153
 
                    self.served_url = None
 
126
                self.served_url = self.url([])
154
127
        path = request.path_info_pop(environ)
155
128
        if not path:
156
129
            raise httpexceptions.HTTPMovedPermanently(