Added comments

This commit is contained in:
2021-03-14 16:01:15 +01:00
parent d5d8c3f413
commit cbf333564c
15 changed files with 308 additions and 24 deletions

View File

@@ -16,6 +16,11 @@ from cpl_cli.live_server.live_server_thread import LiveServerThread
class LiveServerService(ServiceABC, FileSystemEventHandler):
def __init__(self, runtime: ApplicationRuntimeABC, build_settings: BuildSettings):
"""
Service for the live development server
:param runtime:
:param build_settings:
"""
ServiceABC.__init__(self)
FileSystemEventHandler.__init__(self)
@@ -27,11 +32,19 @@ class LiveServerService(ServiceABC, FileSystemEventHandler):
self._observer = None
def _start_observer(self):
"""
Starts the file changes observer
:return:
"""
self._observer = Observer()
self._observer.schedule(self, path=self._src_dir, recursive=True)
self._observer.start()
def _restart(self):
"""
Restarts the CPL project
:return:
"""
for proc in psutil.process_iter():
with suppress(Exception):
if proc.cmdline() == self._ls_thread.command:
@@ -47,6 +60,11 @@ class LiveServerService(ServiceABC, FileSystemEventHandler):
self._start_observer()
def on_modified(self, event):
"""
Triggers when source file is modified
:param event:
:return:
"""
if event.is_directory:
return None
@@ -56,6 +74,10 @@ class LiveServerService(ServiceABC, FileSystemEventHandler):
self._restart()
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()

View File

@@ -10,6 +10,10 @@ from cpl.console import Console
class LiveServerThread(threading.Thread):
def __init__(self, path: str):
"""
Thread to start the CPL project for the live development server
:param path:
"""
threading.Thread.__init__(self)
self._path = path
@@ -25,6 +29,10 @@ class LiveServerThread(threading.Thread):
return self._main
def run(self):
"""
Starts the CPL project
:return:
"""
self._main = os.path.join(self._path, 'main.py')
if not os.path.isfile(self._main):
Console.error('Entry point main.py not found')