From d7174a7b57aebe590a34a59c952e66823f0194bf Mon Sep 17 00:00:00 2001 From: sitisll Date: Mon, 27 Feb 2023 18:02:26 +0300 Subject: [PATCH] =?UTF-8?q?=D1=8E=D0=BD=D0=B8=D1=82=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B,=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hlna.py | 60 ++++++++++++++++++++++++++++++++++++++----------------- pytest.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 pytest.py diff --git a/hlna.py b/hlna.py index 7580188..e651c56 100755 --- a/hlna.py +++ b/hlna.py @@ -16,7 +16,6 @@ home_dir = Path.home() dir_server = f"{home_dir}/ARK_Servers/" config_hlna = f"{home_dir}/.config/hlna/" -"Убрать" mods_id = "" listen_server = True @@ -39,7 +38,6 @@ def find_file(path): list_config = find_file(config_hlna) - delist_config = find_file(config_hlna+"deactivated") @@ -49,8 +47,6 @@ def print_line(text): print(f"{colorama.Fore.GREEN} + {text}") print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL) -print_line(f"list_config=, {list_config}") - def create_dir(directory): """Проверка и создание директории""" @@ -78,14 +74,15 @@ create_dir(config_hlna) @hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов') -def config(name_server=list_config): - port_s = [] - query_p = [] - id_srv = {} +def config(list_config=list_config): data = {} - cluster_dir_override = "" - cluster_id = "" + id_srv = {} + port_s = [] rcon_p = [] + query_p = [] + + cluster_id = "" + cluster_dir_override = "" count_cluster = check_int("""Укажите требуется ли кластер? 1. Да @@ -100,7 +97,7 @@ def config(name_server=list_config): else: cluster_server = False - if name_server != []: + if list_config: print("Уже установленные карты: ") for i in name_server: data = read_yaml(i) @@ -135,12 +132,13 @@ def config(name_server=list_config): if 0 < amount_map <= 12: break - if name_server != []: - for i in name_server: + if list_config: + for i in list_config: data = read_yaml(i) port_s.append(data['Port']) - query_p.append(data['QueryPort']) rcon_p.append(data['RCONPort']) + query_p.append(data['QueryPort']) + if amount_map == 1: map_s = "TheIsland" @@ -170,15 +168,41 @@ def config(name_server=list_config): # Если вдруг каким-то боком проверка не отработает и не будет нужной цифры map_s = 'TheIsland' - if name_server != []: - data = read_yaml(name_server[-1]) + + def ports(ports_arr): + while True: + port = check_int("") + if port == 0: + if not ports_arr: + print("Значение по умолчаню") + else: + port = max(ports_arr + 2) + if port in ports_arr: + print("Порт уже занят") + else: + return port + + + + if list_config: + data = read_yaml(list_config[-1]) name_server.append(input("Укажите название Сервера: \n")) if name_server[-1] == '': if map_s in name_server: name_server.pop(); name_server.append(map_s + str(name_server.count(map_s))) else: name_server.pop(); name_server.append(map_s) # если enter, то ставим последним элементом карту - + + port_server = ports(port_s) + query_port = ports(query_p) + + if port_server == 0: + port_server = 7777 + if query_port == 0: + query_port = 27015 + print("Порт Сервера=",port_server) + print("Query Port=", query_port) + ''' while True: port_server = check_int("Укажите порт Сервера <7777>: \n") if port_server == 0: @@ -202,7 +226,7 @@ def config(name_server=list_config): print("Этот порт уже занят") else: break - + ''' rcon_enabled = True if rcon_p == []: rcon_port = 27020 diff --git a/pytest.py b/pytest.py new file mode 100644 index 0000000..72e2464 --- /dev/null +++ b/pytest.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +from colorama import Fore, Style +import os +import unittest +import time +from threading import Thread + +import hlna + +"---------------import подменяем через unittest.mock -----------------------" + +"---------------------------------------------------------------------------" + +def config(): + x = os.system("./hlna.py config < 1") + print("x=", x) +def servers(): + x = os.system("./hlna.py servers") + if x == 0: + print("Servers - "+Fore.GREEN + "OK" + Style.RESET_ALL) + else: + print(Fore.RED + "Servers Fail" + Style.RESET_ALL) +def delete(): + print("Delete - " + Fore.RED + "False" + Style.RESET_ALL) +class TestHlna(unittest.TestCase): + def test_config(self): + pass + # self.assert _input(hlna.config(input(1), 11)) + def test_servers(self): + pass + def test_enablemap(self): + passs + def test_start(self): + pass + def test_delete(self): + pass + def test_rcon(self): + pass + + +if __name__ == "__main__": + #unittest.main() + servers() + config() + delete() + + +#print(f"{Fore.GREEN} + {text}") +#print(Fore.YELLOW + "-"*30 + Style.RESET_ALL) +