blob: 79577176e7415059d69e5fb193b7e8b4ce475064 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# Example: monitors transient files.
#
# Run this code, then run transient_file.sh in another shell.
from pyinotify import *
class ProcessTransientFile(ProcessEvent):
def process_IN_MODIFY(self, event):
# We have explicitely registered for this kind of event.
print '\t', event.pathname, ' -> written'
def process_default(self, event):
# Implicitely IN_CREATE and IN_DELATE are watched too. You can
# ignore them and provide an empty process_default or you can
# process them, either with process_default or their dedicated
# method (process_IN_CREATE, process_IN_DELETE) which would
# override process_default.
print 'default: ', event.maskname
wm = WatchManager()
notifier = Notifier(wm)
# In this case you must give the class object (ProcessTransientFile)
# as last parameter not a class instance.
wm.watch_transient_file('/tmp/test1234', IN_MODIFY, ProcessTransientFile)
notifier.loop()
|