mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:51:31 +00:00
Merge pull request #22 from avatao-content/webide_enhancements
Webide enhancements
This commit is contained in:
commit
38f61b9daa
@ -1,5 +1,7 @@
|
|||||||
from os.path import isfile, join, relpath, exists, isdir
|
from os.path import isfile, join, relpath, exists, isdir
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
from fnmatch import fnmatchcase
|
||||||
|
from collections import Iterable
|
||||||
|
|
||||||
from tfw.event_handler_base import TriggerlessEventHandler
|
from tfw.event_handler_base import TriggerlessEventHandler
|
||||||
from tfw.components.directory_monitor import DirectoryMonitor
|
from tfw.components.directory_monitor import DirectoryMonitor
|
||||||
@ -10,10 +12,19 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class FileManager:
|
class FileManager:
|
||||||
def __init__(self, working_directory, selected_file=None, exclude=None):
|
def __init__(self, working_directory, selected_file=None, exclude=None):
|
||||||
self.exclude = exclude if exclude is not None else []
|
self._exclude, self.exclude = None, exclude
|
||||||
self._workdir = None
|
self._workdir, self.workdir = None, working_directory
|
||||||
self.workdir = working_directory
|
self._filename, self.filename = None, selected_file or self.files[0]
|
||||||
self.filename = selected_file or self.files[0]
|
|
||||||
|
@property
|
||||||
|
def exclude(self):
|
||||||
|
return self._exclude
|
||||||
|
|
||||||
|
@exclude.setter
|
||||||
|
def exclude(self, exclude):
|
||||||
|
if exclude is None: return
|
||||||
|
if not isinstance(exclude, Iterable): raise TypeError('Exclude must be Iterable!')
|
||||||
|
self._exclude = exclude
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def workdir(self):
|
def workdir(self):
|
||||||
@ -25,16 +36,21 @@ class FileManager:
|
|||||||
raise EnvironmentError('"{}" is not a directory!'.format(directory))
|
raise EnvironmentError('"{}" is not a directory!'.format(directory))
|
||||||
self._workdir = directory
|
self._workdir = directory
|
||||||
|
|
||||||
def select_file(self, filename):
|
@property
|
||||||
|
def filename(self):
|
||||||
|
return self._filename
|
||||||
|
|
||||||
|
@filename.setter
|
||||||
|
def filename(self, filename):
|
||||||
if not filename in self.files:
|
if not filename in self.files:
|
||||||
raise EnvironmentError('No such file in workdir!')
|
raise EnvironmentError('No such file in workdir!')
|
||||||
self.filename = filename
|
self._filename = filename
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def files(self):
|
def files(self):
|
||||||
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True)
|
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True)
|
||||||
if isfile(file) and
|
if isfile(file) and
|
||||||
not any(word in file for word in self.exclude)]
|
not any(fnmatchcase(file, blacklisted) for blacklisted in self.exclude)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def file_contents(self):
|
def file_contents(self):
|
||||||
@ -61,7 +77,8 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
self.commands = {'read': self.read,
|
self.commands = {'read': self.read,
|
||||||
'write': self.write,
|
'write': self.write,
|
||||||
'select': self.select,
|
'select': self.select,
|
||||||
'selectdir': self.select_dir}
|
'selectdir': self.select_dir,
|
||||||
|
'exclude': self.exclude}
|
||||||
|
|
||||||
self._monitor = None
|
self._monitor = None
|
||||||
self.reload_monitor()
|
self.reload_monitor()
|
||||||
@ -92,7 +109,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def select(self, data):
|
def select(self, data):
|
||||||
try: self.filemanager.select_file(data['filename'])
|
try: self.filemanager.filename = data['filename']
|
||||||
except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename']))
|
except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename']))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -101,7 +118,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
self.filemanager.workdir = data['directory']
|
self.filemanager.workdir = data['directory']
|
||||||
self.reload_monitor()
|
self.reload_monitor()
|
||||||
try:
|
try:
|
||||||
self.filemanager.select_file(self.filemanager.files[0])
|
self.filemanager.filename = self.filemanager.files[0]
|
||||||
self.read(data)
|
self.read(data)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
data['content'] = 'No files in this directory :('
|
data['content'] = 'No files in this directory :('
|
||||||
@ -109,6 +126,11 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
|||||||
log.error('Failed to select directory "{}"'.format(data['directory']))
|
log.error('Failed to select directory "{}"'.format(data['directory']))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def exclude(self, data):
|
||||||
|
try: self.filemanager.exclude = list(data['exclude'])
|
||||||
|
except TypeError: log.error('Exclude must be Iterable!')
|
||||||
|
return data
|
||||||
|
|
||||||
def attach_fileinfo(self, data):
|
def attach_fileinfo(self, data):
|
||||||
data['filename'] = self.filemanager.filename
|
data['filename'] = self.filemanager.filename
|
||||||
data['files'] = self.filemanager.files
|
data['files'] = self.filemanager.files
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
import zmq
|
import zmq
|
||||||
from zmq.eventloop import ioloop
|
|
||||||
from zmq.eventloop.zmqstream import ZMQStream
|
from zmq.eventloop.zmqstream import ZMQStream
|
||||||
|
|
||||||
from tfw.config import tfwenv
|
from tfw.config import tfwenv
|
||||||
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
||||||
|
|
||||||
ioloop.install()
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerConnector(ZMQConnectorBase):
|
class ControllerConnector(ZMQConnectorBase):
|
||||||
def __init__(self, zmq_context=None):
|
def __init__(self, zmq_context=None):
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
import zmq
|
import zmq
|
||||||
from zmq.eventloop import ioloop
|
|
||||||
|
|
||||||
from tfw.config import tfwenv
|
from tfw.config import tfwenv
|
||||||
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
||||||
from tfw.networking.serialization import serialize_all, deserialize_all
|
from tfw.networking.serialization import serialize_all, deserialize_all
|
||||||
|
|
||||||
ioloop.install()
|
|
||||||
|
|
||||||
|
|
||||||
class SolvableConnector(ZMQConnectorBase):
|
class SolvableConnector(ZMQConnectorBase):
|
||||||
def __init__(self, zmq_context=None):
|
def __init__(self, zmq_context=None):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
tornado==4.5.3
|
tornado==5.0
|
||||||
pyzmq==16.0.4
|
pyzmq==17.0.0
|
||||||
transitions==0.6.4
|
transitions==0.6.4
|
||||||
terminado==0.8.1
|
terminado==0.8.1
|
||||||
watchdog==0.8.3
|
watchdog==0.8.3
|
||||||
|
@ -40,7 +40,7 @@ toggle_next.button_state = False
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['__pycache__'])
|
ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['*.pyc'])
|
||||||
terminado = TerminadoEventHandler(key='shell')
|
terminado = TerminadoEventHandler(key='shell')
|
||||||
terminado.historymonitor.subscribe_callback(cenator)
|
terminado.historymonitor.subscribe_callback(cenator)
|
||||||
terminado.historymonitor.subscribe_callback(selectdir)
|
terminado.historymonitor.subscribe_callback(selectdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user