13 from common import get_mtime, staticfile, style_map |
13 from common import get_mtime, staticfile, style_map |
14 from hgweb_mod import hgweb |
14 from hgweb_mod import hgweb |
15 |
15 |
16 # This is a stopgap |
16 # This is a stopgap |
17 class hgwebdir(object): |
17 class hgwebdir(object): |
18 def __init__(self, config): |
18 def __init__(self, config, parentui=None): |
19 def cleannames(items): |
19 def cleannames(items): |
20 return [(name.strip(os.sep), path) for name, path in items] |
20 return [(name.strip(os.sep), path) for name, path in items] |
21 |
21 |
22 self.motd = "" |
22 self.parentui = parentui |
23 self.style = "" |
23 self.motd = None |
|
24 self.style = None |
24 self.repos_sorted = ('name', False) |
25 self.repos_sorted = ('name', False) |
25 if isinstance(config, (list, tuple)): |
26 if isinstance(config, (list, tuple)): |
26 self.repos = cleannames(config) |
27 self.repos = cleannames(config) |
27 self.repos_sorted = ('', False) |
28 self.repos_sorted = ('', False) |
28 elif isinstance(config, dict): |
29 elif isinstance(config, dict): |
71 |
72 |
72 def footer(**map): |
73 def footer(**map): |
73 yield tmpl("footer", **map) |
74 yield tmpl("footer", **map) |
74 |
75 |
75 def motd(**map): |
76 def motd(**map): |
76 yield self.motd |
77 if self.motd is not None: |
|
78 yield self.motd |
|
79 else: |
|
80 yield config('web', 'motd', '') |
|
81 |
|
82 parentui = self.parentui or ui.ui(report_untrusted=False) |
|
83 |
|
84 def config(section, name, default=None, untrusted=True): |
|
85 return parentui.config(section, name, default, untrusted) |
77 |
86 |
78 url = req.env['REQUEST_URI'].split('?')[0] |
87 url = req.env['REQUEST_URI'].split('?')[0] |
79 if not url.endswith('/'): |
88 if not url.endswith('/'): |
80 url += '/' |
89 url += '/' |
81 |
90 |
82 style = self.style |
91 style = self.style |
|
92 if style is None: |
|
93 style = config('web', 'style', '') |
83 if req.form.has_key('style'): |
94 if req.form.has_key('style'): |
84 style = req.form['style'][0] |
95 style = req.form['style'][0] |
85 mapfile = style_map(templater.templatepath(), style) |
96 mapfile = style_map(templater.templatepath(), style) |
86 tmpl = templater.templater(mapfile, templater.common_filters, |
97 tmpl = templater.templater(mapfile, templater.common_filters, |
87 defaults={"header": header, |
98 defaults={"header": header, |
111 separator = ';' |
122 separator = ';' |
112 |
123 |
113 rows = [] |
124 rows = [] |
114 parity = 0 |
125 parity = 0 |
115 for name, path in self.repos: |
126 for name, path in self.repos: |
116 u = ui.ui(report_untrusted=False) |
127 u = ui.ui(parentui=parentui) |
117 try: |
128 try: |
118 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
129 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
119 except IOError: |
130 except IOError: |
120 pass |
131 pass |
121 def get(section, name, default=None): |
132 def get(section, name, default=None): |
179 break |
190 break |
180 virtual = virtual[:up] |
191 virtual = virtual[:up] |
181 if real: |
192 if real: |
182 req.env['REPO_NAME'] = virtual |
193 req.env['REPO_NAME'] = virtual |
183 try: |
194 try: |
184 hgweb(real).run_wsgi(req) |
195 repo = hg.repository(parentui, real) |
|
196 hgweb(repo).run_wsgi(req) |
185 except IOError, inst: |
197 except IOError, inst: |
186 req.write(tmpl("error", error=inst.strerror)) |
198 req.write(tmpl("error", error=inst.strerror)) |
187 except hg.RepoError, inst: |
199 except hg.RepoError, inst: |
188 req.write(tmpl("error", error=str(inst))) |
200 req.write(tmpl("error", error=str(inst))) |
189 else: |
201 else: |