]> Repositories - Adafruit_Blinka-hackapet.git/blob - test/scripts/watch_pyboard.py
Separated into uart, i2c tests
[Adafruit_Blinka-hackapet.git] / test / scripts / watch_pyboard.py
1 #!/usr/bin/python3
2 # Verified on Ubuntu with dependencies...
3 # pip3 install watchdog
4 # sudo apt install rsync
5 import time
6 import subprocess
7 from watchdog.observers import Observer
8
9 # the rsync command intended to selectively upload from the local repo to a feather m0 express
10 command = (
11     'rsync '
12     '--recursive --verbose --progress '
13     '--prune-empty-dirs --inplace --times --archive --whole-file '
14     # prefer unittest.py source code
15     '--exclude="/unittest.mpy" '
16     # don't upload upload https://www.youtube.com/watch?v=iEwW6D0sht0
17     '--exclude="upload_*_watch.py" '
18     # recurse in search
19     '--include="*/" '
20     # filter for python source files and micropython bytecode files
21     #'--include="*.py" '
22     '--include="*.mpy" '
23     # exclude everything else
24     '--exclude="*" '
25     # rsync from folder
26     './ '
27     # rsync to folder
28     '/media/cefn/PYBFLASH '
29 )
30
31 syncing = False
32
33 def sync():
34     """Synchronizes from git repo to Feather filesystem"""
35     global syncing
36     syncing = True
37     subprocess.run(command, shell=True)
38     syncing = False
39
40 class ChangeEventHandler:
41     """handler for future filesystem events"""
42     def dispatch(self, event):
43         if not syncing:
44             sync()
45
46 if __name__ == "__main__":
47     sync()
48     handler=ChangeEventHandler() 
49     
50     # set up filesystem monitoring
51     observer = Observer()
52     observer.schedule(handler, ".", recursive=True)
53     observer.start()
54     
55     # await CTRL+C
56     try:
57         while True:
58             time.sleep(1)
59     except KeyboardInterrupt:
60         observer.stop()
61     # join daemon thread to shutdown interpreter
62     observer.join()