b4d4d844fd
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
32 lines
953 B
Python
32 lines
953 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):
|
|
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()
|