From ac96953da33049f4d8017a0cce6475e93b3ec037 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 13 Oct 2010 15:13:44 +0200
Subject: [PATCH] Fix compatibility with Pyinotify 0.8
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

I didn't know why the code previously used
β€œpyinotify.EventsCodes.ALL_FLAGS” instead of using the flags from
β€œpyinotify.EventsCodes” directly. Turns out that Pyinotify 0.8 has them
in β€œpyinotify”, not β€œpyinotify.EventsCodes”.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 daemons/ganeti-rapi  | 11 ++++++-----
 lib/asyncnotifier.py |  7 ++++---
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/daemons/ganeti-rapi b/daemons/ganeti-rapi
index 29469febc..ebc9280c0 100755
--- a/daemons/ganeti-rapi
+++ b/daemons/ganeti-rapi
@@ -253,11 +253,12 @@ class FileEventHandler(asyncnotifier.FileEventHandlerBase):
     self._cb = cb
     self._filename = os.path.basename(path)
 
-    # Class '...' has no 'IN_...' member, pylint: disable-msg=E1103
-    mask = (pyinotify.EventsCodes.IN_CLOSE_WRITE |
-            pyinotify.EventsCodes.IN_DELETE |
-            pyinotify.EventsCodes.IN_MOVED_FROM |
-            pyinotify.EventsCodes.IN_MOVED_TO)
+    # Different Pyinotify versions have the flag constants at different places,
+    # hence not accessing them directly
+    mask = (pyinotify.EventsCodes.ALL_FLAGS["IN_CLOSE_WRITE"] |
+            pyinotify.EventsCodes.ALL_FLAGS["IN_DELETE"] |
+            pyinotify.EventsCodes.ALL_FLAGS["IN_MOVED_FROM"] |
+            pyinotify.EventsCodes.ALL_FLAGS["IN_MOVED_TO"])
 
     self._handle = self.AddWatch(os.path.dirname(path), mask)
 
diff --git a/lib/asyncnotifier.py b/lib/asyncnotifier.py
index e9b68cac9..9d5610ee7 100644
--- a/lib/asyncnotifier.py
+++ b/lib/asyncnotifier.py
@@ -153,9 +153,10 @@ class SingleFileEventHandler(FileEventHandlerBase):
     if self._watch_handle is not None:
       return
 
-    # Class '...' has no 'IN_...' member, pylint: disable-msg=E1103
-    mask = (pyinotify.EventsCodes.IN_MODIFY |
-            pyinotify.EventsCodes.IN_IGNORED)
+    # Different Pyinotify versions have the flag constants at different places,
+    # hence not accessing them directly
+    mask = (pyinotify.EventsCodes.ALL_FLAGS["IN_MODIFY"] |
+            pyinotify.EventsCodes.ALL_FLAGS["IN_IGNORED"])
 
     self._watch_handle = self.AddWatch(self._filename, mask)
 
-- 
GitLab