Implement inotify event ignoration logic

This commit is contained in:
Kristóf Tóth 2018-03-07 09:17:29 +01:00
parent 1165fa4ec9
commit 3cf404ee9a
2 changed files with 16 additions and 3 deletions

View File

@ -13,6 +13,7 @@ class WebideReloadEventHandler(FileSystemEventHandler):
super().__init__()
self.uplink = ServerUplinkConnector()
self._paused = False
self.ignore = 0
def pause(self):
self._paused = True
@ -23,6 +24,9 @@ class WebideReloadEventHandler(FileSystemEventHandler):
@RateLimiter(rate_per_second=5)
def on_modified(self, event):
if self._paused: return
if self.ignore > 0:
self.ignore = self.ignore - 1
return
log.debug(event)
key = 'webide'
self.uplink.send(key, {'data': {'command': 'reload'}})
@ -42,6 +46,15 @@ class DirectoryMonitor:
self.observer.stop()
self.observer.join()
@property
def ignore(self):
return self.eventhandler.ignore
@ignore.setter
def ignore(self, value):
if value >= 0: self.ignore = value
else: self.ignore = 0
@property
def pauser(self):
return DirectoryMonitor.Pauser(self)

View File

@ -68,9 +68,9 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
return data
def write(self, data):
with self.monitor.pauser:
try: self.filemanager.file_contents = data['content']
except Exception: log.exception('Error writing file!')
self.monitor.eventhandler.ignore = 1
try: self.filemanager.file_contents = data['content']
except Exception: log.exception('Error writing file!')
del data['content']
return data