plugins: Add hook for watching Thing commits.

This commit is contained in:
Neil Williams
2012-12-22 00:54:16 -08:00
parent 76594cdeb6
commit 4fda0f9f4a
2 changed files with 16 additions and 7 deletions

View File

@@ -256,20 +256,20 @@ class DataThing(object):
# (including the return in the above branch)
begin()
to_set = self._dirties.copy()
if keys:
keys = tup(keys)
to_set = dict((k, self._dirties[k][1])
for k in keys if self._dirties.has_key(k))
else:
to_set = dict((k, v[1]) for k, v in self._dirties.iteritems())
for key in to_set.keys():
if key not in keys:
del to_set[key]
data_props = {}
thing_props = {}
for k, v in to_set.iteritems():
for k, (old_value, new_value) in to_set.iteritems():
if k.startswith('_'):
thing_props[k[1:]] = v
thing_props[k[1:]] = new_value
else:
data_props[k] = v
data_props[k] = new_value
if data_props:
self._set_data(self._type_id,
@@ -297,6 +297,8 @@ class DataThing(object):
if lock:
lock.release()
g.plugins.on_thing_commit(self, to_set)
@classmethod
def _load_multi(cls, need):
need = tup(need)

View File

@@ -78,6 +78,9 @@ class Plugin(object):
def load_controllers(self):
pass
def on_thing_commit(self, thing, changes):
pass
class PluginLoader(object):
def __init__(self, plugin_names=None):
@@ -137,3 +140,7 @@ class PluginLoader(object):
def load_controllers(self):
for plugin in self:
plugin.load_controllers()
def on_thing_commit(self, thing, changes):
for plugin in self:
plugin.on_thing_commit(thing, changes)