mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:01:31 +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__()
|
super().__init__()
|
||||||
self.uplink = ServerUplinkConnector()
|
self.uplink = ServerUplinkConnector()
|
||||||
self._paused = False
|
self._paused = False
|
||||||
|
self.ignore = 0
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
self._paused = True
|
self._paused = True
|
||||||
@ -23,6 +24,9 @@ class WebideReloadEventHandler(FileSystemEventHandler):
|
|||||||
@RateLimiter(rate_per_second=5)
|
@RateLimiter(rate_per_second=5)
|
||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
if self._paused: return
|
if self._paused: return
|
||||||
|
if self.ignore > 0:
|
||||||
|
self.ignore = self.ignore - 1
|
||||||
|
return
|
||||||
log.debug(event)
|
log.debug(event)
|
||||||
key = 'webide'
|
key = 'webide'
|
||||||
self.uplink.send(key, {'data': {'command': 'reload'}})
|
self.uplink.send(key, {'data': {'command': 'reload'}})
|
||||||
@ -42,6 +46,15 @@ class DirectoryMonitor:
|
|||||||
self.observer.stop()
|
self.observer.stop()
|
||||||
self.observer.join()
|
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
|
@property
|
||||||
def pauser(self):
|
def pauser(self):
|
||||||
return DirectoryMonitor.Pauser(self)
|
return DirectoryMonitor.Pauser(self)
|
||||||
|
@ -68,9 +68,9 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
with self.monitor.pauser:
|
self.monitor.eventhandler.ignore = 1
|
||||||
try: self.filemanager.file_contents = data['content']
|
try: self.filemanager.file_contents = data['content']
|
||||||
except Exception: log.exception('Error writing file!')
|
except Exception: log.exception('Error writing file!')
|
||||||
del data['content']
|
del data['content']
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user