summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-11-05 09:22:28 -0500
committerSimo Sorce <simo@redhat.com>2014-12-05 15:53:00 -0500
commit3c0e5567c9390726f40c23dd645ddf337af63a8a (patch)
tree7e1b33678ab4ff9ea9cf7950da280ac7ada2d0dc
parent40c29b60ffbb2ba6c3f62344db9872dc15b08bbd (diff)
downloadipsilon-3c0e5567c9390726f40c23dd645ddf337af63a8a.tar.gz
ipsilon-3c0e5567c9390726f40c23dd645ddf337af63a8a.tar.xz
ipsilon-3c0e5567c9390726f40c23dd645ddf337af63a8a.zip
WIP: reread plugin configuration if too old
TODO: Need a timer/thred to periodically re-read configuration or trigger a read when something changes. Signed-off-by: Simo Sorce <simo@redhat.com>
-rwxr-xr-xipsilon/util/data.py28
-rwxr-xr-xipsilon/util/plugin.py22
2 files changed, 42 insertions, 8 deletions
diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py
index 5045ee2..ee0bdca 100755
--- a/ipsilon/util/data.py
+++ b/ipsilon/util/data.py
@@ -46,6 +46,10 @@ class SqlStore(Log):
def connection(self):
return self._dbengine.connect()
+ @property
+ def config_changed(self):
+ return True
+
def SqlAutotable(f):
def at(self, *args, **kwargs):
@@ -124,21 +128,31 @@ class FileStore(Log):
def __init__(self, name):
self._filename = name
self.is_readonly = True
- self._timestamp = None
+ self._timestamp = 0
self._config = None
- def get_config(self):
+ def _stat_conf_file(self):
try:
- stat = os.stat(self._filename)
+ return os.stat(self._filename)
except OSError, e:
self.error("Unable to check config file %s: [%s]" % (
self._filename, e))
self._config = None
raise
- timestamp = stat.st_mtime
- if self._config is None or timestamp > self._timestamp:
+
+ @property
+ def config_changed(self):
+ stat = self._stat_conf_file()
+ if stat.st_mtime != self._timestamp:
+ return True
+ return False
+
+ def get_config(self):
+ stat = self._stat_conf_file()
+ if self._config is None or stat.st_mtime != self._timestamp:
self._config = ConfigParser.RawConfigParser()
self._config.read(self._filename)
+ self._timestamp = stat.st_mtime
return self._config
@@ -252,6 +266,10 @@ class Store(Log):
def is_readonly(self):
return self._db.is_readonly
+ @property
+ def config_changed(self):
+ return self._db.config_changed
+
def _row_to_dict_tree(self, data, row):
name = row[0]
if len(row) > 2:
diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py
index ae98b4c..e9d792e 100755
--- a/ipsilon/util/plugin.py
+++ b/ipsilon/util/plugin.py
@@ -21,6 +21,7 @@ import os
import imp
import cherrypy
import inspect
+import time
from ipsilon.util.config import Config
from ipsilon.util.data import AdminStore
from ipsilon.util.log import Log
@@ -183,9 +184,10 @@ class PluginObject(Log):
return self._data.load_options(self._plugins.facility, self.name)
def refresh_plugin_config(self):
- config = self.get_plugin_config()
- if config:
- self.import_config(config)
+ if self._data.config_changed:
+ config = self.get_plugin_config()
+ if config:
+ self.import_config(config)
def save_plugin_config(self, config=None):
if config is None:
@@ -213,10 +215,15 @@ class PluginObject(Log):
self._data.wipe_data(self.name)
+# Use a 30 seconds refresh interval for now
+REFRESH_INTERVAL = 30
+
+
class PluginConfig(Log):
def __init__(self):
self._config = None
+ self.last_refresh = 0
def new_config(self, name, *config_args):
self._config = Config(name, *config_args)
@@ -224,6 +231,13 @@ class PluginConfig(Log):
def get_config_obj(self):
if self._config is None:
raise AttributeError('Config not initialized')
+
+ r = getattr(self, 'refresh_plugin_config', False)
+ if r:
+ t = time.time()
+ if self.last_refresh + REFRESH_INTERVAL < t:
+ r()
+
return self._config
def import_config(self, config):
@@ -234,6 +248,8 @@ class PluginConfig(Log):
if key in self._config:
self._config[key].import_value(str(value))
+ self.last_refresh = time.time()
+
def export_config(self):
config = dict()
for name, option in self._config.iteritems():