mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:11:32 +00:00
Implement inotify event ignoration logic
This commit is contained in:
parent
1165fa4ec9
commit
3cf404ee9a
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user