changeset 8371:1bd0fdf4c1ec

hgwebdir: refresh configuration periodically The old default behaviour of hgwebdir was to maintain a list of repositories permanently. This interacted badly with persistent application hosting software such as WSGI containers. If a new repository was published, it would potentially never appear in the top-level list of repositories. This change causes the hgwebdir configuration and list of repositories served to be refreshed periodically (at most every 20 seconds).
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 13 May 2009 13:30:28 -0700
parents 45ed015b524e
children 783c8c78db86
files mercurial/hgweb/hgwebdir_mod.py
diffstat 1 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Wed May 13 13:07:43 2009 -0500
+++ b/mercurial/hgweb/hgwebdir_mod.py	Wed May 13 13:30:28 2009 -0700
@@ -6,7 +6,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-import os
+import os, time
 from mercurial.i18n import _
 from mercurial import ui, hg, util, templater
 from mercurial import error, encoding
@@ -20,22 +20,31 @@
     return [(util.pconvert(name).strip('/'), path) for name, path in items]
 
 class hgwebdir(object):
+    refreshinterval = 20
 
     def __init__(self, conf, baseui=None):
+        self.conf = conf
+        self.baseui = baseui
+        self.lastrefresh = 0
+        self.refresh()
 
-        if baseui:
-            self.ui = baseui.copy()
+    def refresh(self):
+        if self.lastrefresh + self.refreshinterval > time.time():
+            return
+
+        if self.baseui:
+            self.ui = self.baseui.copy()
         else:
             self.ui = ui.ui()
             self.ui.setconfig('ui', 'report_untrusted', 'off')
             self.ui.setconfig('ui', 'interactive', 'off')
 
-        if isinstance(conf, (list, tuple)):
+        if isinstance(self.conf, (list, tuple)):
             self.repos = cleannames(conf)
-        elif isinstance(conf, dict):
-            self.repos = sorted(cleannames(conf.items()))
+        elif isinstance(self.conf, dict):
+            self.repos = sorted(cleannames(self.conf.items()))
         else:
-            self.ui.readconfig(conf, remap={'paths': 'hgweb-paths'}, trust=True)
+            self.ui.readconfig(self.conf, remap={'paths': 'hgweb-paths'}, trust=True)
             self.repos = []
 
         self.motd = self.ui.config('web', 'motd')
@@ -77,6 +86,7 @@
                  self.repos.append((name.lstrip(os.sep), repo))
 
         self.repos.sort()
+        self.lastrefresh = time.time()
 
     def run(self):
         if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
@@ -111,9 +121,9 @@
         return False
 
     def run_wsgi(self, req):
-
         try:
             try:
+                self.refresh()
 
                 virtual = req.env.get("PATH_INFO", "").strip('/')
                 tmpl = self.templater(req)
@@ -245,6 +255,7 @@
                     row['parity'] = parity.next()
                     yield row
 
+        self.refresh()
         sortable = ["name", "description", "contact", "lastchange"]
         sortcolumn, descending = sortdefault
         if 'sort' in req.form:
@@ -260,6 +271,7 @@
                             and "-" or "", column))
                 for column in sortable]
 
+        self.refresh()
         if self._baseurl is not None:
             req.env['SCRIPT_NAME'] = self._baseurl