<commit_before>import os
from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent

from wizbit import *
from wizbit import Repo, Directory, defaultShares
import gnotifier

import gobject

class InotifyProcessor(ProcessEvent):
    def process_IN_CLOSE_WRITE(self, event):
        if not isWizdir(event.path):
            print 'CLOSE_WRITE', os.path.join(event.path, event.name)
            if event.name:
                path = os.path.join(event.path, event.name)
                base = getWizPath(path)
                wizpath = Paths(base)
                filename = wizpath.getRelFilename(path)
                if Repo.update(wizpath, filename):
                    #Push to others of the same shares
                    pass

    def process_IN_CREATE(self, event):
        if not isWizdir(event.path):
            print 'CREATE', os.path.join(event.path, event.name)
            if event.name:
                path = os.path.join(event.path, event.name)
                base = getWizPath(path)
                if Directory.add(base, path):
                    #Push to others of the same shares
                    pass
            #What is going on here? Do we track dirs??

    def process_IN_DELETE(self, event):
        if not isWizdir(event.path):
            print 'DELETE', os.path.join(event.path, event.name)
            if event.name:
                path = os.path.join(event.path, event.name)
                base = getWizPath(path)
                wizpath = Paths(base)
                filename = wizpath.getRelFilename(path)
                if Repo.remove(wizpath, filename):
                    #Push to others of the same shares
                    pass


    def process_default(self, event):
        if not isWizdir(event.path):
            #print event.event_name, os.path.join(event.path, event.name)
            pass

class SharesObserver():
    """
    Watches all shares directories using pyinotify.
    """
    __single = None

    def __init__(self, shares = defaultShares()):
                self.__shares = shares
        self.__directories = []
        self.__wm = WatchManager()
        self.__loadShares(EventsCodes.IN_CLOSE_WRITE)
                print "watching", shares.shares_path
        self.__wm.add_watch(shares.shares_path, EventsCodes.IN_CLOSE_WRITE, proc_fun=self.__loadShares)
        self.__notifier = gnotifier.GNotifier(self.__wm)

    def __loadShares(self, event):
                print "loadshares"
        shares = self.__shares.getShares()
        added = [directory for id, shrId, directory in shares if directory not in self.__directories]
        tempDirs = [directory for id, shrId, directory in shares]
        removed = [directory for directory in self.__directories if directory not in tempDirs]
        for directory in added:<commit_msg>Remove unused member of SharesObserver, fix up some whitespace.<commit_after>import os
from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent

from wizbit import *
from wizbit import Repo, Directory, defaultShares
import gnotifier

import gobject

class InotifyProcessor(ProcessEvent):
    def process_IN_CLOSE_WRITE(self, event):
        if not isWizdir(event.path):
            print 'CLOSE_WRITE', os.path.join(event.path, event.name)
            if event.name:
                path = os.path.join(event.path, event.name)
                base = getWizPath(path)
                wizpath = Paths(base)
                filename = wizpath.getRelFilename(path)
                if Repo.update(wizpath, filename):
                    #Push to others of the same shares
                    pass

    def process_IN_CREATE(self, event):
        if not isWizdir(event.path):
            print 'CREATE', os.path.join(event.path, event.name)
            if event.name:
                path = os.path.join(event.path, event.name)
                base = getWizPath(path)
                if Directory.add(base, path):
                    #Push to others of the same shares
                    pass
            #What is going on here? Do we track dirs??

    def process_IN_DELETE(self, event):
        if not isWizdir(event.path):
            print 'DELETE', os.path.join(event.path, event.name)
            if event.name:
                path = os.path.join(event.path, event.name)
                base = getWizPath(path)
                wizpath = Paths(base)
                filename = wizpath.getRelFilename(path)
                if Repo.remove(wizpath, filename):
                    #Push to others of the same shares
                    pass


    def process_default(self, event):
        if not isWizdir(event.path):
            #print event.event_name, os.path.join(event.path, event.name)
            pass

class SharesObserver(gobject.GObject):
    """
    Watches all shares directories using pyinotify.
    """

    def __init__(self, shares = defaultShares()):
                self.__shares = shares
        self.__directories = []
        self.__wm = WatchManager()
        self.__loadShares(EventsCodes.IN_CLOSE_WRITE)
        print "watching", shares.shares_path
        self.__wm.add_watch(shares.shares_path, EventsCodes.IN_CLOSE_WRITE, proc_fun=self.__loadShares)
        self.__notifier = gnotifier.GNotifier(self.__wm)

    def __loadShares(self, event):
                print "loadshares"
        shares = self.__shares.getShares()
        added = [directory for id, shrId, directory in shares if directory not in self.__directories]
        tempDirs = [directory for id, shrId, directory in shares]
        removed = [directory for directory in self.__directories if directory not in tempDirs]
        for directory in added:
{'fraction_non_alphanumeric': 0.0841072367268267, 'fraction_numerical': 0.0, 'mean_word_length': 2.0524064171122993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5854016', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1592, 'n_words': 421}