From: Cefn Hoile Date: Sun, 18 Feb 2018 01:31:51 +0000 (+0000) Subject: Improved routine to minimise re-uploading, separate non-CircuitPython files, use... X-Git-Tag: 0.1.0~4^2~131 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/25439099270096095b0100dc3ecc92d49a22e963 Improved routine to minimise re-uploading, separate non-CircuitPython files, use unittest.mpy. Renamed for consistency --- diff --git a/python/upload_feather_m0_watch.py b/python/upload_feather_m0_watch.py new file mode 100755 index 0000000..21c4765 --- /dev/null +++ b/python/upload_feather_m0_watch.py @@ -0,0 +1,68 @@ +#!/usr/bin/python3 +# Verified on Ubuntu with dependencies... +# pip3 install watchdog +# sudo apt install rsync +import time +import subprocess +from watchdog.observers import Observer + +# the rsync command intended to selectively upload from the local repo to a feather m0 express +command = ( + 'rsync ' + '--recursive --verbose --progress ' + '--prune-empty-dirs --inplace --times --archive --whole-file ' + # should already be built-in to circuitpython + '--exclude="/board" ' + '--exclude="/digitalio" ' + '--exclude="/microcontroller" ' + # prefer unittest.mpy bytecode + '--exclude="/unittest.py" ' + # should never be used by tests targeting feather m0 + '--exclude="mcp" ' + # don't upload upload https://www.youtube.com/watch?v=iEwW6D0sht0 + '--exclude="upload_*_watch.py" ' + # recurse in search + '--include="*/" ' + # filter for python source files and micropython bytecode files + '--include="*.py" ' + '--include="*.mpy" ' + # exclude everything else + '--exclude="*" ' + # rsync from folder + './ ' + # rsync to folder + '/media/cefn/CIRCUITPY ' +) + +syncing = False + +def sync(): + """Synchronizes from git repo to Feather filesystem""" + global syncing + syncing = True + subprocess.run(command, shell=True) + syncing = False + +class ChangeEventHandler: + """handler for future filesystem events""" + def dispatch(self, event): + if not syncing: + sync() + +if __name__ == "__main__": + sync() + handler=ChangeEventHandler() + + # set up filesystem monitoring + observer = Observer() + observer.schedule(handler, ".", recursive=True) + observer.start() + + # await CTRL+C + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() + # join daemon thread to shutdown interpreter + observer.join() diff --git a/python/upload_feather_sync.py b/python/upload_feather_sync.py deleted file mode 100644 index b3dac48..0000000 --- a/python/upload_feather_sync.py +++ /dev/null @@ -1,29 +0,0 @@ -# dependencies -# pip3 install watchdog -import time -import subprocess -from watchdog.observers import Observer - -command = 'rsync --prune-empty-dirs --include="*/" --include="*.py" --exclude="*" --recursive --whole-file --verbose --progress ./ /media/cefn/CIRCUITPY' - -syncing = False; -def sync(): - syncing = True - subprocess.run(command, shell=True) - syncing = False - -class ChangeEventHandler: - def dispatch(self, event): - if not syncing: - sync() - -if __name__ == "__main__": - observer = Observer() - observer.schedule(ChangeEventHandler(), ".", recursive=True) - observer.start() - try: - while True: - time.sleep(1) - except KeyboardInterrupt: - observer.stop() - observer.join()