]> Repositories - Adafruit_Blinka-hackapet.git/blob - python/upload_feather_sync.py
Routine to force files on Feather to match local whenever they are changed
[Adafruit_Blinka-hackapet.git] / python / upload_feather_sync.py
1 # dependencies
2 # pip3 install watchdog
3 import time
4 import subprocess
5 from watchdog.observers import Observer
6
7 command = 'rsync --prune-empty-dirs --include="*/" --include="*.py" --exclude="*" --recursive --whole-file --verbose --progress ./ /media/cefn/CIRCUITPY'
8
9 syncing = False;
10 def sync():
11     syncing = True
12     subprocess.run(command, shell=True)
13     syncing = False
14
15 class ChangeEventHandler:
16     def dispatch(self, event):
17         if not syncing:
18             sync()
19
20 if __name__ == "__main__":
21     observer = Observer()
22     observer.schedule(ChangeEventHandler(), ".", recursive=True)
23     observer.start()
24     try:
25         while True:
26             time.sleep(1)
27     except KeyboardInterrupt:
28         observer.stop()
29     observer.join()