bicycle-statistics/input_observer/__init__.py
Thomas Klaehn 629794d5f2 bicycle-statistics: Add logger
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
2018-07-30 13:56:03 +02:00

33 lines
989 B
Python

from watchdog.events import PatternMatchingEventHandler
import threading
class InputObserver(PatternMatchingEventHandler):
def __init__(self, patterns=None, ignore_patterns=None,
ignore_directories=False, case_sensitive=False):
super(InputObserver, self).__init__(patterns, ignore_patterns,
ignore_directories, case_sensitive)
self.lock = threading.Lock()
self.lock.acquire()
self.new_filename = None
self.run_condition = True
# def on_created(self, event):
def on_any_event(self, event):
self.new_filename = event.src_path
self.lock.release()
def get_new_file(self):
self.lock.acquire() # don't release - will be released with next on_created
if self.run_condition == True:
return self.new_filename
else:
return None
def stop(self):
self.run_condition = False
self.lock.release()