mercurial/hgweb/hgwebdir_mod.py
author Matt Mackall <mpm@selenic.com>
Thu, 31 Jan 2008 14:44:19 -0600
changeset 5976 9f1e6ab76069
parent 5970 f25070ecf334
child 5993 948a41e77902
permissions -rw-r--r--
templates: move filters to their own module This eliminates just about all Mercurial dependencies in templater.py
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2391
d351a3be3371 Fixing up comment headers for split up code.
Eric Hopper <hopper@omnifarious.org>
parents: 2360
diff changeset
     1
# hgweb/hgwebdir_mod.py - Web interface for a directory of repositories.
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     2
#
238
3b92f8fe47ae hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents: 222
diff changeset
     3
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2538
diff changeset
     4
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
131
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     5
#
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
c9d51742471c moving hgweb to mercurial subdir
jake@edge2.net
parents:
diff changeset
     8
5928
3340aa5a64f7 hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5915
diff changeset
     9
import os
2311
b832b6eb65ab Moving hgweb.py into it's own module in preparation for breaking it up.
Eric Hopper <hopper@omnifarious.org>
parents: 2275
diff changeset
    10
from mercurial.i18n import gettext as _
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5970
diff changeset
    11
from mercurial import ui, hg, util, templater, templatefilters
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5970
diff changeset
    12
from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen,\
5779
e9f68860d5ed Don't let ui.username override web.contact (issue900)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5760
diff changeset
    13
                   get_contact
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3557
diff changeset
    14
from hgweb_mod import hgweb
5566
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    15
from request import wsgirequest
138
c77a679e9cfa Revamped templated hgweb
mpm@selenic.com
parents: 137
diff changeset
    16
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
    17
# This is a stopgap
1559
59b3639df0a9 Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents: 1554
diff changeset
    18
class hgwebdir(object):
4079
40c9710e8182 Pass a ui from create_server to hgwebdir and a repo from hgwebdir to hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3882
diff changeset
    19
    def __init__(self, config, parentui=None):
1181
4f5001f5b4c3 Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1180
diff changeset
    20
        def cleannames(items):
5584
d2831a5d5947 hgwebdir: normalize virtual paths before stripping the separator
Patrick Mezard <pmezard@gmail.com>
parents: 5336
diff changeset
    21
            return [(util.pconvert(name).strip('/'), path)
5063
142a07e758c8 hgwebdir: change os.sep in the name of repos to "/"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4709
diff changeset
    22
                    for name, path in items]
1181
4f5001f5b4c3 Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1180
diff changeset
    23
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    24
        self.parentui = parentui or ui.ui(report_untrusted=False,
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    25
                                          interactive = False)
4080
ef14fdb675da hgwebdir: try to get web.style and web.motd from the ui.config system
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4079
diff changeset
    26
        self.motd = None
ef14fdb675da hgwebdir: try to get web.style and web.motd from the ui.config system
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4079
diff changeset
    27
        self.style = None
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4250
diff changeset
    28
        self.stripecount = None
2174
3044a3fdae76 If default sorting is name, offer name-descending with one click.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2173
diff changeset
    29
        self.repos_sorted = ('name', False)
1829
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    30
        if isinstance(config, (list, tuple)):
1181
4f5001f5b4c3 Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1180
diff changeset
    31
            self.repos = cleannames(config)
2174
3044a3fdae76 If default sorting is name, offer name-descending with one click.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2173
diff changeset
    32
            self.repos_sorted = ('', False)
1829
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    33
        elif isinstance(config, dict):
1181
4f5001f5b4c3 Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents: 1180
diff changeset
    34
            self.repos = cleannames(config.items())
1143
4fffb3d84b7c Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1142
diff changeset
    35
            self.repos.sort()
4fffb3d84b7c Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1142
diff changeset
    36
        else:
4051
022056263354 hgwebdir: class hgwebdir should also accept a configparser instance
Michael Gebetsroither <michael.geb@gmx.at>
parents: 3887
diff changeset
    37
            if isinstance(config, util.configparser):
022056263354 hgwebdir: class hgwebdir should also accept a configparser instance
Michael Gebetsroither <michael.geb@gmx.at>
parents: 3887
diff changeset
    38
                cp = config
022056263354 hgwebdir: class hgwebdir should also accept a configparser instance
Michael Gebetsroither <michael.geb@gmx.at>
parents: 3887
diff changeset
    39
            else:
022056263354 hgwebdir: class hgwebdir should also accept a configparser instance
Michael Gebetsroither <michael.geb@gmx.at>
parents: 3887
diff changeset
    40
                cp = util.configparser()
022056263354 hgwebdir: class hgwebdir should also accept a configparser instance
Michael Gebetsroither <michael.geb@gmx.at>
parents: 3887
diff changeset
    41
                cp.read(config)
1829
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    42
            self.repos = []
3221
d7d53e3d9590 Add style support to hgwebdir
Edouard Gomez <ed.gomez@free.fr>
parents: 2859
diff changeset
    43
            if cp.has_section('web'):
d7d53e3d9590 Add style support to hgwebdir
Edouard Gomez <ed.gomez@free.fr>
parents: 2859
diff changeset
    44
                if cp.has_option('web', 'motd'):
d7d53e3d9590 Add style support to hgwebdir
Edouard Gomez <ed.gomez@free.fr>
parents: 2859
diff changeset
    45
                    self.motd = cp.get('web', 'motd')
d7d53e3d9590 Add style support to hgwebdir
Edouard Gomez <ed.gomez@free.fr>
parents: 2859
diff changeset
    46
                if cp.has_option('web', 'style'):
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3221
diff changeset
    47
                    self.style = cp.get('web', 'style')
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4250
diff changeset
    48
                if cp.has_option('web', 'stripes'):
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4250
diff changeset
    49
                    self.stripecount = int(cp.get('web', 'stripes'))
1829
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    50
            if cp.has_section('paths'):
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    51
                self.repos.extend(cleannames(cp.items('paths')))
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    52
            if cp.has_section('collections'):
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    53
                for prefix, root in cp.items('collections'):
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    54
                    for path in util.walkrepos(root):
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    55
                        repo = os.path.normpath(path)
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    56
                        name = repo
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    57
                        if name.startswith(prefix):
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    58
                            name = name[len(prefix):]
b0f6af327fd4 hgwebdir: export collections of repos
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1703
diff changeset
    59
                        self.repos.append((name.lstrip(os.sep), repo))
1143
4fffb3d84b7c Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1142
diff changeset
    60
            self.repos.sort()
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
    61
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
    62
    def run(self):
2538
f4b7d71c1c60 Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents: 2537
diff changeset
    63
        if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
    64
            raise RuntimeError("This function is only intended to be called while running as a CGI script.")
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
    65
        import mercurial.hgweb.wsgicgi as wsgicgi
5566
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    66
        wsgicgi.launch(self)
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    67
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    68
    def __call__(self, env, respond):
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    69
        req = wsgirequest(env, respond)
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    70
        self.run_wsgi(req)
d74fc8dec2b4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5561
diff changeset
    71
        return req
2535
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
    72
b8ccf6386db7 Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents: 2514
diff changeset
    73
    def run_wsgi(self, req):
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
    74
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    75
        try:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    76
            try:
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    77
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    78
                virtual = req.env.get("PATH_INFO", "").strip('/')
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5603
diff changeset
    79
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    80
                # a static file
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    81
                if virtual.startswith('static/') or 'static' in req.form:
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    82
                    static = os.path.join(templater.templatepath(), 'static')
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    83
                    if virtual.startswith('static/'):
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    84
                        fname = virtual[7:]
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    85
                    else:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    86
                        fname = req.form['static'][0]
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    87
                    req.write(staticfile(static, fname, req))
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    88
                    return
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    89
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    90
                # top-level index
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    91
                elif not virtual:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    92
                    tmpl = self.templater(req)
5965
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
    93
                    req.write(self.makeindex(req, tmpl))
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    94
                    return
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
    95
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    96
                # nested indexes and hgwebs
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    97
                repos = dict(self.repos)
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    98
                while virtual:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
    99
                    real = repos.get(virtual)
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   100
                    if real:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   101
                        req.env['REPO_NAME'] = virtual
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   102
                        try:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   103
                            repo = hg.repository(self.parentui, real)
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   104
                            hgweb(repo).run_wsgi(req)
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   105
                            return
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   106
                        except IOError, inst:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   107
                            raise ErrorResponse(500, inst.strerror)
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   108
                        except hg.RepoError, inst:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   109
                            raise ErrorResponse(500, str(inst))
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   110
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   111
                    # browse subdirectories
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   112
                    subdir = virtual + '/'
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   113
                    if [r for r in repos if r.startswith(subdir)]:
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   114
                        tmpl = self.templater(req)
5965
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   115
                        req.write(self.makeindex(req, tmpl, subdir))
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   116
                        return
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   117
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   118
                    up = virtual.rfind('/')
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   119
                    if up < 0:
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   120
                        break
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   121
                    virtual = virtual[:up]
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   122
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   123
                # prefixes not found
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   124
                tmpl = self.templater(req)
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   125
                req.respond(404, tmpl("notfound", repo=virtual))
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5603
diff changeset
   126
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   127
            except ErrorResponse, err:
5603
74f65f44a9aa hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5602
diff changeset
   128
                tmpl = self.templater(req)
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   129
                req.respond(err.code, tmpl('error', error=err.message or ''))
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   130
        finally:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   131
            tmpl = None
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   132
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   133
    def makeindex(self, req, tmpl, subdir=""):
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   134
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
   135
        def archivelist(ui, nodeid, url):
3556
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   136
            allowed = ui.configlist("web", "allow_archive", untrusted=True)
3262
1e322b44b366 Teach hgwebdir about new interface
Brendan Cully <brendan@kublai.com>
parents: 3223
diff changeset
   137
            for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
3556
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   138
                if i[0] in allowed or ui.configbool("web", "allow" + i[0],
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   139
                                                    untrusted=True):
3262
1e322b44b366 Teach hgwebdir about new interface
Brendan Cully <brendan@kublai.com>
parents: 3223
diff changeset
   140
                    yield {"type" : i[0], "extension": i[1],
1e322b44b366 Teach hgwebdir about new interface
Brendan Cully <brendan@kublai.com>
parents: 3223
diff changeset
   141
                           "node": nodeid, "url": url}
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
   142
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   143
        def entries(sortcolumn="", descending=False, subdir="", **map):
3365
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   144
            def sessionvars(**map):
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   145
                fields = []
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5779
diff changeset
   146
                if 'style' in req.form:
3365
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   147
                    style = req.form['style'][0]
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   148
                    if style != get('web', 'style', ''):
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   149
                        fields.append(('style', style))
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   150
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   151
                separator = url[-1] == '?' and ';' or '?'
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   152
                for name, value in fields:
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   153
                    yield dict(name=name, value=value, separator=separator)
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   154
                    separator = ';'
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   155
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   156
            rows = []
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4250
diff changeset
   157
            parity = paritygen(self.stripecount)
1141
033c968d7c66 Use ConfigParser only in hgwebdir.__init__()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1140
diff changeset
   158
            for name, path in self.repos:
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   159
                if not name.startswith(subdir):
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   160
                    continue
4843
496ac05c6a31 hgwebdir: show only trailing part of path when browsing subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4841
diff changeset
   161
                name = name[len(subdir):]
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   162
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   163
                u = ui.ui(parentui=self.parentui)
1170
85555540a4e2 Make .hg/hgrc optional for repositories published by hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1165
diff changeset
   164
                try:
1473
7d66ce9895fa make readconfig take a filename instead of a file pointer as argument
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1445
diff changeset
   165
                    u.readconfig(os.path.join(path, '.hg', 'hgrc'))
5332
b0bfe087ad8a hgwebdir: ignore hgrc parse errors while building the index page
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5289
diff changeset
   166
                except Exception, e:
b0bfe087ad8a hgwebdir: ignore hgrc parse errors while building the index page
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5289
diff changeset
   167
                    u.warn(_('error reading %s/.hg/hgrc: %s\n' % (path, e)))
b0bfe087ad8a hgwebdir: ignore hgrc parse errors while building the index page
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5289
diff changeset
   168
                    continue
3556
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   169
                def get(section, name, default=None):
c3043ebe40a0 use untrusted settings in hgwebdir
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3488
diff changeset
   170
                    return u.config(section, name, default, untrusted=True)
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
   171
4709
53eca35c3aeb Add option "hidden" to hgwebdir.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
parents: 4462
diff changeset
   172
                if u.configbool("web", "hidden", untrusted=True):
53eca35c3aeb Add option "hidden" to hgwebdir.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
parents: 4462
diff changeset
   173
                    continue
53eca35c3aeb Add option "hidden" to hgwebdir.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
parents: 4462
diff changeset
   174
5970
f25070ecf334 hgweb: fixes to make hg serve prefix handling more robust
Michele Cella <michele.cella@gmail.com>
parents: 5965
diff changeset
   175
                parts = [req.env['PATH_INFO'].strip('/'), name]
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5566
diff changeset
   176
                if req.env['SCRIPT_NAME']:
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5603
diff changeset
   177
                    parts.insert(0, req.env['SCRIPT_NAME'])
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5566
diff changeset
   178
                url = ('/'.join(parts).replace("//", "/")) + '/'
1022
31dcaf9123ba Minor hgwebdir tweaks
mpm@selenic.com
parents: 987
diff changeset
   179
1348
b8c82bf3da21 hgwebdir: Fix date display
mpm@selenic.com
parents: 1333
diff changeset
   180
                # update time with local timezone
1524
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   181
                try:
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   182
                    d = (get_mtime(path), util.makedate()[1])
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   183
                except OSError:
0d47bb884330 hgweb: fix traceback by skipping invalid repo paths
TK Soh <teekaysoh@yahoo.com>
parents: 1511
diff changeset
   184
                    continue
1348
b8c82bf3da21 hgwebdir: Fix date display
mpm@selenic.com
parents: 1333
diff changeset
   185
5779
e9f68860d5ed Don't let ui.username override web.contact (issue900)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5760
diff changeset
   186
                contact = get_contact(get)
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   187
                description = get("web", "description", "")
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   188
                name = get("web", "name", name)
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   189
                row = dict(contact=contact or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   190
                           contact_sort=contact.upper() or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   191
                           name=name,
2174
3044a3fdae76 If default sorting is name, offer name-descending with one click.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2173
diff changeset
   192
                           name_sort=name,
1062
6d5a62a549fa pep-0008 cleanup
benoit.boissinot@ens-lyon.fr
parents: 1023
diff changeset
   193
                           url=url,
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   194
                           description=description or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   195
                           description_sort=description.upper() or "unknown",
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   196
                           lastchange=d,
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   197
                           lastchange_sort=d[1]-d[0],
3365
cf680c9ab1dd Keep session variables when linking from hgwebdir's index to repositories.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3328
diff changeset
   198
                           sessionvars=sessionvars,
2171
290534ee163c Add download links to hgwebdir index page for allowed archive types.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2170
diff changeset
   199
                           archives=archivelist(u, "tip", url))
2174
3044a3fdae76 If default sorting is name, offer name-descending with one click.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2173
diff changeset
   200
                if (not sortcolumn
3044a3fdae76 If default sorting is name, offer name-descending with one click.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2173
diff changeset
   201
                    or (sortcolumn, descending) == self.repos_sorted):
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   202
                    # fast path for unsorted output
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4250
diff changeset
   203
                    row['parity'] = parity.next()
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   204
                    yield row
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   205
                else:
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   206
                    rows.append((row["%s_sort" % sortcolumn], row))
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   207
            if rows:
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   208
                rows.sort()
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   209
                if descending:
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   210
                    rows.reverse()
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   211
                for key, row in rows:
4462
12e4d9524951 hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4250
diff changeset
   212
                    row['parity'] = parity.next()
2173
d1943df604c4 Make hgwebdir columns sortable.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2171
diff changeset
   213
                    yield row
941
4cf418c2a013 Add a multi-repository server
mpm@selenic.com
parents: 939
diff changeset
   214
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   215
        sortable = ["name", "description", "contact", "lastchange"]
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   216
        sortcolumn, descending = self.repos_sorted
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5779
diff changeset
   217
        if 'sort' in req.form:
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   218
            sortcolumn = req.form['sort'][0]
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   219
            descending = sortcolumn.startswith('-')
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   220
            if descending:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   221
                sortcolumn = sortcolumn[1:]
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   222
            if sortcolumn not in sortable:
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   223
                sortcolumn = ""
4841
9b0ebb5e0f94 hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents: 4709
diff changeset
   224
5601
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   225
        sort = [("sort_%s" % column,
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   226
                 "%s%s" % ((not descending and column == sortcolumn)
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   227
                            and "-" or "", column))
8279cb841467 hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5585
diff changeset
   228
                for column in sortable]
5928
3340aa5a64f7 hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5915
diff changeset
   229
5965
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   230
        return tmpl("index", entries=entries, subdir=subdir,
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   231
                    sortcolumn=sortcolumn, descending=descending,
abe373e16fe6 hgweb: forgot to centralize the req.write() calls in hgwebdir
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5928
diff changeset
   232
                    **dict(sort))
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   233
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   234
    def templater(self, req):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   235
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   236
        def header(**map):
5928
3340aa5a64f7 hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5915
diff changeset
   237
            ctype = tmpl('mimetype', encoding=util._encoding)
3340aa5a64f7 hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5915
diff changeset
   238
            req.httphdr(templater.stringify(ctype))
3340aa5a64f7 hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5915
diff changeset
   239
            yield tmpl('header', encoding=util._encoding, **map)
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   240
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   241
        def footer(**map):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   242
            yield tmpl("footer", **map)
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   243
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   244
        def motd(**map):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   245
            if self.motd is not None:
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   246
                yield self.motd
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   247
            else:
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   248
                yield config('web', 'motd', '')
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   249
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   250
        def config(section, name, default=None, untrusted=True):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   251
            return self.parentui.config(section, name, default, untrusted)
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   252
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   253
        url = req.env.get('SCRIPT_NAME', '')
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   254
        if not url.endswith('/'):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   255
            url += '/'
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   256
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   257
        staticurl = config('web', 'staticurl') or url + 'static/'
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   258
        if not staticurl.endswith('/'):
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   259
            staticurl += '/'
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   260
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   261
        style = self.style
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   262
        if style is None:
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   263
            style = config('web', 'style', '')
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5779
diff changeset
   264
        if 'style' in req.form:
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   265
            style = req.form['style'][0]
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   266
        if self.stripecount is None:
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   267
            self.stripecount = int(config('web', 'stripes', 1))
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   268
        mapfile = style_map(templater.templatepath(), style)
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5970
diff changeset
   269
        tmpl = templater.templater(mapfile, templatefilters.filters,
5602
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   270
                                   defaults={"header": header,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   271
                                             "footer": footer,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   272
                                             "motd": motd,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   273
                                             "url": url,
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   274
                                             "staticurl": staticurl})
d676d0f35bd8 hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5601
diff changeset
   275
        return tmpl