linux-tools/modules/teamspeak/__init__.py

44 lines
1.5 KiB
Python
Raw Normal View History

import re
import subprocess
import time
from os import path
2020-08-02 13:58:47 +02:00
from print_helpers import print_bold
def start():
"""Starts a Teamspeak Server with docker-compose"""
show_creds = False if path.exists(path.join(path.dirname(__file__), "ts3_data")) else True
subprocess.run("docker-compose up -d", shell=True, cwd=path.dirname(__file__))
if show_creds:
logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode("UTF-8")
while re.search(r"token", logs) is None:
time.sleep(2)
2020-08-02 13:58:47 +02:00
logs = subprocess.check_output("docker-compose logs", shell=True, cwd=path.dirname(__file__)).decode(
"UTF-8")
print_bold("Server Query Admin Account: " + re.search(r"loginname=.*", logs).group(0))
print_bold("Server Admin Token: " + re.search(r"token=(.*)", logs).group(1))
def stop():
"""Stops the Teamspeak Server with docker-compose"""
subprocess.run("docker-compose down -v", shell=True, cwd=path.dirname(__file__))
def pack_data(name="ts3_data.tar.gz"):
"""Pack all user data of the server started with this script as tar file"""
subprocess.run(f"tar -zcvf {name} ts3_data", shell=True, cwd=path.dirname(__file__))
def show_logs():
"""show the logs of the running Teamspeak server"""
subprocess.run("docker-compose logs", shell=True, cwd=path.dirname(__file__))
functions = {
"start": start,
"stop": stop,
"pack": pack_data,
"logs": show_logs
}