comparison web/watch.py @ 489:46e327c00246

gets current params
author Matt Johnston <matt@ucc.asn.au>
date Tue, 11 Feb 2014 22:10:32 +0800
parents 4792e9910cde
children 9c2de3f977e4
comparison
equal deleted inserted replaced
488:4792e9910cde 489:46e327c00246
25 for g in sys.argv[2:]: 25 for g in sys.argv[2:]:
26 d = os.path.dirname(g) 26 d = os.path.dirname(g)
27 pattern = os.path.basename(g) 27 pattern = os.path.basename(g)
28 dirpatterns.setdefault(d, []).append(pattern) 28 dirpatterns.setdefault(d, []).append(pattern)
29 29
30 print(dirpatterns)
31
32 watchpatterns = {} 30 watchpatterns = {}
33 for d, patterns in dirpatterns.items(): 31 for d, patterns in dirpatterns.items():
34 32
35 w = watcher.add_watch(d, 33 w = watcher.add_watch(d,
36 (pyinotify.IN_MODIFY 34 (pyinotify.IN_MODIFY
44 42
45 def triggered(event): 43 def triggered(event):
46 if event.name is None: 44 if event.name is None:
47 return 45 return
48 46
49 print("%s %s " % (event.name, event.maskname))
50 patterns = watchpatterns[event.wd] 47 patterns = watchpatterns[event.wd]
51 for p in patterns: 48 for p in patterns:
52 print(p)
53 if fnmatch.fnmatch(event.name, p): 49 if fnmatch.fnmatch(event.name, p):
54 print("matched %s" % p) 50 print("matched %s %s" % (event.name, p, event.maskname))
55 os.utime(touchf, None) 51 os.utime(touchf, None)
56 52
57 n = pyinotify.Notifier(watcher, triggered) 53 n = pyinotify.Notifier(watcher, triggered)
58 n.loop() 54 n.loop()
59 55