| Line | |
|---|
| 1 | # Example |
|---|
| 2 | # |
|---|
| 3 | from pyinotify import * |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | class 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 | |
|---|
| 14 | class TrackMofications(ProcessEvent): |
|---|
| 15 | def process_IN_MODIFY(self, event): |
|---|
| 16 | print 'IN_MODIFY' |
|---|
| 17 | |
|---|
| 18 | def process_default(self, event): |
|---|
| 19 | pass |
|---|
| 20 | |
|---|
| 21 | class 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) |
|---|
| 30 | fo = file('/var/log/pyinotify_log', 'w') |
|---|
| 31 | wm = WatchManager() |
|---|
| 32 | # It is important to pass named extra arguments like 'fileobj'. |
|---|
| 33 | notifier = Notifier(wm, |
|---|
| 34 | default_proc_fun=Empty(TrackMofications(Log(fileobj=fo)), |
|---|
| 35 | msg='outtee chained function')) |
|---|
| 36 | wm.add_watch('/tmp', ALL_EVENTS) |
|---|
| 37 | notifier.loop() |
|---|
| 38 | fo.close() |
|---|