| Line | |
|---|
| 1 | # Example |
|---|
| 2 | # |
|---|
| 3 | import time |
|---|
| 4 | from pyinotify import * |
|---|
| 5 | |
|---|
| 6 | # Do the same thing than stats.py but with a ThreadedNotifier's |
|---|
| 7 | # instance. |
|---|
| 8 | # This example illustrates the use of this class but the recommanded |
|---|
| 9 | # implementation is whom of stats.py |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | class Identity(ProcessEvent): |
|---|
| 13 | |
|---|
| 14 | def process_default(self, event): |
|---|
| 15 | # Does nothing, just to demonstrate how stuffs could be done |
|---|
| 16 | # after having processed statistics. |
|---|
| 17 | pass |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | wm = WatchManager() |
|---|
| 21 | s = Stats() # Stats is a subclass of ProcessEvent |
|---|
| 22 | notifier = ThreadedNotifier(wm, default_proc_fun=Identity(s)) |
|---|
| 23 | notifier.start() |
|---|
| 24 | wm.add_watch('/tmp/', ALL_EVENTS, rec=True, auto_add=True) |
|---|
| 25 | |
|---|
| 26 | while True: |
|---|
| 27 | try: |
|---|
| 28 | print repr(s) |
|---|
| 29 | print |
|---|
| 30 | print s |
|---|
| 31 | print |
|---|
| 32 | time.sleep(5) |
|---|
| 33 | except KeyboardInterrupt: |
|---|
| 34 | print 'stop monitoring...' |
|---|
| 35 | notifier.stop() |
|---|
| 36 | break |
|---|
| 37 | except Exception, err: |
|---|
| 38 | print err |
|---|