2
# -*- coding: iso-8859-1 -*-
4
# close.py - process several events with the same method
5
# Copyright (C) 2006 S�bastien Martini <sebastien.martini@gmail.com>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
# usage: ./close.py '/path-to-watch'
25
# please read src/examples/README
29
from src.pyinotify.pyinotify import SimpleINotify, ProcessEvent, \
32
# import global (installed) pyinotify
33
from pyinotify import SimpleINotify, ProcessEvent, EventsCodes
37
class PClose(ProcessEvent):
38
def process_IN_CLOSE(self, event_k):
40
process 'IN_CLOSE_*' events
43
f = "%s" % os.path.join(event_k.path, event_k.name)
45
f = "%s" % event_k.path
46
print "%s: closed" % f
50
if __name__ == '__main__':
52
# - watch for IN_CLOSE_* events and process them with
53
# the same processing method.
54
# - The watched path is '/tmp' (by default) or the first
55
# command line argument if given.
59
path = '/tmp' # default watched path
63
# only watch those events
64
mask = EventsCodes.IN_CLOSE_WRITE | EventsCodes.IN_CLOSE_NOWRITE
66
# class instance and init
69
print 'start monitoring %s with mask %d' % (path, mask)
72
# read and process events
76
# on first iteration, add a watch on path:
77
# watch path for events handled by mask and give an
78
# instance of PClose as processing function.
79
ino.add_watch(path, mask, PClose())
84
except KeyboardInterrupt:
86
print 'stop monitoring...'
87
# close inotify's instance
90
except Exception, err:
91
# otherwise keep on watching