Skip to content

Commit

Permalink
[BUG] Fixed inotify events.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Delle Cave committed Jul 6, 2018
1 parent 7d01b1d commit be06bdb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
25 changes: 23 additions & 2 deletions dwho/classes/inoplugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import abc
import logging
import os

from dwho.classes.abstract import DWhoAbstractDB
from socket import getfqdn
Expand Down Expand Up @@ -138,6 +139,7 @@ class DWhoInoEventPlugBase(DWhoInoPlugBase, DWhoInotifyEventBase):
__metaclass__ = abc.ABCMeta

def __init__(self):
self.cfg_path = None
DWhoInoPlugBase.__init__(self)
DWhoInotifyEventBase.__init__(self)

Expand All @@ -148,6 +150,25 @@ def init(self, config):
return self

@abc.abstractmethod
def __call__(self, event, filepath):
def run(self, cfg_path, event, filepath):
"""Do the action."""
return

def realdstpath(self, event, filepath, prefix = None):
if not self.cfg_path \
or self.cfg_path.path not in self.config['inotify']['paths']:
return filepath

r = filepath
cfg = self.config['inotify']['paths'][self.cfg_path.path]

if cfg.get('dst') and filepath.startswith(self.cfg_path.path):
r = os.path.join(cfg['dst'], filepath[len(self.cfg_path.path):])

if not prefix:
return r

return os.path.join(os.path.sep, prefix, r.lstrip(os.path.sep))

def __call__(self, cfg_path, event, filepath):
self.cfg_path = cfg_path
return self.run(cfg_path, event, filepath)
17 changes: 15 additions & 2 deletions dwho/classes/inotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@

MAX_WORKERS = 5

ALL_EVENTS = ('access',
'attrib',
'create',
'close_write',
'close_nowrite',
'delete',
'delete_self',
'modify',
'move_self',
'moved_from',
'moved_to',
'open')

DEFAULT_CONFIG = {'plugins': dict(zip(INOPLUGS.keys(),
[False] * len(INOPLUGS.keys()))),
'events': ['create',
Expand Down Expand Up @@ -134,7 +147,7 @@ def __call__(self, notifier, conf):

if value['exclude_files']:
for x in value['exclude_files']:
pattern = load_patterns_from_file(x)
pattern = helpers.load_patterns_from_file(x)
if not pattern:
raise DWhoConfigurationError("Unable to load exclude patterns from %r. (path: %r)"
% (x, path))
Expand Down Expand Up @@ -167,7 +180,7 @@ def __call__(self, notifier, conf):

@staticmethod
def valid_event(event):
return event in DEFAULT_CONFIG['events']
return event in ALL_EVENTS


class DWhoInotify(Thread):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Mako
pyyaml>=3.10
pyinotify
redis>=2.4.0
requests
sonicprobe
requests>=2.0
sonicprobe>=0.2.42
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import find_packages, setup

requirements = [line.strip() for line in open('requirements.txt', 'r').readlines()]
version = '0.2.28'
version = '0.2.29'

if os.path.isfile('VERSION'):
version = open('VERSION', 'r').readline().strip() or version
Expand Down

0 comments on commit be06bdb

Please sign in to comment.