| Line | |
|---|
| 1 | # Example |
|---|
| 2 | # |
|---|
| 3 | from pyinotify import * |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | class Identity(ProcessEvent): |
|---|
| 7 | |
|---|
| 8 | def process_default(self, event): |
|---|
| 9 | # Does nothing, just to demonstrate how stuffs could trivially |
|---|
| 10 | # be accomplished after having processed statistics. |
|---|
| 11 | pass |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | def on_loop(notifier): |
|---|
| 15 | # notifier.proc_fun() is Identity's instance |
|---|
| 16 | s_inst = notifier.proc_fun().nested_pevent() |
|---|
| 17 | print repr(s_inst), '\n', s_inst, '\n' |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | wm = WatchManager() |
|---|
| 21 | # Stats is a subclass of ProcessEvent provided by pyinotify |
|---|
| 22 | # for computing basics statistics. |
|---|
| 23 | s = Stats() |
|---|
| 24 | notifier = Notifier(wm, default_proc_fun=Identity(s), read_freq=5) |
|---|
| 25 | wm.add_watch('/tmp/', ALL_EVENTS, rec=True, auto_add=True) |
|---|
| 26 | notifier.loop(callback=on_loop) |
|---|