diff --git a/scripts/install.sh b/scripts/install.sh index 12d9b74..ff06868 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -118,6 +118,12 @@ fi # Install rc.local cp scripts/rc.local /etc/ +# Ensure that the watchdog python library is installed +pip3 list --format=columns | grep watchdog >/dev/null +if [ $? -ne 0 ]; then + pip3 install scripts/watchdog-v0.10.6.tar.gz +fi + # Install bbctrl if $UPDATE_PY; then rm -rf /usr/local/lib/python*/dist-packages/bbctrl-* diff --git a/scripts/watchdog-v0.10.6.tar.gz b/scripts/watchdog-v0.10.6.tar.gz new file mode 100644 index 0000000..e431b31 Binary files /dev/null and b/scripts/watchdog-v0.10.6.tar.gz differ diff --git a/setup.py b/setup.py index cf4069d..e3ff885 100755 --- a/setup.py +++ b/setup.py @@ -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, ) diff --git a/src/py/bbctrl/State.py b/src/py/bbctrl/State.py index 2bb42fc..3cb17e7 100644 --- a/src/py/bbctrl/State.py +++ b/src/py/bbctrl/State.py @@ -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'