Mercurial > libervia-backend
comparison frontends/src/jp/cmd_blog.py @ 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 | 7b9cdde29d8b |
children | 116a55865364 |
comparison
equal
deleted
inserted
replaced
1892:8a5b178ff28b | 1893:4f252b72b193 |
---|---|
443 open_cb() | 443 open_cb() |
444 i = inotify.adapters.Inotify(block_duration_s=60) # no need for 1 s duraction, inotify drive actions here | 444 i = inotify.adapters.Inotify(block_duration_s=60) # no need for 1 s duraction, inotify drive actions here |
445 | 445 |
446 def add_watch(): | 446 def add_watch(): |
447 i.add_watch(self.content_file_path, mask=inotify.constants.IN_CLOSE_WRITE | | 447 i.add_watch(self.content_file_path, mask=inotify.constants.IN_CLOSE_WRITE | |
448 inotify.constants.IN_DELETE_SELF) | 448 inotify.constants.IN_DELETE_SELF | |
449 inotify.constants.IN_MOVE_SELF) | |
449 add_watch() | 450 add_watch() |
450 | 451 |
451 try: | 452 try: |
452 for event in i.event_gen(): | 453 for event in i.event_gen(): |
453 if event is not None: | 454 if event is not None: |
454 self.disp(u"Content updated", 1) | 455 self.disp(u"Content updated", 1) |
455 if "IN_DELETE_SELF" in event[1]: | 456 if {"IN_DELETE_SELF", "IN_MOVE_SELF"}.intersection(event[1]): |
456 self.disp(u"IN_DELETE_SELF event catched, changing the watch", 2) | 457 self.disp(u"{} event catched, changing the watch".format(", ".join(event[1])), 2) |
457 add_watch() | 458 try: |
459 add_watch() | |
460 except InotifyError: | |
461 # if the new file is not here yet we can have an error | |
462 # as a workaround, we do a little rest | |
463 time.sleep(1) | |
464 add_watch() | |
458 self.updateContent() | 465 self.updateContent() |
459 update_cb() | 466 update_cb() |
460 except InotifyError: | 467 except InotifyError: |
461 self.disp(u"Can't catch inotify events, as the file been deleted?", error=True) | 468 self.disp(u"Can't catch inotify events, as the file been deleted?", error=True) |
462 finally: | 469 finally: |