Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgwebdir_mod.py @ 8345:dcebff8a25dd
hgwebdir: read --webdir-conf as actual configuration to ui (issue1586)
This cleans up code and allows specification of values more globally. For
example, it's now possible to specify web.contact in webdir-conf for all
repositories without a specified contact set.
author | Alexander Solovyov <piranha@piranha.org.ua> |
---|---|
date | Mon, 11 May 2009 14:20:18 +0200 |
parents | 46293a0c7e9f |
children | b579823cc546 |
comparison
equal
deleted
inserted
replaced
8344:873429914ec5 | 8345:dcebff8a25dd |
---|---|
7 # GNU General Public License version 2, incorporated herein by reference. | 7 # GNU General Public License version 2, incorporated herein by reference. |
8 | 8 |
9 import os | 9 import os |
10 from mercurial.i18n import _ | 10 from mercurial.i18n import _ |
11 from mercurial import ui, hg, util, templater, templatefilters | 11 from mercurial import ui, hg, util, templater, templatefilters |
12 from mercurial import config, 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 |
15 from hgweb_mod import hgweb | 15 from hgweb_mod import hgweb |
16 from request import wsgirequest | 16 from request import wsgirequest |
17 import webutil | 17 import webutil |
28 else: | 28 else: |
29 self.ui = ui.ui() | 29 self.ui = ui.ui() |
30 self.ui.setconfig('ui', 'report_untrusted', 'off') | 30 self.ui.setconfig('ui', 'report_untrusted', 'off') |
31 self.ui.setconfig('ui', 'interactive', 'off') | 31 self.ui.setconfig('ui', 'interactive', 'off') |
32 | 32 |
33 self.motd = None | |
34 self.style = 'paper' | |
35 self.stripecount = 1 | |
36 self.repos_sorted = ('name', False) | 33 self.repos_sorted = ('name', False) |
37 self._baseurl = None | |
38 | 34 |
39 if isinstance(conf, (list, tuple)): | 35 if isinstance(conf, (list, tuple)): |
40 self.repos = cleannames(conf) | 36 self.repos = cleannames(conf) |
41 self.repos_sorted = ('', False) | 37 self.repos_sorted = ('', False) |
42 elif isinstance(conf, dict): | 38 elif isinstance(conf, dict): |
43 self.repos = sorted(cleannames(conf.items())) | 39 self.repos = sorted(cleannames(conf.items())) |
44 else: | 40 else: |
45 if isinstance(conf, config.config): | 41 self.ui.readconfig(conf, remap={'paths': 'hgweb-paths'}) |
46 cp = conf | |
47 else: | |
48 cp = config.config() | |
49 cp.read(conf) | |
50 self.repos = [] | 42 self.repos = [] |
51 self.motd = cp.get('web', 'motd') | 43 |
52 self.style = cp.get('web', 'style', 'paper') | 44 self.motd = self.ui.config('web', 'motd') |
53 self.stripecount = cp.get('web', 'stripes', 1) | 45 self.style = self.ui.config('web', 'style', 'paper') |
54 self._baseurl = cp.get('web', 'baseurl') | 46 self.stripecount = self.ui.config('web', 'stripes', 1) |
55 if 'paths' in cp: | 47 if self.stripecount: |
56 paths = cleannames(cp.items('paths')) | 48 self.stripecount = int(self.stripecount) |
57 for prefix, root in paths: | 49 self._baseurl = self.ui.config('web', 'baseurl') |
58 roothead, roottail = os.path.split(root) | 50 |
59 # "foo = /bar/*" makes every subrepo of /bar/ to be | 51 if self.repos: |
60 # mounted as foo/subrepo | 52 return |
61 # and "foo = /bar/**" does even recurse inside the | 53 |
62 # subdirectories, remember to use it without working dir. | 54 for prefix, root in cleannames(self.ui.configitems('hgweb-paths')): |
63 try: | 55 roothead, roottail = os.path.split(root) |
64 recurse = {'*': False, '**': True}[roottail] | 56 # "foo = /bar/*" makes every subrepo of /bar/ to be |
65 except KeyError: | 57 # mounted as foo/subrepo |
66 self.repos.append((prefix, root)) | 58 # and "foo = /bar/**" also recurses into the subdirectories, |
67 continue | 59 # remember to use it without working dir. |
68 roothead = os.path.normpath(roothead) | 60 try: |
69 for path in util.walkrepos(roothead, followsym=True, | 61 recurse = {'*': False, '**': True}[roottail] |
70 recurse=recurse): | 62 except KeyError: |
71 path = os.path.normpath(path) | 63 self.repos.append((prefix, root)) |
72 name = util.pconvert(path[len(roothead):]).strip('/') | 64 continue |
73 if prefix: | 65 roothead = os.path.normpath(roothead) |
74 name = prefix + '/' + name | 66 for path in util.walkrepos(roothead, followsym=True, |
75 self.repos.append((name, path)) | 67 recurse=recurse): |
76 for prefix, root in cp.items('collections'): | 68 path = os.path.normpath(path) |
77 for path in util.walkrepos(root, followsym=True): | 69 name = util.pconvert(path[len(roothead):]).strip('/') |
78 repo = os.path.normpath(path) | 70 if prefix: |
79 name = repo | 71 name = prefix + '/' + name |
80 if name.startswith(prefix): | 72 self.repos.append((name, path)) |
81 name = name[len(prefix):] | 73 |
82 self.repos.append((name.lstrip(os.sep), repo)) | 74 for prefix, root in self.ui.configitems('collections'): |
83 self.repos.sort() | 75 for path in util.walkrepos(root, followsym=True): |
76 repo = os.path.normpath(path) | |
77 name = repo | |
78 if name.startswith(prefix): | |
79 name = name[len(prefix):] | |
80 self.repos.append((name.lstrip(os.sep), repo)) | |
81 | |
82 self.repos.sort() | |
84 | 83 |
85 def run(self): | 84 def run(self): |
86 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): | 85 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
87 raise RuntimeError("This function is only intended to be called while running as a CGI script.") | 86 raise RuntimeError("This function is only intended to be called while running as a CGI script.") |
88 import mercurial.hgweb.wsgicgi as wsgicgi | 87 import mercurial.hgweb.wsgicgi as wsgicgi |