# HG changeset patch # User Goffi # Date 1457202250 -3600 # Node ID f3db27508b31bf0a3e470f3d981b20a1d05d7bd0 # Parent edd8dc8df1b922ae13cff2b63c50446cc339e785 jp (blog/preview): inotify improvments: - InotifyError are catched (can happen if file is deleted during preview for instance) - handle IN_DELETE_SELF event which happen when editor write content in a new file and switch to it (tested with vim) diff -r edd8dc8df1b9 -r f3db27508b31 frontends/src/jp/cmd_blog.py --- a/frontends/src/jp/cmd_blog.py Sat Mar 05 19:21:35 2016 +0100 +++ b/frontends/src/jp/cmd_blog.py Sat Mar 05 19:24:10 2016 +0100 @@ -374,6 +374,7 @@ try: import inotify.adapters import inotify.constants + from inotify.calls import InotifyError except ImportError: if self.args.inotify == 'auto': inotify = None @@ -429,18 +430,29 @@ else: open_cb() i = inotify.adapters.Inotify(block_duration_s=60) # no need for 1 s duraction, inotify drive actions here - # XXX: we only check IN_CLOSE_WRITE, but that may need to be changed depending on editor - # experience will tell the appropriate values - i.add_watch(self.current_file_path, mask=inotify.constants.IN_CLOSE_WRITE) + + def add_watch(): + i.add_watch(self.content_file_path, mask=inotify.constants.IN_CLOSE_WRITE | + inotify.constants.IN_DELETE_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() self.updateContent() update_cb() + except InotifyError: + self.disp(u"Can't catch inotify events, as the file been deleted?", error=True) finally: os.unlink(self.preview_file_path) - i.remove_watch(self.current_file_path) + try: + i.remove_watch(self.content_file_path) + except InotifyError: + pass class Import(base.CommandAnswering):