QA: remove the --default-hypervisor option
[ganeti-local] / lib / asyncnotifier.py
1 #
2 #
3
4 # Copyright (C) 2009 Google Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21
22 """Asynchronous pyinotify implementation"""
23
24
25 import pyinotify
26 import asyncore
27
28
29 class AsyncNotifier(asyncore.file_dispatcher):
30   """An asyncore dispatcher for inotify events.
31
32   """
33
34   def __init__(self, watch_manager,
35                default_proc_fun=None,
36                map=None):
37     """
38     Constructor for AsyncNotifier, a special asyncore file_dispatcher that
39     actually wraps a pyinotify Notifier, making it asyncronous.
40
41     """
42     if default_proc_fun is None:
43       default_proc_fun=pyinotify.ProcessEvent()
44     self.notifier = pyinotify.Notifier(watch_manager, default_proc_fun)
45     # here we need to steal the file descriptor from the notifier, so we can
46     # use it in the global asyncore select, and avoid calling the
47     # check_events() function of the notifier (which doesn't allow us to select
48     # together with other file descriptors)
49     self.fd = self.notifier._fd
50     asyncore.file_dispatcher.__init__(self, self.fd, map)
51
52   def handle_read(self):
53     self.notifier.read_events()
54     self.notifier.process_events()
55