jp (blog/preview): change watch for IN_MOVE_SELF event, needed at least for Emacs
This commit is contained in:
parent
a6f9cd5bfb
commit
fe340c0135
1 changed files with 11 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue