Added a filesystem watcher for uploaded files

This commit is contained in:
David Carley
2021-03-06 01:26:14 -08:00
parent fd371f5189
commit 5cd7291581
2 changed files with 14 additions and 1 deletions

View File

@@ -35,6 +35,6 @@ setup(
'scripts/edit-boot-config',
'scripts/browser',
],
install_requires = 'tornado sockjs-tornado pyserial pyudev smbus2'.split(),
install_requires = 'tornado sockjs-tornado pyserial pyudev smbus2 watchdog'.split(),
zip_safe = False,
)

View File

@@ -30,6 +30,15 @@ import copy
import uuid
import os
import bbctrl
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class UploadChangeHandler(FileSystemEventHandler):
def __init__(self, state):
self.state = state
def on_any_event(self, event):
self.state.load_files()
class State(object):
@@ -79,6 +88,10 @@ class State(object):
self.reset()
self.load_files()
observer = Observer()
observer.schedule(UploadChangeHandler(self), self.ctrl.get_upload(), recursive=True)
observer.start()
#def is_metric(self): return self.get('units', 'METRIC') == 'METRIC'