Allow port to be changed using MTT_PORT environment variable.

This commit is contained in:
2022-06-11 18:10:23 -04:00
parent d92761ed70
commit e40e190e1e
8 changed files with 597 additions and 30 deletions

View File

@@ -2,6 +2,8 @@
from asyncio import create_subprocess_exec, get_event_loop, sleep
from pathlib import Path
from socket import socket
class Server:
"""Setup a single server."""
@@ -36,13 +38,14 @@ class Server:
@port.setter
def port(self, num):
"""Set the port for the server."""
self.env["MTT_PORT"] = num
self.env["MTT_PORT"] = str(num)
async def __start(self):
"""async start of the server."""
print(self.env)
self.process = await create_subprocess_exec(
Path.cwd().joinpath("target", "release", "morethantext_web")
)
Path.cwd().joinpath("target", "release", "morethantext_web"), env=self.env
)
await sleep(1)
async def __stop(self):
@@ -62,3 +65,10 @@ class Server:
def destroy(self):
"""Removes the server instance."""
self.stop()
def set_safe_port(self):
"""Set the server port to something not being used."""
sock = socket()
sock.bind((self.address, 0))
self.port = sock.getsockname()[1]
sock.close()