Fix more bugs and use dotenv library
This commit is contained in:
parent
290ad4e72d
commit
617ffc0b14
|
@ -4,6 +4,10 @@ ENV PYTHONUNBUFFERED=1
|
|||
|
||||
WORKDIR /app/data
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY config.py /app/bin/
|
||||
COPY generate.py /app/bin/
|
||||
|
||||
|
|
|
@ -2,16 +2,6 @@ import os
|
|||
import re
|
||||
|
||||
|
||||
def load_env(filename=".env"):
|
||||
env_vars = {}
|
||||
with open(filename) as f:
|
||||
for line in f:
|
||||
if "=" in line:
|
||||
key, value = line.strip().split("=", 1)
|
||||
env_vars[key] = value
|
||||
return env_vars
|
||||
|
||||
|
||||
def count_servers(env_vars):
|
||||
server_keys = [key for key in env_vars if re.match(r"PORT_\d+", key)]
|
||||
return len(server_keys)
|
||||
|
@ -50,7 +40,6 @@ services:
|
|||
|
||||
|
||||
def generate_mediamtx_files(env_vars, num_servers):
|
||||
# os.makedirs("mediamtx")
|
||||
mediamtx_dir = "mediamtx"
|
||||
if not os.path.exists(mediamtx_dir):
|
||||
os.makedirs(mediamtx_dir)
|
||||
|
@ -69,7 +58,7 @@ def generate_mediamtx_files(env_vars, num_servers):
|
|||
with open(f"mediamtx/mediamtx_{i}.yml", "w") as f:
|
||||
f.write(generated_content)
|
||||
|
||||
existing_files = os.listdir("mediamtx")
|
||||
existing_files = os.listdir(mediamtx_dir)
|
||||
for file in existing_files:
|
||||
if file.startswith("mediamtx_"):
|
||||
file_num = int(file.split("_")[1].split(".")[0])
|
||||
|
@ -84,11 +73,11 @@ def generate_start_bat(num_servers):
|
|||
|
||||
obs_instances = ""
|
||||
for i in range(1, num_servers + 1):
|
||||
obs_instance = f""" # noqa: E501
|
||||
obs_instance = f"""
|
||||
echo Launching OBS instance {i}
|
||||
start /MIN "OBS{i}" /D "C:\\Program Files\\obs-studio\\bin\\64bit" "obs64.exe" --profile "Profile{i}" --collection "Profile{i}" --multi --startstreaming
|
||||
timeout /t 1 >nul
|
||||
"""
|
||||
""" # noqa: E501
|
||||
obs_instances += obs_instance
|
||||
|
||||
bat_content = bat_template.replace("{{OBS_INSTANCES}}", obs_instances)
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
from dotenv import dotenv_values
|
||||
|
||||
from config import (
|
||||
count_servers,
|
||||
generate_docker_compose,
|
||||
generate_mediamtx_files,
|
||||
generate_start_bat,
|
||||
load_env,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
env_vars = load_env(".env")
|
||||
env_vars = dotenv_values(".env")
|
||||
|
||||
num_servers = count_servers(env_vars)
|
||||
|
||||
generate_docker_compose(env_vars, num_servers)
|
||||
|
|
Loading…
Reference in New Issue