Mercurial > templog
annotate web/watch.py @ 639:89818a14648b rust tip
- switch to using anyhow for errors, surf for http
runs but surf has problems
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 28 Nov 2019 23:57:00 +0800 |
parents | 9c2de3f977e4 |
children |
rev | line source |
---|---|
189 | 1 #!/usr/bin/env python3.3 |
2 | |
3 import pyinotify | |
4 import glob | |
5 import sys | |
6 import fnmatch | |
7 import os | |
8 | |
9 def GlobWatcher(object): | |
10 def __init__(self, g, watcher): | |
11 self.glob = g | |
12 self.watches = [] | |
13 self.watcher = watcher | |
14 | |
15 def add_glob(watcher, g): | |
16 d = os.path.dirname(g) | |
17 | |
18 file_watches = add_glob_files | |
19 | |
20 def main(): | |
21 touchf = sys.argv[1] | |
22 | |
23 watcher = pyinotify.WatchManager() | |
24 dirpatterns = {} | |
25 for g in sys.argv[2:]: | |
26 d = os.path.dirname(g) | |
27 pattern = os.path.basename(g) | |
28 dirpatterns.setdefault(d, []).append(pattern) | |
29 | |
30 watchpatterns = {} | |
31 for d, patterns in dirpatterns.items(): | |
32 | |
33 w = watcher.add_watch(d, | |
34 (pyinotify.IN_MODIFY | |
35 |pyinotify.IN_CREATE | |
36 |pyinotify.IN_DELETE | |
37 |pyinotify.IN_MOVED_FROM | |
38 |pyinotify.IN_MOVED_TO)) | |
39 | |
40 wd = w[d] | |
41 watchpatterns[wd] = patterns | |
42 | |
43 def triggered(event): | |
44 if event.name is None: | |
45 return | |
46 | |
47 patterns = watchpatterns[event.wd] | |
48 for p in patterns: | |
49 if fnmatch.fnmatch(event.name, p): | |
207
9c2de3f977e4
- fermentation heat prediction kind of works?
Matt Johnston <matt@ucc.asn.au>
parents:
191
diff
changeset
|
50 print("matched %s %s %s" % (event.name, p, event.maskname)) |
189 | 51 os.utime(touchf, None) |
52 | |
53 n = pyinotify.Notifier(watcher, triggered) | |
54 n.loop() | |
55 | |
56 if __name__ == '__main__': | |
57 main() | |
58 |