Bugfixes with live development server

This commit is contained in:
2021-03-15 18:25:53 +01:00
parent bdb0548bc8
commit 3e59f01add
36 changed files with 141 additions and 82 deletions

View File

@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.live_server'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.4.1.post1'
__version__ = '2021.4.1.post3'
from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='04', micro='01-1')
version_info = VersionInfo(major='2021', minor='04', micro='01-3')

View File

@@ -28,7 +28,7 @@ class LiveServerService(ServiceABC, FileSystemEventHandler):
self._build_settings = build_settings
self._src_dir = os.path.join(self._runtime.working_directory, self._build_settings.source_path)
self._ls_thread = LiveServerThread(self._src_dir)
self._ls_thread = None
self._observer = None
def _start_observer(self):
@@ -54,10 +54,7 @@ class LiveServerService(ServiceABC, FileSystemEventHandler):
while self._ls_thread.is_alive():
time.sleep(1)
self._ls_thread = LiveServerThread(self._src_dir)
self._ls_thread.start()
self._start_observer()
self._start()
def on_modified(self, event):
"""
@@ -73,14 +70,17 @@ class LiveServerService(ServiceABC, FileSystemEventHandler):
self._observer.stop()
self._restart()
def _start(self):
self._start_observer()
self._ls_thread = LiveServerThread(self._src_dir)
self._ls_thread.start()
self._ls_thread.join()
Console.close()
def start(self):
"""
Starts the CPL live development server
:return:
"""
Console.write_line('** CPL live development server is running **')
self._start_observer()
self._ls_thread.start()
Console.close()
Console.write('\n')
self._start()

View File

@@ -4,7 +4,8 @@ import sys
import threading
from datetime import datetime
from cpl.console import Console
from cpl.console.console import Console
from cpl.console.foreground_color_enum import ForegroundColorEnum
class LiveServerThread(threading.Thread):
@@ -38,9 +39,12 @@ class LiveServerThread(threading.Thread):
Console.error('Entry point main.py not found')
return
Console.set_foreground_color(ForegroundColorEnum.green)
Console.write_line('Read successfully')
Console.set_foreground_color(ForegroundColorEnum.cyan)
now = datetime.now()
Console.write_line(f'Started at {now.strftime("%Y-%m-%d %H:%M:%S")}\n\n')
Console.set_foreground_color(ForegroundColorEnum.default)
self._command = [sys.executable, self._main, ''.join(sys.argv[2:])]
subprocess.run(self._command)