mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-26 02:01:32 +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 glob import glob
|
||||
from fnmatch import fnmatchcase
|
||||
from collections import Iterable
|
||||
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.components.directory_monitor import DirectoryMonitor
|
||||
@ -10,10 +12,19 @@ log = logging.getLogger(__name__)
|
||||
|
||||
class FileManager:
|
||||
def __init__(self, working_directory, selected_file=None, exclude=None):
|
||||
self.exclude = exclude if exclude is not None else []
|
||||
self._workdir = None
|
||||
self.workdir = working_directory
|
||||
self.filename = selected_file or self.files[0]
|
||||
self._exclude, self.exclude = None, exclude
|
||||
self._workdir, self.workdir = None, working_directory
|
||||
self._filename, self.filename = None, 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
|
||||
def workdir(self):
|
||||
@ -25,16 +36,21 @@ class FileManager:
|
||||
raise EnvironmentError('"{}" is not a directory!'.format(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:
|
||||
raise EnvironmentError('No such file in workdir!')
|
||||
self.filename = filename
|
||||
self._filename = filename
|
||||
|
||||
@property
|
||||
def files(self):
|
||||
return [self._relpath(file) for file in glob(join(self._workdir, '**/*'), recursive=True)
|
||||
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
|
||||
def file_contents(self):
|
||||
@ -61,7 +77,8 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
self.commands = {'read': self.read,
|
||||
'write': self.write,
|
||||
'select': self.select,
|
||||
'selectdir': self.select_dir}
|
||||
'selectdir': self.select_dir,
|
||||
'exclude': self.exclude}
|
||||
|
||||
self._monitor = None
|
||||
self.reload_monitor()
|
||||
@ -92,7 +109,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
return 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']))
|
||||
return data
|
||||
|
||||
@ -101,7 +118,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
self.filemanager.workdir = data['directory']
|
||||
self.reload_monitor()
|
||||
try:
|
||||
self.filemanager.select_file(self.filemanager.files[0])
|
||||
self.filemanager.filename = self.filemanager.files[0]
|
||||
self.read(data)
|
||||
except IndexError:
|
||||
data['content'] = 'No files in this directory :('
|
||||
@ -109,6 +126,11 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
log.error('Failed to select directory "{}"'.format(data['directory']))
|
||||
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):
|
||||
data['filename'] = self.filemanager.filename
|
||||
data['files'] = self.filemanager.files
|
||||
|
@ -1,12 +1,9 @@
|
||||
import zmq
|
||||
from zmq.eventloop import ioloop
|
||||
from zmq.eventloop.zmqstream import ZMQStream
|
||||
|
||||
from tfw.config import tfwenv
|
||||
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
||||
|
||||
ioloop.install()
|
||||
|
||||
|
||||
class ControllerConnector(ZMQConnectorBase):
|
||||
def __init__(self, zmq_context=None):
|
||||
|
@ -1,12 +1,9 @@
|
||||
import zmq
|
||||
from zmq.eventloop import ioloop
|
||||
|
||||
from tfw.config import tfwenv
|
||||
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
||||
from tfw.networking.serialization import serialize_all, deserialize_all
|
||||
|
||||
ioloop.install()
|
||||
|
||||
|
||||
class SolvableConnector(ZMQConnectorBase):
|
||||
def __init__(self, zmq_context=None):
|
||||
|
@ -1,5 +1,5 @@
|
||||
tornado==4.5.3
|
||||
pyzmq==16.0.4
|
||||
tornado==5.0
|
||||
pyzmq==17.0.0
|
||||
transitions==0.6.4
|
||||
terminado==0.8.1
|
||||
watchdog==0.8.3
|
||||
|
@ -40,7 +40,7 @@ toggle_next.button_state = False
|
||||
|
||||
|
||||
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.historymonitor.subscribe_callback(cenator)
|
||||
terminado.historymonitor.subscribe_callback(selectdir)
|
||||
|
Loading…
Reference in New Issue
Block a user