]> Repositories - Adafruit_Blinka-hackapet.git/blob - python/upload_feather_m0_watch.py
Suppress bytecode files
[Adafruit_Blinka-hackapet.git] / python / upload_feather_m0_watch.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     # should already be built-in to circuitpython
15     '--exclude="/board" '
16     '--exclude="/digitalio" '
17     '--exclude="/microcontroller" '
18     # prefer unittest.mpy bytecode
19     '--exclude="/unittest.py" '
20     # should never be used by tests targeting feather m0
21     '--exclude="mcp" '
22     # don't upload upload https://www.youtube.com/watch?v=iEwW6D0sht0
23     '--exclude="upload_*_watch.py" '
24     # recurse in search
25     '--include="*/" '
26     # filter for python source files and micropython bytecode files
27     '--include="*.py" '
28     '--include="*.mpy" '
29     # exclude everything else
30     '--exclude="*" '
31     # rsync from folder
32     './ '
33     # rsync to folder
34     '/media/cefn/CIRCUITPY '
35 )
36
37 syncing = False
38
39 def sync():
40     """Synchronizes from git repo to Feather filesystem"""
41     global syncing
42     syncing = True
43     subprocess.run(command, shell=True)
44     syncing = False
45
46 class ChangeEventHandler:
47     """handler for future filesystem events"""
48     def dispatch(self, event):
49         if not syncing:
50             sync()
51
52 if __name__ == "__main__":
53     sync()
54     handler=ChangeEventHandler() 
55     
56     # set up filesystem monitoring
57     observer = Observer()
58     observer.schedule(handler, ".", recursive=True)
59     observer.start()
60     
61     # await CTRL+C
62     try:
63         while True:
64             time.sleep(1)
65     except KeyboardInterrupt:
66         observer.stop()
67     # join daemon thread to shutdown interpreter
68     observer.join()