hgwebdir_mod.py
578 lines
| 19.2 KiB
| text/x-python
|
PythonLexer
|
r2391 | # hgweb/hgwebdir_mod.py - Web interface for a directory of repositories. | ||
|
r2356 | # | ||
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | ||||
|
r2859 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> | ||
|
r2356 | # | ||
|
r8225 | # This software may be used and distributed according to the terms of the | ||
|
r10263 | # GNU General Public License version 2 or any later version. | ||
|
r2356 | |||
|
r27046 | from __future__ import absolute_import | ||
|
r36929 | import gc | ||
|
r27046 | import os | ||
import time | ||||
from ..i18n import _ | ||||
from .common import ( | ||||
ErrorResponse, | ||||
HTTP_SERVER_ERROR, | ||||
|
r30766 | cspvalues, | ||
|
r27046 | get_contact, | ||
get_mtime, | ||||
ismember, | ||||
paritygen, | ||||
staticfile, | ||||
|
r36923 | statusmessage, | ||
|
r27046 | ) | ||
from .. import ( | ||||
|
r34241 | configitems, | ||
|
r27046 | encoding, | ||
error, | ||||
|
r40759 | extensions, | ||
|
r27046 | hg, | ||
|
r29787 | profiling, | ||
|
r34354 | pycompat, | ||
|
r38964 | registrar, | ||
|
r27046 | scmutil, | ||
templater, | ||||
|
r37526 | templateutil, | ||
|
r27046 | ui as uimod, | ||
util, | ||||
) | ||||
from . import ( | ||||
hgweb_mod, | ||||
|
r36822 | request as requestmod, | ||
|
r27046 | webutil, | ||
wsgicgi, | ||||
) | ||||
|
r36625 | from ..utils import dateutil | ||
|
r2356 | |||
|
r43346 | |||
|
r8215 | def cleannames(items): | ||
|
r43347 | return [(util.pconvert(name).strip(b'/'), path) for name, path in items] | ||
|
r2356 | |||
|
r43346 | |||
|
r8529 | def findrepos(paths): | ||
|
r9723 | repos = [] | ||
|
r8529 | for prefix, root in cleannames(paths): | ||
roothead, roottail = os.path.split(root) | ||||
|
r17104 | # "foo = /bar/*" or "foo = /bar/**" lets every repo /bar/N in or below | ||
# /bar/ be served as as foo/N . | ||||
# '*' will not search inside dirs with .hg (except .hg/patches), | ||||
# '**' will search inside dirs with .hg (and thus also find subrepos). | ||||
|
r8529 | try: | ||
|
r43347 | recurse = {b'*': False, b'**': True}[roottail] | ||
|
r8529 | except KeyError: | ||
|
r9723 | repos.append((prefix, root)) | ||
|
r8529 | continue | ||
|
r11677 | roothead = os.path.normpath(os.path.abspath(roothead)) | ||
|
r13975 | paths = scmutil.walkrepos(roothead, followsym=True, recurse=recurse) | ||
|
r13402 | repos.extend(urlrepos(prefix, roothead, paths)) | ||
|
r9723 | return repos | ||
|
r8529 | |||
|
r43346 | |||
|
r13402 | def urlrepos(prefix, roothead, paths): | ||
"""yield url paths and filesystem paths from a list of repo paths | ||||
|
r13538 | >>> conv = lambda seq: [(v, util.pconvert(p)) for v,p in seq] | ||
|
r34133 | >>> conv(urlrepos(b'hg', b'/opt', [b'/opt/r', b'/opt/r/r', b'/opt'])) | ||
|
r13403 | [('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg', '/opt')] | ||
|
r34133 | >>> conv(urlrepos(b'', b'/opt', [b'/opt/r', b'/opt/r/r', b'/opt'])) | ||
|
r13402 | [('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')] | ||
""" | ||||
for path in paths: | ||||
path = os.path.normpath(path) | ||||
|
r43346 | yield ( | ||
|
r43347 | prefix + b'/' + util.pconvert(path[len(roothead) :]).lstrip(b'/') | ||
).strip(b'/'), path | ||||
|
r43346 | |||
|
r13402 | |||
|
r36906 | def readallowed(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.remoteuser | ||||
|
r43347 | deny_read = ui.configlist(b'web', b'deny_read', untrusted=True) | ||
|
r36906 | if deny_read and (not user or ismember(ui, user, deny_read)): | ||
return False | ||||
|
r43347 | allow_read = ui.configlist(b'web', b'allow_read', untrusted=True) | ||
|
r36906 | # by default, allow reading if no allow_read option has been set | ||
if not allow_read or ismember(ui, user, allow_read): | ||||
return True | ||||
return False | ||||
|
r43346 | |||
|
r43347 | def rawindexentries(ui, repos, req, subdir=b''): | ||
descend = ui.configbool(b'web', b'descend') | ||||
collapse = ui.configbool(b'web', b'collapse') | ||||
|
r36908 | seenrepos = set() | ||
seendirs = set() | ||||
for name, path in repos: | ||||
if not name.startswith(subdir): | ||||
continue | ||||
|
r43346 | name = name[len(subdir) :] | ||
|
r36908 | directory = False | ||
|
r43347 | if b'/' in name: | ||
|
r36908 | if not descend: | ||
continue | ||||
|
r43347 | nameparts = name.split(b'/') | ||
|
r36908 | rootname = nameparts[0] | ||
if not collapse: | ||||
pass | ||||
elif rootname in seendirs: | ||||
continue | ||||
elif rootname in seenrepos: | ||||
pass | ||||
else: | ||||
directory = True | ||||
name = rootname | ||||
# redefine the path to refer to the directory | ||||
|
r43347 | discarded = b'/'.join(nameparts[1:]) | ||
|
r36908 | |||
# remove name parts plus accompanying slash | ||||
|
r43346 | path = path[: -len(discarded) - 1] | ||
|
r36908 | |||
try: | ||||
|
r41401 | hg.repository(ui, path) | ||
|
r36908 | directory = False | ||
except (IOError, error.RepoError): | ||||
pass | ||||
|
r36918 | parts = [ | ||
|
r43347 | req.apppath.strip(b'/'), | ||
subdir.strip(b'/'), | ||||
name.strip(b'/'), | ||||
|
r36918 | ] | ||
|
r43347 | url = b'/' + b'/'.join(p for p in parts if p) + b'/' | ||
|
r15003 | |||
|
r36908 | # show either a directory entry or a repository | ||
if directory: | ||||
# get the directory's time information | ||||
try: | ||||
d = (get_mtime(path), dateutil.makedate()[1]) | ||||
except OSError: | ||||
continue | ||||
# add '/' to the name to make it obvious that | ||||
# the entry is a directory, not a regular repository | ||||
|
r43346 | row = { | ||
|
r43347 | b'contact': b"", | ||
b'contact_sort': b"", | ||||
b'name': name + b'/', | ||||
b'name_sort': name, | ||||
b'url': url, | ||||
b'description': b"", | ||||
b'description_sort': b"", | ||||
b'lastchange': d, | ||||
b'lastchange_sort': d[1] - d[0], | ||||
b'archives': templateutil.mappinglist([]), | ||||
b'isdirectory': True, | ||||
b'labels': templateutil.hybridlist([], name=b'label'), | ||||
|
r43346 | } | ||
|
r36908 | |||
seendirs.add(name) | ||||
yield row | ||||
continue | ||||
u = ui.copy() | ||||
try: | ||||
|
r43347 | u.readconfig(os.path.join(path, b'.hg', b'hgrc')) | ||
|
r36908 | except Exception as e: | ||
|
r43347 | u.warn(_(b'error reading %s/.hg/hgrc: %s\n') % (path, e)) | ||
|
r36908 | continue | ||
def get(section, name, default=uimod._unset): | ||||
return u.config(section, name, default, untrusted=True) | ||||
|
r43347 | if u.configbool(b"web", b"hidden", untrusted=True): | ||
|
r36908 | continue | ||
if not readallowed(u, req): | ||||
continue | ||||
|
r15003 | |||
|
r36908 | # update time with local timezone | ||
try: | ||||
r = hg.repository(ui, path) | ||||
except IOError: | ||||
|
r43347 | u.warn(_(b'error accessing repository at %s\n') % path) | ||
|
r36908 | continue | ||
except error.RepoError: | ||||
|
r43347 | u.warn(_(b'error accessing repository at %s\n') % path) | ||
|
r36908 | continue | ||
try: | ||||
d = (get_mtime(r.spath), dateutil.makedate()[1]) | ||||
except OSError: | ||||
continue | ||||
contact = get_contact(get) | ||||
|
r43347 | description = get(b"web", b"description") | ||
|
r36908 | seenrepos.add(name) | ||
|
r43347 | name = get(b"web", b"name", name) | ||
labels = u.configlist(b'web', b'labels', untrusted=True) | ||||
|
r43346 | row = { | ||
|
r43347 | b'contact': contact or b"unknown", | ||
b'contact_sort': contact.upper() or b"unknown", | ||||
b'name': name, | ||||
b'name_sort': name, | ||||
b'url': url, | ||||
b'description': description or b"unknown", | ||||
b'description_sort': description.upper() or b"unknown", | ||||
b'lastchange': d, | ||||
b'lastchange_sort': d[1] - d[0], | ||||
b'archives': webutil.archivelist(u, b"tip", url), | ||||
b'isdirectory': None, | ||||
b'labels': templateutil.hybridlist(labels, name=b'label'), | ||||
|
r43346 | } | ||
|
r36908 | |||
yield row | ||||
|
r43346 | |||
def _indexentriesgen( | ||||
context, ui, repos, req, stripecount, sortcolumn, descending, subdir | ||||
): | ||||
|
r36920 | rows = rawindexentries(ui, repos, req, subdir=subdir) | ||
|
r36909 | |||
sortdefault = None, False | ||||
if sortcolumn and sortdefault != (sortcolumn, descending): | ||||
|
r43347 | sortkey = b'%s_sort' % sortcolumn | ||
|
r43346 | rows = sorted(rows, key=lambda x: x[sortkey], reverse=descending) | ||
|
r36909 | |||
for row, parity in zip(rows, paritygen(stripecount)): | ||||
|
r43347 | row[b'parity'] = parity | ||
|
r36909 | yield row | ||
|
r15003 | |||
|
r43346 | |||
def indexentries( | ||||
|
r43347 | ui, repos, req, stripecount, sortcolumn=b'', descending=False, subdir=b'' | ||
|
r43346 | ): | ||
|
r37526 | args = (ui, repos, req, stripecount, sortcolumn, descending, subdir) | ||
return templateutil.mappinggenerator(_indexentriesgen, args=args) | ||||
|
r43346 | |||
|
r2356 | class hgwebdir(object): | ||
|
r26132 | """HTTP server for multiple repositories. | ||
Given a configuration, different repositories will be served depending | ||||
on the request path. | ||||
Instances are typically used as WSGI applications. | ||||
""" | ||||
|
r43346 | |||
|
r8191 | def __init__(self, conf, baseui=None): | ||
|
r8371 | self.conf = conf | ||
self.baseui = baseui | ||||
|
r26072 | self.ui = None | ||
|
r8371 | self.lastrefresh = 0 | ||
|
r9903 | self.motd = None | ||
|
r8371 | self.refresh() | ||
|
r40759 | if not baseui: | ||
# set up environment for new ui | ||||
extensions.loadall(self.ui) | ||||
|
r40760 | extensions.populateui(self.ui) | ||
|
r2356 | |||
|
r8371 | def refresh(self): | ||
|
r26072 | if self.ui: | ||
|
r43347 | refreshinterval = self.ui.configint(b'web', b'refreshinterval') | ||
|
r34241 | else: | ||
|
r43347 | item = configitems.coreitems[b'web'][b'refreshinterval'] | ||
|
r34241 | refreshinterval = item.default | ||
|
r26072 | |||
# refreshinterval <= 0 means to always refresh. | ||||
|
r43346 | if ( | ||
refreshinterval > 0 | ||||
and self.lastrefresh + refreshinterval > time.time() | ||||
): | ||||
|
r8371 | return | ||
if self.baseui: | ||||
|
r11239 | u = self.baseui.copy() | ||
|
r2356 | else: | ||
|
r30559 | u = uimod.ui.load() | ||
|
r43347 | u.setconfig(b'ui', b'report_untrusted', b'off', b'hgwebdir') | ||
u.setconfig(b'ui', b'nontty', b'true', b'hgwebdir') | ||||
|
r25488 | # displaying bundling progress bar while serving feels wrong and may | ||
# break some wsgi implementations. | ||||
|
r43347 | u.setconfig(b'progress', b'disable', b'true', b'hgweb') | ||
|
r8136 | |||
|
r8529 | if not isinstance(self.conf, (dict, list, tuple)): | ||
|
r43347 | map = {b'paths': b'hgweb-paths'} | ||
|
r13214 | if not os.path.exists(self.conf): | ||
|
r43347 | raise error.Abort(_(b'config file %s not found!') % self.conf) | ||
|
r11239 | u.readconfig(self.conf, remap=map, trust=True) | ||
|
r13667 | paths = [] | ||
|
r43347 | for name, ignored in u.configitems(b'hgweb-paths'): | ||
for path in u.configlist(b'hgweb-paths', name): | ||||
|
r13667 | paths.append((name, path)) | ||
|
r8529 | elif isinstance(self.conf, (list, tuple)): | ||
paths = self.conf | ||||
elif isinstance(self.conf, dict): | ||||
paths = self.conf.items() | ||||
|
r40760 | extensions.populateui(u) | ||
|
r8345 | |||
|
r11239 | repos = findrepos(paths) | ||
|
r43347 | for prefix, root in u.configitems(b'collections'): | ||
|
r11239 | prefix = util.pconvert(prefix) | ||
|
r13975 | for path in scmutil.walkrepos(root, followsym=True): | ||
|
r11239 | repo = os.path.normpath(path) | ||
name = util.pconvert(repo) | ||||
if name.startswith(prefix): | ||||
|
r43346 | name = name[len(prefix) :] | ||
|
r43347 | repos.append((name.lstrip(b'/'), repo)) | ||
|
r11239 | |||
self.repos = repos | ||||
self.ui = u | ||||
|
r43347 | encoding.encoding = self.ui.config(b'web', b'encoding') | ||
self.style = self.ui.config(b'web', b'style') | ||||
self.templatepath = self.ui.config( | ||||
b'web', b'templates', untrusted=False | ||||
) | ||||
self.stripecount = self.ui.config(b'web', b'stripes') | ||||
|
r8621 | if self.stripecount: | ||
self.stripecount = int(self.stripecount) | ||||
|
r43347 | prefix = self.ui.config(b'web', b'prefix') | ||
if prefix.startswith(b'/'): | ||||
|
r18515 | prefix = prefix[1:] | ||
|
r43347 | if prefix.endswith(b'/'): | ||
|
r18515 | prefix = prefix[:-1] | ||
self.prefix = prefix | ||||
|
r8371 | self.lastrefresh = time.time() | ||
|
r2356 | |||
|
r2535 | def run(self): | ||
|
r43347 | if not encoding.environ.get(b'GATEWAY_INTERFACE', b'').startswith( | ||
b"CGI/1." | ||||
|
r43346 | ): | ||
raise RuntimeError( | ||||
|
r43347 | b"This function is only intended to be " | ||
b"called while running as a CGI script." | ||||
|
r43346 | ) | ||
|
r5566 | wsgicgi.launch(self) | ||
def __call__(self, env, respond): | ||||
|
r43347 | baseurl = self.ui.config(b'web', b'baseurl') | ||
|
r36928 | req = requestmod.parserequestfromenv(env, altbaseurl=baseurl) | ||
res = requestmod.wsgiresponse(req, respond) | ||||
|
r7336 | |||
|
r36928 | return self.run_wsgi(req, res) | ||
|
r7336 | |||
|
r36928 | def run_wsgi(self, req, res): | ||
|
r43347 | profile = self.ui.configbool(b'profiling', b'enabled') | ||
r32788 | with profiling.profile(self.ui, enabled=profile): | |||
|
r36929 | try: | ||
|
r36996 | for r in self._runwsgi(req, res): | ||
|
r36929 | yield r | ||
finally: | ||||
# There are known cycles in localrepository that prevent | ||||
# those objects (and tons of held references) from being | ||||
# collected through normal refcounting. We mitigate those | ||||
# leaks by performing an explicit GC on every request. | ||||
# TODO remove this once leaks are fixed. | ||||
# TODO only run this on requests that create localrepository | ||||
# instances instead of every request. | ||||
gc.collect() | ||||
|
r29786 | |||
|
r36928 | def _runwsgi(self, req, res): | ||
|
r5601 | try: | ||
|
r25083 | self.refresh() | ||
|
r5603 | |||
|
r30766 | csp, nonce = cspvalues(self.ui) | ||
if csp: | ||||
|
r43347 | res.headers[b'Content-Security-Policy'] = csp | ||
|
r30766 | |||
|
r43347 | virtual = req.dispatchpath.strip(b'/') | ||
|
r30766 | tmpl = self.templater(req, nonce) | ||
|
r43347 | ctype = tmpl.render(b'mimetype', {b'encoding': encoding.encoding}) | ||
|
r5760 | |||
|
r36889 | # Global defaults. These can be overridden by any handler. | ||
|
r43347 | res.status = b'200 Script output follows' | ||
res.headers[b'Content-Type'] = ctype | ||||
|
r5760 | |||
|
r25083 | # a static file | ||
|
r43347 | if virtual.startswith(b'static/') or b'static' in req.qsparams: | ||
if virtual.startswith(b'static/'): | ||||
|
r25083 | fname = virtual[7:] | ||
else: | ||||
|
r43347 | fname = req.qsparams[b'static'] | ||
static = self.ui.config(b"web", b"static", untrusted=False) | ||||
|
r25083 | if not static: | ||
tp = self.templatepath or templater.templatepaths() | ||||
if isinstance(tp, str): | ||||
tp = [tp] | ||||
|
r43347 | static = [os.path.join(p, b'static') for p in tp] | ||
|
r36889 | |||
staticfile(static, fname, res) | ||||
return res.sendresponse() | ||||
|
r5603 | |||
|
r25083 | # top-level index | ||
|
r31482 | |||
repos = dict(self.repos) | ||||
|
r43347 | if (not virtual or virtual == b'index') and virtual not in repos: | ||
|
r36921 | return self.makeindex(req, res, tmpl) | ||
|
r5601 | |||
|
r25083 | # nested indexes and hgwebs | ||
|
r6210 | |||
|
r43347 | if virtual.endswith(b'/index') and virtual not in repos: | ||
subdir = virtual[: -len(b'index')] | ||||
|
r31482 | if any(r.startswith(subdir) for r in repos): | ||
|
r36921 | return self.makeindex(req, res, tmpl, subdir) | ||
|
r31482 | |||
|
r32004 | def _virtualdirs(): | ||
|
r42530 | # Check the full virtual path, and each parent | ||
yield virtual | ||||
for p in util.finddirs(virtual): | ||||
yield p | ||||
|
r32004 | |||
for virtualrepo in _virtualdirs(): | ||||
|
r25083 | real = repos.get(virtualrepo) | ||
if real: | ||||
|
r36913 | # Re-parse the WSGI environment to take into account our | ||
# repository path component. | ||||
|
r37730 | uenv = req.rawenv | ||
if pycompat.ispy3: | ||||
|
r43346 | uenv = { | ||
|
r43376 | k.decode('latin1'): v | ||
for k, v in pycompat.iteritems(uenv) | ||||
|
r43346 | } | ||
|
r36928 | req = requestmod.parserequestfromenv( | ||
|
r43346 | uenv, | ||
reponame=virtualrepo, | ||||
|
r43347 | altbaseurl=self.ui.config(b'web', b'baseurl'), | ||
|
r37836 | # Reuse wrapped body file object otherwise state | ||
# tracking can get confused. | ||||
|
r43346 | bodyfh=req.bodyfh, | ||
) | ||||
|
r25083 | try: | ||
# ensure caller gets private copy of ui | ||||
repo = hg.repository(self.ui.copy(), real) | ||||
|
r36928 | return hgweb_mod.hgweb(repo).run_wsgi(req, res) | ||
|
r25660 | except IOError as inst: | ||
|
r34024 | msg = encoding.strtolocal(inst.strerror) | ||
|
r25083 | raise ErrorResponse(HTTP_SERVER_ERROR, msg) | ||
|
r25660 | except error.RepoError as inst: | ||
|
r34354 | raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) | ||
|
r5601 | |||
|
r25083 | # browse subdirectories | ||
|
r43347 | subdir = virtual + b'/' | ||
|
r25083 | if [r for r in repos if r.startswith(subdir)]: | ||
|
r36921 | return self.makeindex(req, res, tmpl, subdir) | ||
|
r5603 | |||
|
r25083 | # prefixes not found | ||
|
r43347 | res.status = b'404 Not Found' | ||
res.setbodygen(tmpl.generate(b'notfound', {b'repo': virtual})) | ||||
|
r36923 | return res.sendresponse() | ||
|
r5760 | |||
|
r36923 | except ErrorResponse as e: | ||
res.status = statusmessage(e.code, pycompat.bytestr(e)) | ||||
|
r43347 | res.setbodygen( | ||
tmpl.generate(b'error', {b'error': e.message or b''}) | ||||
) | ||||
|
r36923 | return res.sendresponse() | ||
|
r5601 | finally: | ||
tmpl = None | ||||
|
r43347 | def makeindex(self, req, res, tmpl, subdir=b""): | ||
|
r8371 | self.refresh() | ||
|
r43347 | sortable = [b"name", b"description", b"contact", b"lastchange"] | ||
|
r36909 | sortcolumn, descending = None, False | ||
|
r43347 | if b'sort' in req.qsparams: | ||
sortcolumn = req.qsparams[b'sort'] | ||||
descending = sortcolumn.startswith(b'-') | ||||
|
r5601 | if descending: | ||
sortcolumn = sortcolumn[1:] | ||||
if sortcolumn not in sortable: | ||||
|
r43347 | sortcolumn = b"" | ||
|
r4841 | |||
|
r43346 | sort = [ | ||
( | ||||
|
r43347 | b"sort_%s" % column, | ||
b"%s%s" | ||||
|
r43346 | % ( | ||
|
r43347 | (not descending and column == sortcolumn) and b"-" or b"", | ||
|
r43346 | column, | ||
), | ||||
) | ||||
for column in sortable | ||||
] | ||||
|
r5928 | |||
|
r8371 | self.refresh() | ||
|
r6221 | |||
|
r43346 | entries = indexentries( | ||
self.ui, | ||||
self.repos, | ||||
req, | ||||
self.stripecount, | ||||
sortcolumn=sortcolumn, | ||||
descending=descending, | ||||
subdir=subdir, | ||||
) | ||||
|
r6221 | |||
|
r37037 | mapping = { | ||
|
r43347 | b'entries': entries, | ||
b'subdir': subdir, | ||||
b'pathdef': hgweb_mod.makebreadcrumb(b'/' + subdir, self.prefix), | ||||
b'sortcolumn': sortcolumn, | ||||
b'descending': descending, | ||||
|
r37037 | } | ||
mapping.update(sort) | ||||
|
r43347 | res.setbodygen(tmpl.generate(b'index', mapping)) | ||
|
r36921 | return res.sendresponse() | ||
|
r5602 | |||
|
r30766 | def templater(self, req, nonce): | ||
|
r34223 | def config(section, name, default=uimod._unset, untrusted=True): | ||
|
r8191 | return self.ui.config(section, name, default, untrusted) | ||
|
r5602 | |||
|
r8216 | vars = {} | ||
|
r43346 | styles, (style, mapfile) = hgweb_mod.getstyle( | ||
req, config, self.templatepath | ||||
) | ||||
|
r9842 | if style == styles[0]: | ||
|
r43347 | vars[b'style'] = style | ||
|
r10282 | |||
|
r43347 | sessionvars = webutil.sessionvars(vars, b'?') | ||
logourl = config(b'web', b'logourl') | ||||
logoimg = config(b'web', b'logoimg') | ||||
|
r43346 | staticurl = ( | ||
|
r43347 | config(b'web', b'staticurl') | ||
or req.apppath.rstrip(b'/') + b'/static/' | ||||
|
r43346 | ) | ||
|
r43347 | if not staticurl.endswith(b'/'): | ||
staticurl += b'/' | ||||
|
r5602 | |||
|
r28954 | defaults = { | ||
|
r43347 | b"encoding": encoding.encoding, | ||
b"url": req.apppath + b'/', | ||||
b"logourl": logourl, | ||||
b"logoimg": logoimg, | ||||
b"staticurl": staticurl, | ||||
b"sessionvars": sessionvars, | ||||
b"style": style, | ||||
b"nonce": nonce, | ||||
|
r28954 | } | ||
|
r38964 | templatekeyword = registrar.templatekeyword(defaults) | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'motd', requires=()) | ||
|
r38964 | def motd(context, mapping): | ||
if self.motd is not None: | ||||
yield self.motd | ||||
else: | ||||
|
r43347 | yield config(b'web', b'motd') | ||
|
r38964 | |||
|
r28954 | tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) | ||
|
r5602 | return tmpl | ||