<commit_before>#
# Do some generic stuff to wrap whatever method is chosen.
#

import os, time
import threading, Queue


def IsModuleAvailable(moduleName):
    try:
        __import__(moduleName)
        return True
    except ImportError:
        return False


class ChangeHandler:
    watchState = None

    def __init__(self, callback):
        self.callback = callback
        self.thread = None
        self.directories = []

    def AddDirectory(self, path):
        self.directories.append(path)
        if self.thread is None:
            self.thread = ChangeThread(self)

    def ProcessFileAddition(self, path):
        self.callback(path, added=True)

    def ProcessFileChange(self, path):
        self.callback(path, changed=True)

    def ProcessFileDeletion(self, path):
        self.callback(path, deleted=True)

class ChangeThread(threading.Thread):
    def __init__(self, handler, **kwargs):
        threading.Thread.__init__ (self, **kwargs)
        self.setDaemon(1)

        self.handler = handler
        self.start()
        
    def run(self):
        module = None
        # Not ready for use.  If it is going to handle multiple directories,
        # it needs to be non-blocking.
        #if os.name == "nt":
        #    if IsModuleAvailable("win32file"):
        #        import golden3
        #        module = golden3.watch_directories        
        if module is None:
            import recipe215418
            module = recipe215418.watch_directories
        module.Prepare(self.handler)

        while len(handler.directories):
            module.Check(self.handler)
            time.sleep(1)

if __name__ == "__main__":
    path = r"C:\devkitPro\dl\livecoding\livecoding-google\trunk\filechanges"
    def f(path, added=False, changed=False, deleted=False):
        print "f", path, (added, changed, deleted)
    ch = ChangeHandler(f)
    ch.AddDirectory(path)

    while 1:
        time.sleep(10)<commit_msg>Corrected a bug which prevented the file change detection from working.<commit_after>#
# Do some generic stuff to wrap whatever method is chosen.
#

import os, time
import threading, Queue


def IsModuleAvailable(moduleName):
    try:
        __import__(moduleName)
        return True
    except ImportError:
        return False


class ChangeHandler:
    watchState = None

    def __init__(self, callback):
        self.callback = callback
        self.thread = None
        self.directories = []

    def AddDirectory(self, path):
        self.directories.append(path)
        if self.thread is None:
            self.thread = ChangeThread(self)

    def ProcessFileAddition(self, path):
        self.callback(path, added=True)

    def ProcessFileChange(self, path):
        self.callback(path, changed=True)

    def ProcessFileDeletion(self, path):
        self.callback(path, deleted=True)

class ChangeThread(threading.Thread):
    def __init__(self, handler, **kwargs):
        threading.Thread.__init__ (self, **kwargs)
        self.setDaemon(1)

        self.handler = handler
        self.start()
        
    def run(self):
        module = None
        # Not ready for use.  If it is going to handle multiple directories,
        # it needs to be non-blocking.
        #if os.name == "nt":
        #    if IsModuleAvailable("win32file"):
        #        import golden3
        #        module = golden3        
        if module is None:
            import recipe215418
            module = recipe215418
        module.Prepare(self.handler)

        while len(self.handler.directories):
            module.Check(self.handler)
            time.sleep(1)

if __name__ == "__main__":
    path = r"C:\devkitPro\dl\livecoding\livecoding-google\trunk\filechanges"
    def f(path, added=False, changed=False, deleted=False):
        print "f", path, (added, changed, deleted) 
    ch = ChangeHandler(f)
    ch.AddDirectory(path)

    while 1:
        time.sleep(10)
{'fraction_non_alphanumeric': 0.09438775510204081, 'fraction_numerical': 0.010714285714285714, 'mean_word_length': 2.3116554054054053, 'pattern_counts': {'":': 4, '<': 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': '3358849', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1102, 'n_words': 293}