add lock support to linux filemon
This commit is contained in:
parent
5373e8c68b
commit
6794633205
2 changed files with 32 additions and 5 deletions
|
@ -62,6 +62,9 @@ class MonitorProfile(object):
|
||||||
func = edbob.load_spec(spec)
|
func = edbob.load_spec(spec)
|
||||||
self.actions.append((spec, func, args))
|
self.actions.append((spec, func, args))
|
||||||
|
|
||||||
|
self.locks = edbob.config.getboolean(
|
||||||
|
'%s.filemon' % appname, '%s.locks' % key, default=False)
|
||||||
|
|
||||||
|
|
||||||
def get_monitor_profiles(appname):
|
def get_monitor_profiles(appname):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -45,15 +45,35 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
Event processor for file monitor daemon.
|
Event processor for file monitor daemon.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def my_init(self, actions=[], **kwargs):
|
def my_init(self, actions=[], locks=False, **kwargs):
|
||||||
self.actions = actions
|
self.actions = actions
|
||||||
|
self.locks = locks
|
||||||
|
|
||||||
|
def process_IN_ACCESS(self, event):
|
||||||
|
log.debug("EventHandler: IN_ACCESS: %s" % event.pathname)
|
||||||
|
|
||||||
|
def process_IN_ATTRIB(self, event):
|
||||||
|
log.debug("EventHandler: IN_ATTRIB: %s" % event.pathname)
|
||||||
|
|
||||||
|
def process_IN_CLOSE_WRITE(self, event):
|
||||||
|
log.debug("EventHandler: IN_CLOSE_WRITE: %s" % event.pathname)
|
||||||
|
if not self.locks:
|
||||||
|
self.perform_actions(event.pathname)
|
||||||
|
|
||||||
def process_IN_CREATE(self, event):
|
def process_IN_CREATE(self, event):
|
||||||
log.debug("EventHandler: IN_CREATE: %s" % event.pathname)
|
log.debug("EventHandler: IN_CREATE: %s" % event.pathname)
|
||||||
self.perform_actions(event.pathname)
|
|
||||||
|
def process_IN_DELETE(self, event):
|
||||||
|
log.debug("EventHandler: IN_DELETE: %s" % event.pathname)
|
||||||
|
if self.locks and event.pathname.endswith('.lock'):
|
||||||
|
self.perform_actions(event.pathname[:-5])
|
||||||
|
|
||||||
|
def process_IN_MODIFY(self, event):
|
||||||
|
log.debug("EventHandler: IN_MODIFY: %s" % event.pathname)
|
||||||
|
|
||||||
def process_IN_MOVED_TO(self, event):
|
def process_IN_MOVED_TO(self, event):
|
||||||
log.debug("EventHandler: IN_MOVED_TO: %s" % event.pathname)
|
log.debug("EventHandler: IN_MOVED_TO: %s" % event.pathname)
|
||||||
|
if not self.locks:
|
||||||
self.perform_actions(event.pathname)
|
self.perform_actions(event.pathname)
|
||||||
|
|
||||||
def perform_actions(self, path):
|
def perform_actions(self, path):
|
||||||
|
@ -85,10 +105,14 @@ def start_daemon(appname, daemonize=True):
|
||||||
|
|
||||||
monitored = get_monitor_profiles(appname)
|
monitored = get_monitor_profiles(appname)
|
||||||
|
|
||||||
mask = pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO
|
mask = (pyinotify.IN_ACCESS | pyinotify.IN_ATTRIB
|
||||||
|
| pyinotify.IN_CLOSE_WRITE | pyinotify.IN_CREATE
|
||||||
|
| pyinotify.IN_DELETE | pyinotify.IN_MODIFY
|
||||||
|
| pyinotify.IN_MOVED_TO)
|
||||||
for profile in monitored.itervalues():
|
for profile in monitored.itervalues():
|
||||||
for path in profile.dirs:
|
for path in profile.dirs:
|
||||||
wm.add_watch(path, mask, proc_fun=EventHandler(actions=profile.actions))
|
wm.add_watch(path, mask, proc_fun=EventHandler(
|
||||||
|
actions=profile.actions, locks=profile.locks))
|
||||||
|
|
||||||
if not daemonize:
|
if not daemonize:
|
||||||
sys.stderr.write("Starting file monitor. (Press Ctrl+C to quit.)\n")
|
sys.stderr.write("Starting file monitor. (Press Ctrl+C to quit.)\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue