Пример #1
0
 def add_watch(self, path):
     if path not in self.watching_paths:
         try:
             wm = WatchManager()
             notifier = QNotifier(wm, self._emit_signal_on_change)
             notifier.start()
             exclude = ExcludeFilter([
                 os.path.join(path, folder)
                 for folder in self._ignore_hidden
             ])
             wm.add_watch(path,
                          mask,
                          rec=True,
                          auto_add=True,
                          exclude_filter=exclude)
             self.watching_paths[path] = notifier
         except (OSError, IOError):
             pass
Пример #2
0
    def add_monitor_path(self, path):
        if path is None:
            Logger.error("FS: unable to monitor None directory")
            return False

        exclude1 = "^%s/conf.Windows*" % (path)
        exclude2 = "^%s/conf.Linux*" % (path)
        exc_filter = ExcludeFilter([exclude1, exclude2])

        try:
            self.add_watch(path=path,
                           mask=Rec.mask,
                           proc_fun=Rec(),
                           rec=True,
                           auto_add=True,
                           exclude_filter=exc_filter)
        except WatchManagerError, e:
            Logger.error("FS: unable to monitor directory %s, %s" %
                         (path, str(e)))
            return False
Пример #3
0
#!/usr/bin/env python
# vim: set sw=4 sts=4 et foldmethod=indent :

import os
from pyinotify import WatchManager, Notifier, ThreadedNotifier, ProcessEvent, ExcludeFilter
from subprocess import Popen, PIPE
import pyinotify
import os.path
import os, re

excludes = ExcludeFilter("/home/nikolavp/excludes")
wm = WatchManager(exclude_filter=excludes)
mask = pyinotify.IN_CLOSE_WRITE


class PyWatchEventProcessor(ProcessEvent):
    def __init__(self):
        self.rules = {}

    def process_default(self, event):
        if excludes(event.name):
            return
        modified_filename = os.path.join(event.path, event.name)
        for pattern, function in self.rules.items():
            matcher = pattern.match(modified_filename)
            if matcher:
                function(matcher)

    def addRule(self, regexp_str, func):
        pattern = re.compile(regexp_str)
        self.rules[pattern] = func