<commit_before># Module:   notify
# Date:     2nd March 2009
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""File Notification Support

A Component wrapping the inotify API using the pyinotify library.
"""

try:
    from pyinotify import IN_UNMOUNT
    from pyinotify import WatchManager, Notifier, ALL_EVENTS
    from pyinotify import IN_ACCESS, IN_MODIFY, IN_ATTRIB, IN_CLOSE_WRITE
    from pyinotify import IN_CREATE, IN_DELETE, IN_DELETE_SELF, IN_MOVE_SELF
    from pyinotify import IN_CLOSE_NOWRITE, IN_OPEN, IN_MOVED_FROM, IN_MOVED_TO
except ImportError:
    raise Exception("No pyinotify support available. Is pyinotify installed?")

from circuits.core.utils import findcmp
from circuits.core import handler, Component, Event
from circuits.core.pollers import BasePoller, Poller

MASK = ALL_EVENTS


class Ready(Event):
    """Ready Event"""


class AddPath(Event):
    """Add path to watch"""
    channel = 'add_path'


class RemovePath(Event):
    """Remove path from watch"""
    channel = 'remove_path'


class Moved(Event):
    """Moved Event"""


class Opened(Event):
    """Opened Event"""


class Closed(Event):
    """Closed Event"""


class Created(Event):
    """Created Event"""


class Deleted(Event):
    """Deleted Event"""


class Accessed(Event):
    """Accessed Event"""


class Modified(Event):
    """Modified Event"""


class Unmounted(Event):
    """Unmounted Event"""


EVENT_MAP = {
    IN_MOVED_TO:        Moved,
    IN_MOVE_SELF:       Moved,
    IN_MOVED_FROM:      Moved,
    IN_CLOSE_WRITE:     Closed,
    IN_CLOSE_NOWRITE:   Closed,
    IN_OPEN:            Opened,
    IN_DELETE_SELF:     Deleted,
    IN_DELETE:          Deleted,
    IN_CREATE:          Created,
    IN_ACCESS:          Accessed,
    IN_MODIFY:          Modified,
    IN_ATTRIB:          Modified,
    IN_UNMOUNT:         Unmounted,
}


class Notify(Component):

    channel = "notify"

    def __init__(self, channel=channel):
        super(Notify, self).__init__(channel=channel)

        self._poller = None
        self._wm = WatchManager()
        self._notifier = Notifier(self._wm, self._process)

    def _process(self, event):
        dir = event.dir
        mask = event.mask
        path = event.path
        name = event.name
        pathname = event.pathname

        for k, v in EVENT_MAP.items():
            if mask & k:
                self.fire(v(name, path, pathname, dir))

    def add_path(self, path, mask=None, recursive=False):
        mask = mask or MASK
        self._wm.add_watch(path, mask, rec=recursive)

    def remove_path(self, path, recursive=False):
        wd = self._wm.get_wd(path)
        if wd:<commit_msg>Fixed name of method for handling inotify events - conflicting with ._process of Manager/Component<commit_after># Module:   notify
# Date:     2nd March 2009
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""File Notification Support

A Component wrapping the inotify API using the pyinotify library.
"""

try:
    from pyinotify import IN_UNMOUNT
    from pyinotify import WatchManager, Notifier, ALL_EVENTS
    from pyinotify import IN_ACCESS, IN_MODIFY, IN_ATTRIB, IN_CLOSE_WRITE
    from pyinotify import IN_CREATE, IN_DELETE, IN_DELETE_SELF, IN_MOVE_SELF
    from pyinotify import IN_CLOSE_NOWRITE, IN_OPEN, IN_MOVED_FROM, IN_MOVED_TO
except ImportError:
    raise Exception("No pyinotify support available. Is pyinotify installed?")

from circuits.core.utils import findcmp
from circuits.core import handler, Component, Event
from circuits.core.pollers import BasePoller, Poller

MASK = ALL_EVENTS


class Ready(Event):
    """Ready Event"""


class AddPath(Event):
    """Add path to watch"""


class RemovePath(Event):
    """Remove path from watch"""


class Moved(Event):
    """Moved Event"""


class Opened(Event):
    """Opened Event"""


class Closed(Event):
    """Closed Event"""


class Created(Event):
    """Created Event"""


class Deleted(Event):
    """Deleted Event"""


class Accessed(Event):
    """Accessed Event"""


class Modified(Event):
    """Modified Event"""


class Unmounted(Event):
    """Unmounted Event"""


EVENT_MAP = {
    IN_MOVED_TO:        Moved,
    IN_MOVE_SELF:       Moved,
    IN_MOVED_FROM:      Moved,
    IN_CLOSE_WRITE:     Closed,
    IN_CLOSE_NOWRITE:   Closed,
    IN_OPEN:            Opened,
    IN_DELETE_SELF:     Deleted,
    IN_DELETE:          Deleted,
    IN_CREATE:          Created,
    IN_ACCESS:          Accessed,
    IN_MODIFY:          Modified,
    IN_ATTRIB:          Modified,
    IN_UNMOUNT:         Unmounted,
}


class Notify(Component):

    channel = "notify"

    def __init__(self, channel=channel):
        super(Notify, self).__init__(channel=channel)

        self._poller = None
        self._wm = WatchManager()
        self._notifier = Notifier(self._wm, self._on_process_events)

    def _on_process_events(self, event):
        dir = event.dir
        mask = event.mask
        path = event.path
        name = event.name
        pathname = event.pathname

        for k, v in EVENT_MAP.items():
            if mask & k:
                self.fire(v(name, path, pathname, dir))

    def add_path(self, path, mask=None, recursive=False):
        mask = mask or MASK
        self._wm.add_watch(path, mask, rec=recursive)

    def remove_path(self, path, recursive=False):
        wd = self._wm.get_wd(path)
        if wd:
{'fraction_non_alphanumeric': 0.09929472902746844, 'fraction_numerical': 0.001855976243504083, 'mean_word_length': 2.852037169406719, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7110335', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1693, 'n_words': 463}