1
# Copyright (C) 2008, 2009, 2010 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
17
1
"""The WSGI application for serving a Bazaar branch."""
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
88
71
for k, v in kw.iteritems():
90
qs.append('%s=%s' % (k, urllib.quote(v)))
73
qs.append('%s=%s'%(k, urllib.quote(v)))
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
129
def public_branch_url(self):
112
def branch_url(self):
130
113
return self.branch.get_config().get_user_option('public_branch')
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
147
# Loggerhead only supports serving .bzr/ on local branches, so
148
# we shouldn't suggest something that won't work.
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)
156
129
raise httpexceptions.HTTPMovedPermanently(