mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 21:31:31 +00:00
Merge pull request #16 from avatao-content/pmgeh_monitorpasuse_fix
Fix monitor pausing rendered useless by pmgeh, general webide optimization
This commit is contained in:
commit
a785a1a76f
@ -1,3 +1,5 @@
|
|||||||
|
from functools import wraps
|
||||||
|
|
||||||
from tfw.event_handler_base import TriggerlessEventHandler
|
from tfw.event_handler_base import TriggerlessEventHandler
|
||||||
from tfw.components.mixins import SupervisorMixin
|
from tfw.components.mixins import SupervisorMixin
|
||||||
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
||||||
@ -16,12 +18,23 @@ class ProcessManager(SupervisorMixin):
|
|||||||
|
|
||||||
|
|
||||||
class ProcessManagingEventHandler(TriggerlessEventHandler):
|
class ProcessManagingEventHandler(TriggerlessEventHandler):
|
||||||
def __init__(self, key):
|
def __init__(self, key, dirmonitor=None):
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
self.key = key
|
self.key = key
|
||||||
|
self.monitor = dirmonitor
|
||||||
self.processmanager = ProcessManager()
|
self.processmanager = ProcessManager()
|
||||||
self.uplink = ServerUplinkConnector()
|
self.uplink = ServerUplinkConnector()
|
||||||
|
|
||||||
|
def _with_monitor_paused(fun):
|
||||||
|
@wraps(fun)
|
||||||
|
def wrapper(self, *args, **kwargs):
|
||||||
|
if self.monitor:
|
||||||
|
with self.monitor.pauser:
|
||||||
|
return fun(self, *args, **kwargs)
|
||||||
|
return fun(self, *args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
@_with_monitor_paused
|
||||||
def handle_event(self, key, data_json):
|
def handle_event(self, key, data_json):
|
||||||
data = data_json['data']
|
data = data_json['data']
|
||||||
self.processmanager(data['command'], data['process_name'])
|
self.processmanager(data['command'], data['process_name'])
|
||||||
|
@ -53,8 +53,12 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
'select': self.select
|
'select': self.select
|
||||||
}
|
}
|
||||||
|
|
||||||
self.monitor = DirectoryMonitor(directory)
|
self._monitor = DirectoryMonitor(directory)
|
||||||
self.monitor.watch() # This runs on a separate thread
|
self._monitor.watch() # This runs on a separate thread
|
||||||
|
|
||||||
|
@property
|
||||||
|
def monitor(self):
|
||||||
|
return self._monitor
|
||||||
|
|
||||||
def read(self, data):
|
def read(self, data):
|
||||||
try: data['content'] = self.filemanager.file_contents
|
try: data['content'] = self.filemanager.file_contents
|
||||||
@ -67,6 +71,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
with self.monitor.pauser:
|
with self.monitor.pauser:
|
||||||
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']
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def select(self, data):
|
def select(self, data):
|
||||||
|
@ -7,9 +7,11 @@ from tfw.config import tfwenv
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
eventhandlers = {SourceCodeEventHandler('webide', tfwenv.WEBIDE_WD),
|
ide = SourceCodeEventHandler('webide', tfwenv.WEBIDE_WD)
|
||||||
TerminadoEventHandler('terminado', 'terminado'),
|
terminado = TerminadoEventHandler('terminado', 'terminado')
|
||||||
ProcessManagingEventHandler('processmanager')}
|
processmanager = ProcessManagingEventHandler('processmanager', ide.monitor)
|
||||||
|
|
||||||
|
eventhandlers = {ide, terminado, processmanager}
|
||||||
try:
|
try:
|
||||||
IOLoop.instance().start()
|
IOLoop.instance().start()
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user