root / chain.py

Revision ca5ddc5f5eea62c76b6be75a1fbdedf663dbcfd0, 0.9 kB (checked in by Sebastien Martini <ookoi@…>, 6 months ago)

Flag example files as 'Example'.

  • Property mode set to 100644
Line 
1# Example
2#
3from pyinotify import *
4
5
6class Log(ProcessEvent):
7    def my_init(self, fileobj):
8        self._fileobj = fileobj
9
10    def process_default(self, event):
11        self._fileobj.write(str(event) + '\n')
12        self._fileobj.flush()
13
14class TrackMofications(ProcessEvent):
15    def process_IN_MODIFY(self, event):
16        print 'IN_MODIFY'
17
18    def process_default(self, event):
19        pass
20
21class Empty(ProcessEvent):
22    def my_init(self, msg):
23        self._msg = msg
24
25    def process_default(self, event):
26        print self._msg
27
28
29#log.setLevel(10)
30fo = file('/var/log/pyinotify_log', 'w')
31wm = WatchManager()
32# It is important to pass named extra arguments like 'fileobj'.
33notifier = Notifier(wm,
34                    default_proc_fun=Empty(TrackMofications(Log(fileobj=fo)),
35                                           msg='outtee chained function'))
36wm.add_watch('/tmp', ALL_EVENTS)
37notifier.loop()
38fo.close()
Note: See TracBrowser for help on using the browser.