diff --git a/frontends/src/jp/cmd_blog.py b/frontends/src/jp/cmd_blog.py index 306d8b27..22cea448 100644 --- a/frontends/src/jp/cmd_blog.py +++ b/frontends/src/jp/cmd_blog.py @@ -374,6 +374,7 @@ class Preview(base.CommandBase, BlogCommon): 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 @@ class Preview(base.CommandBase, BlogCommon): 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):