4 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
4 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
5 # |
5 # |
6 # This software may be used and distributed according to the terms of the |
6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. |
7 # GNU General Public License version 2 or any later version. |
8 |
8 |
9 import os, re, time |
9 import os, re, time, urlparse |
10 from mercurial.i18n import _ |
10 from mercurial.i18n import _ |
11 from mercurial import ui, hg, util, templater |
11 from mercurial import ui, hg, util, templater |
12 from mercurial import error, encoding |
12 from mercurial import error, encoding |
13 from common import ErrorResponse, get_mtime, staticfile, paritygen, \ |
13 from common import ErrorResponse, get_mtime, staticfile, paritygen, \ |
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
224 parts = [name] |
224 parts = [name] |
225 if 'PATH_INFO' in req.env: |
225 if 'PATH_INFO' in req.env: |
226 parts.insert(0, req.env['PATH_INFO'].rstrip('/')) |
226 parts.insert(0, req.env['PATH_INFO'].rstrip('/')) |
227 if req.env['SCRIPT_NAME']: |
227 if req.env['SCRIPT_NAME']: |
228 parts.insert(0, req.env['SCRIPT_NAME']) |
228 parts.insert(0, req.env['SCRIPT_NAME']) |
229 m = re.match('((?:https?://)?)(.*)', '/'.join(parts)) |
229 url = re.sub(r'/+', '/', '/'.join(parts) + '/') |
230 # squish repeated slashes out of the path component |
|
231 url = m.group(1) + re.sub('/+', '/', m.group(2)) + '/' |
|
232 |
230 |
233 # update time with local timezone |
231 # update time with local timezone |
234 try: |
232 try: |
235 r = hg.repository(self.ui, path) |
233 r = hg.repository(self.ui, path) |
236 d = (get_mtime(r.spath), util.makedate()[1]) |
234 d = (get_mtime(r.spath), util.makedate()[1]) |
279 "%s%s" % ((not descending and column == sortcolumn) |
277 "%s%s" % ((not descending and column == sortcolumn) |
280 and "-" or "", column)) |
278 and "-" or "", column)) |
281 for column in sortable] |
279 for column in sortable] |
282 |
280 |
283 self.refresh() |
281 self.refresh() |
284 if self._baseurl is not None: |
282 self.updatereqenv(req.env) |
285 req.env['SCRIPT_NAME'] = self._baseurl |
|
286 |
283 |
287 return tmpl("index", entries=entries, subdir=subdir, |
284 return tmpl("index", entries=entries, subdir=subdir, |
288 sortcolumn=sortcolumn, descending=descending, |
285 sortcolumn=sortcolumn, descending=descending, |
289 **dict(sort)) |
286 **dict(sort)) |
290 |
287 |
303 yield config('web', 'motd', '') |
300 yield config('web', 'motd', '') |
304 |
301 |
305 def config(section, name, default=None, untrusted=True): |
302 def config(section, name, default=None, untrusted=True): |
306 return self.ui.config(section, name, default, untrusted) |
303 return self.ui.config(section, name, default, untrusted) |
307 |
304 |
308 if self._baseurl is not None: |
305 self.updatereqenv(req.env) |
309 req.env['SCRIPT_NAME'] = self._baseurl |
|
310 |
306 |
311 url = req.env.get('SCRIPT_NAME', '') |
307 url = req.env.get('SCRIPT_NAME', '') |
312 if not url.endswith('/'): |
308 if not url.endswith('/'): |
313 url += '/' |
309 url += '/' |
314 |
310 |
334 "motd": motd, |
330 "motd": motd, |
335 "url": url, |
331 "url": url, |
336 "staticurl": staticurl, |
332 "staticurl": staticurl, |
337 "sessionvars": sessionvars}) |
333 "sessionvars": sessionvars}) |
338 return tmpl |
334 return tmpl |
|
335 |
|
336 def updatereqenv(self, env): |
|
337 def splitnetloc(netloc): |
|
338 if ':' in netloc: |
|
339 return netloc.split(':', 1) |
|
340 else: |
|
341 return (netloc, None) |
|
342 |
|
343 if self._baseurl is not None: |
|
344 urlcomp = urlparse.urlparse(self._baseurl) |
|
345 host, port = splitnetloc(urlcomp[1]) |
|
346 path = urlcomp[2] |
|
347 env['SERVER_NAME'] = host |
|
348 if port: |
|
349 env['SERVER_PORT'] = port |
|
350 env['SCRIPT_NAME'] = path |