2006-06-02 19:05:01 +04:00
|
|
|
# hgweb/hgwebdir_mod.py - Web interface for a directory of repositories.
|
2006-05-31 21:42:44 +04:00
|
|
|
#
|
|
|
|
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
|
2006-08-12 23:30:02 +04:00
|
|
|
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
|
2006-05-31 21:42:44 +04:00
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2010-03-10 18:28:27 +03:00
|
|
|
import os, re, time, urlparse
|
2008-10-21 19:47:49 +04:00
|
|
|
from mercurial.i18n import _
|
2009-05-12 14:04:05 +04:00
|
|
|
from mercurial import ui, hg, util, templater
|
2009-05-11 16:20:18 +04:00
|
|
|
from mercurial import error, encoding
|
2010-02-08 17:36:34 +03:00
|
|
|
from common import ErrorResponse, get_mtime, staticfile, paritygen, \
|
2008-02-01 12:31:13 +03:00
|
|
|
get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
|
2006-12-13 22:27:09 +03:00
|
|
|
from hgweb_mod import hgweb
|
2007-11-30 20:23:18 +03:00
|
|
|
from request import wsgirequest
|
2009-04-27 13:37:30 +04:00
|
|
|
import webutil
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2009-04-27 13:37:08 +04:00
|
|
|
def cleannames(items):
|
|
|
|
return [(util.pconvert(name).strip('/'), path) for name, path in items]
|
|
|
|
|
2009-05-20 18:04:37 +04:00
|
|
|
def findrepos(paths):
|
2009-11-05 17:01:00 +03:00
|
|
|
repos = []
|
2009-05-20 18:04:37 +04:00
|
|
|
for prefix, root in cleannames(paths):
|
|
|
|
roothead, roottail = os.path.split(root)
|
|
|
|
# "foo = /bar/*" makes every subrepo of /bar/ to be
|
|
|
|
# mounted as foo/subrepo
|
|
|
|
# and "foo = /bar/**" also recurses into the subdirectories,
|
|
|
|
# remember to use it without working dir.
|
|
|
|
try:
|
|
|
|
recurse = {'*': False, '**': True}[roottail]
|
|
|
|
except KeyError:
|
2009-11-05 17:01:00 +03:00
|
|
|
repos.append((prefix, root))
|
2009-05-20 18:04:37 +04:00
|
|
|
continue
|
2010-07-22 00:22:28 +04:00
|
|
|
roothead = os.path.normpath(os.path.abspath(roothead))
|
2011-02-15 03:04:10 +03:00
|
|
|
paths = util.walkrepos(roothead, followsym=True, recurse=recurse)
|
|
|
|
repos.extend(urlrepos(prefix, roothead, paths))
|
2009-11-05 17:01:00 +03:00
|
|
|
return repos
|
2009-05-20 18:04:37 +04:00
|
|
|
|
2011-02-15 03:04:10 +03:00
|
|
|
def urlrepos(prefix, roothead, paths):
|
|
|
|
"""yield url paths and filesystem paths from a list of repo paths
|
|
|
|
|
|
|
|
>>> list(urlrepos('hg', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
|
2011-02-15 03:04:10 +03:00
|
|
|
[('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg', '/opt')]
|
2011-02-15 03:04:10 +03:00
|
|
|
>>> list(urlrepos('', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
|
|
|
|
[('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')]
|
|
|
|
"""
|
|
|
|
for path in paths:
|
|
|
|
path = os.path.normpath(path)
|
2011-02-15 03:04:10 +03:00
|
|
|
yield (prefix + '/' +
|
|
|
|
util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path
|
2011-02-15 03:04:10 +03:00
|
|
|
|
2006-05-31 21:42:44 +04:00
|
|
|
class hgwebdir(object):
|
2009-05-14 00:30:28 +04:00
|
|
|
refreshinterval = 20
|
2009-04-27 13:37:08 +04:00
|
|
|
|
2009-04-27 01:50:43 +04:00
|
|
|
def __init__(self, conf, baseui=None):
|
2009-05-14 00:30:28 +04:00
|
|
|
self.conf = conf
|
|
|
|
self.baseui = baseui
|
|
|
|
self.lastrefresh = 0
|
2009-11-22 13:25:01 +03:00
|
|
|
self.motd = None
|
2009-05-14 00:30:28 +04:00
|
|
|
self.refresh()
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2009-05-14 00:30:28 +04:00
|
|
|
def refresh(self):
|
|
|
|
if self.lastrefresh + self.refreshinterval > time.time():
|
|
|
|
return
|
|
|
|
|
|
|
|
if self.baseui:
|
2010-05-14 21:57:24 +04:00
|
|
|
u = self.baseui.copy()
|
2009-04-24 00:40:10 +04:00
|
|
|
else:
|
2010-10-11 02:35:28 +04:00
|
|
|
u = ui.ui()
|
2010-05-14 21:57:24 +04:00
|
|
|
u.setconfig('ui', 'report_untrusted', 'off')
|
|
|
|
u.setconfig('ui', 'interactive', 'off')
|
2009-04-24 00:40:10 +04:00
|
|
|
|
2009-05-20 18:04:37 +04:00
|
|
|
if not isinstance(self.conf, (dict, list, tuple)):
|
|
|
|
map = {'paths': 'hgweb-paths'}
|
2010-12-30 00:23:16 +03:00
|
|
|
if not os.path.exists(self.conf):
|
|
|
|
raise util.Abort(_('config file %s not found!') % self.conf)
|
2010-05-14 21:57:24 +04:00
|
|
|
u.readconfig(self.conf, remap=map, trust=True)
|
|
|
|
paths = u.configitems('hgweb-paths')
|
2009-05-20 18:04:37 +04:00
|
|
|
elif isinstance(self.conf, (list, tuple)):
|
|
|
|
paths = self.conf
|
|
|
|
elif isinstance(self.conf, dict):
|
|
|
|
paths = self.conf.items()
|
2009-05-11 16:20:18 +04:00
|
|
|
|
2010-05-14 21:57:24 +04:00
|
|
|
repos = findrepos(paths)
|
|
|
|
for prefix, root in u.configitems('collections'):
|
2009-05-22 00:41:18 +04:00
|
|
|
prefix = util.pconvert(prefix)
|
2009-05-14 17:24:36 +04:00
|
|
|
for path in util.walkrepos(root, followsym=True):
|
|
|
|
repo = os.path.normpath(path)
|
2009-05-22 00:41:18 +04:00
|
|
|
name = util.pconvert(repo)
|
2009-05-14 17:24:36 +04:00
|
|
|
if name.startswith(prefix):
|
|
|
|
name = name[len(prefix):]
|
2010-05-14 21:57:24 +04:00
|
|
|
repos.append((name.lstrip('/'), repo))
|
2009-05-11 16:20:18 +04:00
|
|
|
|
2010-05-14 21:57:24 +04:00
|
|
|
self.repos = repos
|
|
|
|
self.ui = u
|
|
|
|
encoding.encoding = self.ui.config('web', 'encoding',
|
|
|
|
encoding.encoding)
|
|
|
|
self.style = self.ui.config('web', 'style', 'paper')
|
2010-07-12 18:07:58 +04:00
|
|
|
self.templatepath = self.ui.config('web', 'templates', None)
|
2010-05-14 21:57:24 +04:00
|
|
|
self.stripecount = self.ui.config('web', 'stripes', 1)
|
|
|
|
if self.stripecount:
|
|
|
|
self.stripecount = int(self.stripecount)
|
|
|
|
self._baseurl = self.ui.config('web', 'baseurl')
|
2009-05-14 00:30:28 +04:00
|
|
|
self.lastrefresh = time.time()
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2006-06-30 06:06:18 +04:00
|
|
|
def run(self):
|
2006-06-30 20:50:25 +04:00
|
|
|
if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
|
2009-05-31 03:30:16 +04:00
|
|
|
raise RuntimeError("This function is only intended to be "
|
|
|
|
"called while running as a CGI script.")
|
2006-06-30 06:06:18 +04:00
|
|
|
import mercurial.hgweb.wsgicgi as wsgicgi
|
2007-11-30 20:23:18 +03:00
|
|
|
wsgicgi.launch(self)
|
|
|
|
|
|
|
|
def __call__(self, env, respond):
|
|
|
|
req = wsgirequest(env, respond)
|
2008-06-30 00:36:18 +04:00
|
|
|
return self.run_wsgi(req)
|
2006-06-30 06:06:18 +04:00
|
|
|
|
2008-10-31 17:28:06 +03:00
|
|
|
def read_allowed(self, ui, req):
|
|
|
|
"""Check allow_read and deny_read config options of a repo's ui object
|
|
|
|
to determine user permissions. By default, with neither option set (or
|
|
|
|
both empty), allow all users to read the repo. There are two ways a
|
|
|
|
user can be denied read access: (1) deny_read is not empty, and the
|
|
|
|
user is unauthenticated or deny_read contains user (or *), and (2)
|
|
|
|
allow_read is not empty and the user is not in allow_read. Return True
|
|
|
|
if user is allowed to read the repo, else return False."""
|
|
|
|
|
|
|
|
user = req.env.get('REMOTE_USER')
|
|
|
|
|
2009-01-03 23:44:15 +03:00
|
|
|
deny_read = ui.configlist('web', 'deny_read', untrusted=True)
|
2008-10-31 17:28:06 +03:00
|
|
|
if deny_read and (not user or deny_read == ['*'] or user in deny_read):
|
|
|
|
return False
|
|
|
|
|
2009-01-03 23:44:15 +03:00
|
|
|
allow_read = ui.configlist('web', 'allow_read', untrusted=True)
|
2008-10-31 17:28:06 +03:00
|
|
|
# by default, allow reading if no allow_read option has been set
|
|
|
|
if (not allow_read) or (allow_read == ['*']) or (user in allow_read):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2006-06-30 06:06:18 +04:00
|
|
|
def run_wsgi(self, req):
|
2007-12-03 20:40:37 +03:00
|
|
|
try:
|
|
|
|
try:
|
2009-05-14 00:30:28 +04:00
|
|
|
self.refresh()
|
2007-12-03 21:19:12 +03:00
|
|
|
|
2007-12-03 20:40:37 +03:00
|
|
|
virtual = req.env.get("PATH_INFO", "").strip('/')
|
2008-02-01 12:31:13 +03:00
|
|
|
tmpl = self.templater(req)
|
2009-04-03 23:51:48 +04:00
|
|
|
ctype = tmpl('mimetype', encoding=encoding.encoding)
|
2008-03-24 20:18:39 +03:00
|
|
|
ctype = templater.stringify(ctype)
|
2007-12-29 21:49:48 +03:00
|
|
|
|
2007-12-03 21:19:12 +03:00
|
|
|
# a static file
|
|
|
|
if virtual.startswith('static/') or 'static' in req.form:
|
|
|
|
if virtual.startswith('static/'):
|
|
|
|
fname = virtual[7:]
|
|
|
|
else:
|
|
|
|
fname = req.form['static'][0]
|
2008-10-17 22:34:31 +04:00
|
|
|
static = templater.templatepath('static')
|
2009-01-03 03:00:46 +03:00
|
|
|
return (staticfile(static, fname, req),)
|
2007-12-03 20:40:37 +03:00
|
|
|
|
2007-12-03 21:19:12 +03:00
|
|
|
# top-level index
|
|
|
|
elif not virtual:
|
2008-02-01 12:31:13 +03:00
|
|
|
req.respond(HTTP_OK, ctype)
|
2008-11-22 02:51:40 +03:00
|
|
|
return self.makeindex(req, tmpl)
|
2007-12-03 20:40:37 +03:00
|
|
|
|
2007-12-03 21:19:12 +03:00
|
|
|
# nested indexes and hgwebs
|
2008-03-07 02:24:36 +03:00
|
|
|
|
2007-12-03 21:19:12 +03:00
|
|
|
repos = dict(self.repos)
|
2010-11-30 17:45:25 +03:00
|
|
|
virtualrepo = virtual
|
|
|
|
while virtualrepo:
|
|
|
|
real = repos.get(virtualrepo)
|
2007-12-03 21:19:12 +03:00
|
|
|
if real:
|
2010-11-30 17:45:25 +03:00
|
|
|
req.env['REPO_NAME'] = virtualrepo
|
2007-12-03 21:19:12 +03:00
|
|
|
try:
|
2009-04-27 01:50:43 +04:00
|
|
|
repo = hg.repository(self.ui, real)
|
2008-06-30 00:36:18 +04:00
|
|
|
return hgweb(repo).run_wsgi(req)
|
2007-12-03 21:19:12 +03:00
|
|
|
except IOError, inst:
|
2008-02-01 12:31:13 +03:00
|
|
|
msg = inst.strerror
|
|
|
|
raise ErrorResponse(HTTP_SERVER_ERROR, msg)
|
2009-01-12 19:42:31 +03:00
|
|
|
except error.RepoError, inst:
|
2008-02-01 12:31:13 +03:00
|
|
|
raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
|
2007-12-03 20:40:37 +03:00
|
|
|
|
2010-11-30 17:45:25 +03:00
|
|
|
up = virtualrepo.rfind('/')
|
2007-12-03 21:19:12 +03:00
|
|
|
if up < 0:
|
|
|
|
break
|
2010-11-30 17:45:25 +03:00
|
|
|
virtualrepo = virtualrepo[:up]
|
|
|
|
|
|
|
|
# browse subdirectories
|
|
|
|
subdir = virtual + '/'
|
|
|
|
if [r for r in repos if r.startswith(subdir)]:
|
|
|
|
req.respond(HTTP_OK, ctype)
|
|
|
|
return self.makeindex(req, tmpl, subdir)
|
2007-12-03 21:19:12 +03:00
|
|
|
|
|
|
|
# prefixes not found
|
2008-02-01 12:31:13 +03:00
|
|
|
req.respond(HTTP_NOT_FOUND, ctype)
|
2008-11-22 02:51:40 +03:00
|
|
|
return tmpl("notfound", repo=virtual)
|
2007-12-29 21:49:48 +03:00
|
|
|
|
2007-12-03 20:40:37 +03:00
|
|
|
except ErrorResponse, err:
|
2009-02-09 13:29:09 +03:00
|
|
|
req.respond(err, ctype)
|
2008-11-22 02:51:40 +03:00
|
|
|
return tmpl('error', error=err.message or '')
|
2007-12-03 20:40:37 +03:00
|
|
|
finally:
|
|
|
|
tmpl = None
|
|
|
|
|
|
|
|
def makeindex(self, req, tmpl, subdir=""):
|
|
|
|
|
2006-05-31 21:42:44 +04:00
|
|
|
def archivelist(ui, nodeid, url):
|
2006-10-26 21:25:45 +04:00
|
|
|
allowed = ui.configlist("web", "allow_archive", untrusted=True)
|
2006-10-05 04:04:40 +04:00
|
|
|
for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
|
2006-10-26 21:25:45 +04:00
|
|
|
if i[0] in allowed or ui.configbool("web", "allow" + i[0],
|
|
|
|
untrusted=True):
|
2006-10-05 04:04:40 +04:00
|
|
|
yield {"type" : i[0], "extension": i[1],
|
|
|
|
"node": nodeid, "url": url}
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2010-03-06 14:45:14 +03:00
|
|
|
def rawentries(subdir="", **map):
|
2009-08-19 14:47:04 +04:00
|
|
|
|
|
|
|
descend = self.ui.configbool('web', 'descend', True)
|
2006-05-31 21:42:44 +04:00
|
|
|
for name, path in self.repos:
|
2009-08-19 14:47:04 +04:00
|
|
|
|
2007-07-06 06:44:06 +04:00
|
|
|
if not name.startswith(subdir):
|
|
|
|
continue
|
2007-07-06 06:56:16 +04:00
|
|
|
name = name[len(subdir):]
|
2009-08-19 14:47:04 +04:00
|
|
|
if not descend and '/' in name:
|
|
|
|
continue
|
2007-07-06 06:44:06 +04:00
|
|
|
|
2009-04-27 01:50:43 +04:00
|
|
|
u = self.ui.copy()
|
2006-05-31 21:42:44 +04:00
|
|
|
try:
|
|
|
|
u.readconfig(os.path.join(path, '.hg', 'hgrc'))
|
2007-09-25 02:00:11 +04:00
|
|
|
except Exception, e:
|
2008-08-16 16:46:56 +04:00
|
|
|
u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e))
|
2007-09-25 02:00:11 +04:00
|
|
|
continue
|
2006-10-26 21:25:45 +04:00
|
|
|
def get(section, name, default=None):
|
|
|
|
return u.config(section, name, default, untrusted=True)
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2007-06-25 16:46:20 +04:00
|
|
|
if u.configbool("web", "hidden", untrusted=True):
|
|
|
|
continue
|
|
|
|
|
2008-10-31 17:28:06 +03:00
|
|
|
if not self.read_allowed(u, req):
|
|
|
|
continue
|
|
|
|
|
2008-04-03 15:14:43 +04:00
|
|
|
parts = [name]
|
|
|
|
if 'PATH_INFO' in req.env:
|
|
|
|
parts.insert(0, req.env['PATH_INFO'].rstrip('/'))
|
2007-12-01 21:19:08 +03:00
|
|
|
if req.env['SCRIPT_NAME']:
|
2007-12-29 21:49:48 +03:00
|
|
|
parts.insert(0, req.env['SCRIPT_NAME'])
|
2010-03-10 18:28:31 +03:00
|
|
|
url = re.sub(r'/+', '/', '/'.join(parts) + '/')
|
2006-05-31 21:42:44 +04:00
|
|
|
|
|
|
|
# update time with local timezone
|
|
|
|
try:
|
2009-12-15 23:33:04 +03:00
|
|
|
r = hg.repository(self.ui, path)
|
2010-08-24 18:30:51 +04:00
|
|
|
except error.RepoError:
|
|
|
|
u.warn(_('error accessing repository at %s\n') % path)
|
|
|
|
continue
|
|
|
|
try:
|
2009-12-15 23:33:04 +03:00
|
|
|
d = (get_mtime(r.spath), util.makedate()[1])
|
2006-05-31 21:42:44 +04:00
|
|
|
except OSError:
|
|
|
|
continue
|
|
|
|
|
2008-01-01 19:07:15 +03:00
|
|
|
contact = get_contact(get)
|
2006-05-31 21:42:44 +04:00
|
|
|
description = get("web", "description", "")
|
|
|
|
name = get("web", "name", name)
|
|
|
|
row = dict(contact=contact or "unknown",
|
|
|
|
contact_sort=contact.upper() or "unknown",
|
|
|
|
name=name,
|
|
|
|
name_sort=name,
|
|
|
|
url=url,
|
|
|
|
description=description or "unknown",
|
|
|
|
description_sort=description.upper() or "unknown",
|
|
|
|
lastchange=d,
|
|
|
|
lastchange_sort=d[1]-d[0],
|
|
|
|
archives=archivelist(u, "tip", url))
|
2010-03-06 14:45:14 +03:00
|
|
|
yield row
|
|
|
|
|
|
|
|
sortdefault = None, False
|
|
|
|
def entries(sortcolumn="", descending=False, subdir="", **map):
|
|
|
|
rows = rawentries(subdir=subdir, **map)
|
|
|
|
|
|
|
|
if sortcolumn and sortdefault != (sortcolumn, descending):
|
|
|
|
sortkey = '%s_sort' % sortcolumn
|
|
|
|
rows = sorted(rows, key=lambda x: x[sortkey],
|
|
|
|
reverse=descending)
|
|
|
|
for row, parity in zip(rows, paritygen(self.stripecount)):
|
|
|
|
row['parity'] = parity
|
|
|
|
yield row
|
2006-05-31 21:42:44 +04:00
|
|
|
|
2009-05-14 00:30:28 +04:00
|
|
|
self.refresh()
|
2007-12-03 20:40:37 +03:00
|
|
|
sortable = ["name", "description", "contact", "lastchange"]
|
2009-05-11 16:19:49 +04:00
|
|
|
sortcolumn, descending = sortdefault
|
2008-01-20 16:39:25 +03:00
|
|
|
if 'sort' in req.form:
|
2007-12-03 20:40:37 +03:00
|
|
|
sortcolumn = req.form['sort'][0]
|
|
|
|
descending = sortcolumn.startswith('-')
|
|
|
|
if descending:
|
|
|
|
sortcolumn = sortcolumn[1:]
|
|
|
|
if sortcolumn not in sortable:
|
|
|
|
sortcolumn = ""
|
2007-07-21 12:30:51 +04:00
|
|
|
|
2007-12-03 20:40:37 +03:00
|
|
|
sort = [("sort_%s" % column,
|
|
|
|
"%s%s" % ((not descending and column == sortcolumn)
|
|
|
|
and "-" or "", column))
|
|
|
|
for column in sortable]
|
2008-01-22 12:45:55 +03:00
|
|
|
|
2009-05-14 00:30:28 +04:00
|
|
|
self.refresh()
|
2010-03-10 18:25:46 +03:00
|
|
|
self.updatereqenv(req.env)
|
2008-03-09 04:19:18 +03:00
|
|
|
|
2008-01-28 18:35:02 +03:00
|
|
|
return tmpl("index", entries=entries, subdir=subdir,
|
|
|
|
sortcolumn=sortcolumn, descending=descending,
|
|
|
|
**dict(sort))
|
2007-12-03 20:58:18 +03:00
|
|
|
|
|
|
|
def templater(self, req):
|
|
|
|
|
|
|
|
def header(**map):
|
2009-04-03 23:51:48 +04:00
|
|
|
yield tmpl('header', encoding=encoding.encoding, **map)
|
2007-12-03 20:58:18 +03:00
|
|
|
|
|
|
|
def footer(**map):
|
|
|
|
yield tmpl("footer", **map)
|
|
|
|
|
|
|
|
def motd(**map):
|
|
|
|
if self.motd is not None:
|
|
|
|
yield self.motd
|
|
|
|
else:
|
|
|
|
yield config('web', 'motd', '')
|
|
|
|
|
|
|
|
def config(section, name, default=None, untrusted=True):
|
2009-04-27 01:50:43 +04:00
|
|
|
return self.ui.config(section, name, default, untrusted)
|
2007-12-03 20:58:18 +03:00
|
|
|
|
2010-03-10 18:25:46 +03:00
|
|
|
self.updatereqenv(req.env)
|
2008-03-09 04:19:18 +03:00
|
|
|
|
2007-12-03 20:58:18 +03:00
|
|
|
url = req.env.get('SCRIPT_NAME', '')
|
|
|
|
if not url.endswith('/'):
|
|
|
|
url += '/'
|
|
|
|
|
2009-04-27 13:37:30 +04:00
|
|
|
vars = {}
|
2009-11-12 18:39:11 +03:00
|
|
|
styles = (
|
|
|
|
req.form.get('style', [None])[0],
|
|
|
|
config('web', 'style'),
|
|
|
|
'paper'
|
|
|
|
)
|
2010-07-12 18:07:58 +04:00
|
|
|
style, mapfile = templater.stylemap(styles, self.templatepath)
|
2009-11-12 18:39:11 +03:00
|
|
|
if style == styles[0]:
|
|
|
|
vars['style'] = style
|
2010-01-25 09:05:27 +03:00
|
|
|
|
2009-04-27 13:37:30 +04:00
|
|
|
start = url[-1] == '?' and '&' or '?'
|
|
|
|
sessionvars = webutil.sessionvars(vars, start)
|
2007-12-03 20:58:18 +03:00
|
|
|
staticurl = config('web', 'staticurl') or url + 'static/'
|
|
|
|
if not staticurl.endswith('/'):
|
|
|
|
staticurl += '/'
|
|
|
|
|
2009-05-12 14:04:05 +04:00
|
|
|
tmpl = templater.templater(mapfile,
|
2007-12-03 20:58:18 +03:00
|
|
|
defaults={"header": header,
|
|
|
|
"footer": footer,
|
|
|
|
"motd": motd,
|
|
|
|
"url": url,
|
2009-04-27 13:37:30 +04:00
|
|
|
"staticurl": staticurl,
|
|
|
|
"sessionvars": sessionvars})
|
2007-12-03 20:58:18 +03:00
|
|
|
return tmpl
|
2010-03-10 18:25:46 +03:00
|
|
|
|
|
|
|
def updatereqenv(self, env):
|
2010-03-10 18:28:27 +03:00
|
|
|
def splitnetloc(netloc):
|
|
|
|
if ':' in netloc:
|
|
|
|
return netloc.split(':', 1)
|
|
|
|
else:
|
|
|
|
return (netloc, None)
|
|
|
|
|
2010-03-10 18:25:46 +03:00
|
|
|
if self._baseurl is not None:
|
2010-03-10 18:28:27 +03:00
|
|
|
urlcomp = urlparse.urlparse(self._baseurl)
|
|
|
|
host, port = splitnetloc(urlcomp[1])
|
|
|
|
path = urlcomp[2]
|
|
|
|
env['SERVER_NAME'] = host
|
|
|
|
if port:
|
|
|
|
env['SERVER_PORT'] = port
|
|
|
|
env['SCRIPT_NAME'] = path
|