changeset 1893:4f252b72b193

jp (blog/preview): change watch for IN_MOVE_SELF event, needed at least for Emacs
author Goffi <goffi@goffi.org>
date Mon, 07 Mar 2016 19:43:02 +0100
parents 8a5b178ff28b
children 116a55865364
files frontends/src/jp/cmd_blog.py
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_blog.py	Mon Mar 07 16:20:41 2016 +0100
+++ b/frontends/src/jp/cmd_blog.py	Mon Mar 07 19:43:02 2016 +0100
@@ -445,16 +445,23 @@
 
             def add_watch():
                 i.add_watch(self.content_file_path, mask=inotify.constants.IN_CLOSE_WRITE |
-                                                         inotify.constants.IN_DELETE_SELF)
+                                                         inotify.constants.IN_DELETE_SELF |
+                                                         inotify.constants.IN_MOVE_SELF)
             add_watch()
 
             try:
                 for event in i.event_gen():
                     if event is not None:
                         self.disp(u"Content updated", 1)
-                        if "IN_DELETE_SELF" in event[1]:
-                            self.disp(u"IN_DELETE_SELF event catched, changing the watch", 2)
-                            add_watch()
+                        if {"IN_DELETE_SELF", "IN_MOVE_SELF"}.intersection(event[1]):
+                            self.disp(u"{} event catched, changing the watch".format(", ".join(event[1])), 2)
+                            try:
+                                add_watch()
+                            except InotifyError:
+                                # if the new file is not here yet we can have an error
+                                # as a workaround, we do a little rest
+                                time.sleep(1)
+                                add_watch()
                         self.updateContent()
                         update_cb()
             except InotifyError: