diff options
author | Sebastien Martini <seb@dbzteam.org> | 2009-11-11 18:13:24 +0100 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2009-11-11 18:13:24 +0100 |
commit | add26a10a28661d88710c99d10a1cf2065c06d04 (patch) | |
tree | 881319888979d2ca84e63732ee1f4f809b52e292 /python2/examples/chain.py | |
parent | 649429ae8af743d9c404c1cc219bd018ae073578 (diff) | |
download | pyinotify-add26a10a28661d88710c99d10a1cf2065c06d04.tar.gz |
Updated examples.
Diffstat (limited to 'python2/examples/chain.py')
-rw-r--r-- | python2/examples/chain.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/python2/examples/chain.py b/python2/examples/chain.py index 9760414..5f110ee 100644 --- a/python2/examples/chain.py +++ b/python2/examples/chain.py @@ -1,8 +1,8 @@ # Example: monitors events and logs them into a log file. # -from pyinotify import * +import pyinotify -class Log(ProcessEvent): +class Log(pyinotify.ProcessEvent): def my_init(self, fileobj): """ Method automatically called from ProcessEvent.__init__(). Additional @@ -15,11 +15,11 @@ class Log(ProcessEvent): self._fileobj.write(str(event) + '\n') self._fileobj.flush() -class TrackModifications(ProcessEvent): +class TrackModifications(pyinotify.ProcessEvent): def process_IN_MODIFY(self, event): print 'IN_MODIFY' -class Empty(ProcessEvent): +class Empty(pyinotify.ProcessEvent): def my_init(self, msg): self._msg = msg @@ -27,13 +27,14 @@ class Empty(ProcessEvent): print self._msg -#log.setLevel(10) +# pyinotify.log.setLevel(10) fo = file('/var/log/pyinotify_log', 'w') -wm = WatchManager() -# It is important to pass named extra arguments like 'fileobj'. -notifier = Notifier(wm, - default_proc_fun=Empty(TrackModifications(Log(fileobj=fo)), - msg='outtee chained function')) -wm.add_watch('/tmp', ALL_EVENTS) -notifier.loop() -fo.close() +try: + wm = pyinotify.WatchManager() + # It is important to pass named extra arguments like 'fileobj'. + handler = Empty(TrackModifications(Log(fileobj=fo)), msg='Outer chained method') + notifier = pyinotify.Notifier(wm, default_proc_fun=handler) + wm.add_watch('/tmp', pyinotify.ALL_EVENTS) + notifier.loop() +finally: + fo.close() |