Добавлена функция для создания логов, добавлена проверка директории '/ShooterGame/Binaries/Linux' перед запуском

This commit is contained in:
sitisll 2023-02-17 14:18:52 +03:00
parent 5f9eb980c1
commit d40320beef
2 changed files with 37 additions and 14 deletions

@ -5,7 +5,7 @@ import telebot
from telebot import types from telebot import types
key_api = input("Укажите ключ бота") key_api = input("Укажите ключ бота")
dodo_bot = telebot.Telebot(f"{key_api}", parse_mode=None) dodo_bot = telebot.Telebot(f"{key_api, parse_mode=None)
@bot.message_handler(commans=['start', 'help']) @bot.message_handler(commans=['start', 'help'])

35
dodo.py

@ -1,11 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"Модуль для создания и управления серверами Арк"
import os import os
import traceback
import yaml import yaml
import threading import threading
from pathlib import Path from pathlib import Path
import click import click
import colorama import colorama
import datetime
home_dir = Path.home() home_dir = Path.home()
dir_server = f"{home_dir}/ARK_Servers/" dir_server = f"{home_dir}/ARK_Servers/"
@ -23,6 +27,14 @@ if x>0:
list_config.remove('.directory') list_config.remove('.directory')
def logging(l):
"Записываем логи в файл"
with open(dir_server + "logs", "a") as filelog:
now1 = datetime.datetime.today()
now1 = now1.strftime("%d-%m %H:%M | ")
filelog.write(now1 + l)
def print_line(text): def print_line(text):
"Добавление тире вокруг текста, покраска" "Добавление тире вокруг текста, покраска"
print(colorama.Fore.YELLOW + "-"*30) print(colorama.Fore.YELLOW + "-"*30)
@ -32,22 +44,32 @@ def print_line(text):
def create_dir(directory): def create_dir(directory):
"Проверка и создание директории" "Проверка и создание директории"
try:
if not os.path.exists(directory): if not os.path.exists(directory):
os.mkdir(directory) os.mkdir(directory)
except:
logging(traceback.format_exc())
logging(f"Не удалось создать директорию - {directory}")
def check_int(number=""): def check_int(number=""):
"Проверка на ввод числа" "Проверка на ввод числа"
x=""
while True: while True:
try: try:
x = input(number) x = input(number)
if x == "": if bool(x) == True:
return 0
x = x.replace(' ', '') x = x.replace(' ', '')
x = x.replace(',', '') x = x.replace(',', '')
x = int(x) x = int(x)
return x return x
else:
return 0
except ValueError: except ValueError:
logging(traceback.format_exc())
logging(f"Не прошла проверка на ввод числа, func(check_int) ввод пользователя {x}")
print("Введите число") print("Введите число")
@ -189,7 +211,6 @@ def yaml_create(cluster_server, map_server, name_server, port_server, query_port
} }
] ]
print(cluster_id)
if cluster_id != None: if cluster_id != None:
settings_dodo[0]['clusterid'] = cluster_id settings_dodo[0]['clusterid'] = cluster_id
settings_dodo[0]['clusterdir'] = cluster_dir_override settings_dodo[0]['clusterdir'] = cluster_dir_override
@ -235,6 +256,8 @@ def start(map_server=list_config):
if len(map_list) <= len(map_server) and check == True: if len(map_list) <= len(map_server) and check == True:
break break
except: except:
logging(traceback.format_exc())
logging(f"Ошибка при выборе карт для запуска, пользователь ввел - {map_list}")
print("Неправильный ввод") print("Неправильный ввод")
@ -251,9 +274,11 @@ def start(map_server=list_config):
def start(i): def start(i):
os.chdir(dir_server + i + "/ShooterGame/Binaries/Linux/") os.chdir(dir_server + i + "/ShooterGame/Binaries/Linux/")
os.system(f"./ShooterGameServer {i}?SessionName={name_server}?Port={port_server}?QueryPort={query_port}?MaxPlayers={max_players}?GameModIds={mods_id}?listen={listen_server} -clusterid={cluster_id} -ClusterDirOverride={cluster_dir_ovverride}") os.system(f"./ShooterGameServer {i}?SessionName={name_server}?Port={port_server}?QueryPort={query_port}?MaxPlayers={max_players}?GameModIds={mods_id}?listen={listen_server} -clusterid={cluster_id} -ClusterDirOverride={cluster_dir_ovverride}")
if os.path.exists(dir_server + i + "/ShooterGame/Binaries/Linux/"):
threads = threading.Thread(target=start, args=(i,)) threads = threading.Thread(target=start, args=(i,))
threads.start() threads.start()
else:
print("Сервер не установлен, проверьте, достаточно ли места на диске для установки карты")
def read_yaml(map_server): def read_yaml(map_server):
with open(f"{home_dir}/.config/dodo/{map_server}", "r") as yamlfile: with open(f"{home_dir}/.config/dodo/{map_server}", "r") as yamlfile:
@ -270,8 +295,6 @@ def read_yaml(map_server):
cluster_server = data['Cluster'] cluster_server = data['Cluster']
cluster_id = data['clusterid'] cluster_id = data['clusterid']
cluster_dir_ovverride = data['clusterdir'] cluster_dir_ovverride = data['clusterdir']
print(cluster_id)
print(cluster_dir_ovverride)
return cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride return cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride