2021-03-12 22:53:02 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
from datetime import datetime
|
|
|
|
|
2021-03-15 18:25:53 +01:00
|
|
|
from cpl.console.console import Console
|
|
|
|
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
2021-03-12 22:53:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LiveServerThread(threading.Thread):
|
|
|
|
|
|
|
|
def __init__(self, path: str):
|
2021-03-14 16:01:15 +01:00
|
|
|
"""
|
|
|
|
Thread to start the CPL project for the live development server
|
|
|
|
:param path:
|
|
|
|
"""
|
2021-03-12 22:53:02 +01:00
|
|
|
threading.Thread.__init__(self)
|
|
|
|
|
|
|
|
self._path = path
|
|
|
|
self._main = ''
|
|
|
|
self._command = []
|
|
|
|
|
|
|
|
@property
|
|
|
|
def command(self) -> list[str]:
|
|
|
|
return self._command
|
|
|
|
|
|
|
|
@property
|
|
|
|
def main(self) -> str:
|
|
|
|
return self._main
|
|
|
|
|
|
|
|
def run(self):
|
2021-03-14 16:01:15 +01:00
|
|
|
"""
|
|
|
|
Starts the CPL project
|
|
|
|
:return:
|
|
|
|
"""
|
2021-03-12 22:53:02 +01:00
|
|
|
self._main = os.path.join(self._path, 'main.py')
|
|
|
|
if not os.path.isfile(self._main):
|
2021-03-13 11:05:17 +01:00
|
|
|
Console.error('Entry point main.py not found')
|
2021-03-12 22:53:02 +01:00
|
|
|
return
|
|
|
|
|
2021-03-15 18:25:53 +01:00
|
|
|
Console.set_foreground_color(ForegroundColorEnum.green)
|
2021-03-12 22:53:02 +01:00
|
|
|
Console.write_line('Read successfully')
|
2021-03-15 18:25:53 +01:00
|
|
|
Console.set_foreground_color(ForegroundColorEnum.cyan)
|
2021-03-12 22:53:02 +01:00
|
|
|
now = datetime.now()
|
|
|
|
Console.write_line(f'Started at {now.strftime("%Y-%m-%d %H:%M:%S")}\n\n')
|
2021-03-15 18:25:53 +01:00
|
|
|
Console.set_foreground_color(ForegroundColorEnum.default)
|
2021-03-12 22:53:02 +01:00
|
|
|
|
|
|
|
self._command = [sys.executable, self._main, ''.join(sys.argv[2:])]
|
|
|
|
subprocess.run(self._command)
|