From fe340c0135b9ba37907ab2739c4be8a9cb6c0211 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 7 Mar 2016 19:43:02 +0100 Subject: [PATCH] jp (blog/preview): change watch for IN_MOVE_SELF event, needed at least for Emacs --- frontends/src/jp/cmd_blog.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontends/src/jp/cmd_blog.py b/frontends/src/jp/cmd_blog.py index 9421ff86..569f7a6f 100644 --- a/frontends/src/jp/cmd_blog.py +++ b/frontends/src/jp/cmd_blog.py @@ -445,16 +445,23 @@ class Preview(base.CommandBase, BlogCommon): 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: