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