summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Generator.py
diff options
context:
space:
mode:
authorBrian Pellin <bpellin@mcs.anl.gov>2005-01-04 22:20:09 +0000
committerBrian Pellin <bpellin@mcs.anl.gov>2005-01-04 22:20:09 +0000
commit909d081411ff7b16e0e1d1affed736a38999129e (patch)
tree3cbd738963f7ffafba47446bbb5988de73571ce6 /src/lib/Server/Generator.py
parentaf272c9745307dc7c0234bcd4da3159199842269 (diff)
downloadbcfg2-909d081411ff7b16e0e1d1affed736a38999129e.tar.gz
bcfg2-909d081411ff7b16e0e1d1affed736a38999129e.tar.bz2
bcfg2-909d081411ff7b16e0e1d1affed736a38999129e.zip
Auto merged
2005/01/04 16:20:00-06:00 (none)!bpellin Added throttling for multiple events in file watching. (Logical change 1.173) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@752 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Generator.py')
-rw-r--r--src/lib/Server/Generator.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/lib/Server/Generator.py b/src/lib/Server/Generator.py
index 1d77c2b9a..485976f16 100644
--- a/src/lib/Server/Generator.py
+++ b/src/lib/Server/Generator.py
@@ -1,9 +1,11 @@
'''This is a baseclass not intended for instantiation'''
-__revision__ = '$Revision$'
+__revision__ = '$Revision: 1.34 $'
from elementtree.ElementTree import XML
from syslog import syslog, LOG_ERR, LOG_INFO
from xml.parsers.expat import ExpatError
+from os import stat
+from stat import ST_MTIME
class GeneratorError(Exception):
'''Generator runtime error used to inform upper layers of internal generator failure'''
@@ -80,15 +82,28 @@ class FileBacked(object):
object.__init__(self)
self.data = ''
self.name = name
- self.HandleEvent()
+ self.mtime = 0
+ #self.readonce = 0
+ #self.HandleEvent()
def HandleEvent(self, event=None):
'''Read file upon update'''
+ oldmtime = self.mtime
try:
- self.data = file(self.name).read()
- except IOError:
- syslog(LOG_ERR, "Failed to read file %s" % (self.name))
- self.Index()
+ self.mtime = stat(self.name)[ST_MTIME]
+ except OSError:
+ syslog(LOG_ERR, "Failed to stat file %s" % (self.name))
+
+ if self.mtime > oldmtime:
+ try:
+ # if self.readonce == 0:
+ # self.readonce = 1
+ # else:
+ # syslog(LOG_INFO, "Updated file %s" % (self.name))
+ self.data = file(self.name).read()
+ self.Index()
+ except IOError:
+ syslog(LOG_ERR, "Failed to read file %s" % (self.name))
def Index(self):
'''Update local data structures based on current file state'''