Merge pull request #24 from dacarley/watch-for-uploaded-files

Added a filesystem watcher for uploaded files
This commit is contained in:
OneFinityCNC
2021-03-06 14:51:52 -05:00
committed by GitHub
4 changed files with 20 additions and 1 deletions

View File

@@ -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-*

Binary file not shown.

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'