Show More
@@ -6,7 +6,7 b'' | |||||
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
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, time | |
10 | from mercurial.i18n import _ |
|
10 | from mercurial.i18n import _ | |
11 | from mercurial import ui, hg, util, templater |
|
11 | from mercurial import ui, hg, util, templater | |
12 | from mercurial import error, encoding |
|
12 | from mercurial import error, encoding | |
@@ -20,22 +20,31 b' def cleannames(items):' | |||||
20 | return [(util.pconvert(name).strip('/'), path) for name, path in items] |
|
20 | return [(util.pconvert(name).strip('/'), path) for name, path in items] | |
21 |
|
21 | |||
22 | class hgwebdir(object): |
|
22 | class hgwebdir(object): | |
|
23 | refreshinterval = 20 | |||
23 |
|
24 | |||
24 | def __init__(self, conf, baseui=None): |
|
25 | def __init__(self, conf, baseui=None): | |
|
26 | self.conf = conf | |||
|
27 | self.baseui = baseui | |||
|
28 | self.lastrefresh = 0 | |||
|
29 | self.refresh() | |||
25 |
|
30 | |||
26 | if baseui: |
|
31 | def refresh(self): | |
27 | self.ui = baseui.copy() |
|
32 | if self.lastrefresh + self.refreshinterval > time.time(): | |
|
33 | return | |||
|
34 | ||||
|
35 | if self.baseui: | |||
|
36 | self.ui = self.baseui.copy() | |||
28 | else: |
|
37 | else: | |
29 | self.ui = ui.ui() |
|
38 | self.ui = ui.ui() | |
30 | self.ui.setconfig('ui', 'report_untrusted', 'off') |
|
39 | self.ui.setconfig('ui', 'report_untrusted', 'off') | |
31 | self.ui.setconfig('ui', 'interactive', 'off') |
|
40 | self.ui.setconfig('ui', 'interactive', 'off') | |
32 |
|
41 | |||
33 | if isinstance(conf, (list, tuple)): |
|
42 | if isinstance(self.conf, (list, tuple)): | |
34 | self.repos = cleannames(conf) |
|
43 | self.repos = cleannames(conf) | |
35 | elif isinstance(conf, dict): |
|
44 | elif isinstance(self.conf, dict): | |
36 | self.repos = sorted(cleannames(conf.items())) |
|
45 | self.repos = sorted(cleannames(self.conf.items())) | |
37 | else: |
|
46 | else: | |
38 | self.ui.readconfig(conf, remap={'paths': 'hgweb-paths'}, trust=True) |
|
47 | self.ui.readconfig(self.conf, remap={'paths': 'hgweb-paths'}, trust=True) | |
39 | self.repos = [] |
|
48 | self.repos = [] | |
40 |
|
49 | |||
41 | self.motd = self.ui.config('web', 'motd') |
|
50 | self.motd = self.ui.config('web', 'motd') | |
@@ -77,6 +86,7 b' class hgwebdir(object):' | |||||
77 | self.repos.append((name.lstrip(os.sep), repo)) |
|
86 | self.repos.append((name.lstrip(os.sep), repo)) | |
78 |
|
87 | |||
79 | self.repos.sort() |
|
88 | self.repos.sort() | |
|
89 | self.lastrefresh = time.time() | |||
80 |
|
90 | |||
81 | def run(self): |
|
91 | def run(self): | |
82 | if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
|
92 | if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): | |
@@ -111,9 +121,9 b' class hgwebdir(object):' | |||||
111 | return False |
|
121 | return False | |
112 |
|
122 | |||
113 | def run_wsgi(self, req): |
|
123 | def run_wsgi(self, req): | |
114 |
|
||||
115 | try: |
|
124 | try: | |
116 | try: |
|
125 | try: | |
|
126 | self.refresh() | |||
117 |
|
127 | |||
118 | virtual = req.env.get("PATH_INFO", "").strip('/') |
|
128 | virtual = req.env.get("PATH_INFO", "").strip('/') | |
119 | tmpl = self.templater(req) |
|
129 | tmpl = self.templater(req) | |
@@ -245,6 +255,7 b' class hgwebdir(object):' | |||||
245 | row['parity'] = parity.next() |
|
255 | row['parity'] = parity.next() | |
246 | yield row |
|
256 | yield row | |
247 |
|
257 | |||
|
258 | self.refresh() | |||
248 | sortable = ["name", "description", "contact", "lastchange"] |
|
259 | sortable = ["name", "description", "contact", "lastchange"] | |
249 | sortcolumn, descending = sortdefault |
|
260 | sortcolumn, descending = sortdefault | |
250 | if 'sort' in req.form: |
|
261 | if 'sort' in req.form: | |
@@ -260,6 +271,7 b' class hgwebdir(object):' | |||||
260 | and "-" or "", column)) |
|
271 | and "-" or "", column)) | |
261 | for column in sortable] |
|
272 | for column in sortable] | |
262 |
|
273 | |||
|
274 | self.refresh() | |||
263 | if self._baseurl is not None: |
|
275 | if self._baseurl is not None: | |
264 | req.env['SCRIPT_NAME'] = self._baseurl |
|
276 | req.env['SCRIPT_NAME'] = self._baseurl | |
265 |
|
277 |
General Comments 0
You need to be logged in to leave comments.
Login now