[llvm-commits] [zorg] r150448 - /zorg/trunk/zorg/buildbot/util/ConfigEmailLookup.py

Galina Kistanova gkistanova at gmail.com
Mon Feb 13 16:46:15 PST 2012


Author: gkistanova
Date: Mon Feb 13 18:46:15 2012
New Revision: 150448

URL: http://llvm.org/viewvc/llvm-project?rev=150448&view=rev
Log:
Changes to support reloading list of authors if the file with list updated.

Modified:
    zorg/trunk/zorg/buildbot/util/ConfigEmailLookup.py

Modified: zorg/trunk/zorg/buildbot/util/ConfigEmailLookup.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/util/ConfigEmailLookup.py?rev=150448&r1=150447&r2=150448&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/util/ConfigEmailLookup.py (original)
+++ zorg/trunk/zorg/buildbot/util/ConfigEmailLookup.py Mon Feb 13 18:46:15 2012
@@ -1,5 +1,9 @@
 import buildbot
 import zope
+import os
+
+from datetime import datetime, timedelta
+from twisted.python import log
 
 class ConfigEmailLookup(buildbot.util.ComparableMixin):
   """
@@ -7,21 +11,26 @@
   file to match commit authors to email addresses.
   """
 
-  # FIXME: This should be able to reload the config file when it
-  # changes.
+  # TODO: Document this class.
+  # Class loads llvm_authors from file and reload if the file was updated.
 
   zope.interface.implements(buildbot.interfaces.IEmailLookup)
   compare_attrs = ["author_filename", "default_address", "only_addresses"]
 
-  def __init__(self, author_filename, default_address, only_addresses = None):
+  def __init__(self, author_filename, default_address, only_addresses = None, update_interval=timedelta(hours=1)):
     from ConfigParser import ConfigParser
 
     self.author_filename = author_filename
     self.default_address = default_address
     self.only_addresses = only_addresses
+    self.update_interval = update_interval
 
     self.config_parser = ConfigParser()
-    self.config_parser.read(author_filename)
+    self.config_parser.read(self.author_filename)
+
+    self.time_checked = datetime.utcnow()
+    self.time_loaded  = datetime.utcfromtimestamp(os.path.getmtime(self.author_filename))
+    log.msg('Loaded file %s (mtime=%s) at %s' % (self.author_filename, self.time_loaded, self.time_checked))
 
     if only_addresses:
       import re
@@ -30,6 +39,24 @@
       self.address_match_p = lambda addr: True
 
   def getAddress(self, name):
+
+    try:
+
+      if (datetime.utcnow() - self.time_checked) >= timedelta(minutes=1):
+        self.time_checked = datetime.utcnow()
+        current_mtime = datetime.utcfromtimestamp(os.path.getmtime(self.author_filename))
+        log.msg('Checked file %s (mtime=%s) at %s' % (self.author_filename, current_mtime, self.time_checked))
+
+        if (current_mtime != self.time_loaded) and ((datetime.utcnow() - current_mtime) >= timedelta(minutes=1)):
+          # Reload the list of authors.
+          self.config_parser.read(self.author_filename)
+          self.time_loaded = current_mtime
+          log.msg('Reloaded file %s (mtime=%s) at %s' % (self.author_filename, self.time_loaded, self.time_checked))
+
+    except:
+      log.msg('Cannot load the %s file.' % self.author_filename)
+      pass
+
     try:
       email = self.config_parser.get("authors", name)
     except:





More information about the llvm-commits mailing list