юниттесты, пока не рабочие
This commit is contained in:
60
hlna.py
60
hlna.py
@ -16,7 +16,6 @@ home_dir = Path.home()
|
|||||||
dir_server = f"{home_dir}/ARK_Servers/"
|
dir_server = f"{home_dir}/ARK_Servers/"
|
||||||
config_hlna = f"{home_dir}/.config/hlna/"
|
config_hlna = f"{home_dir}/.config/hlna/"
|
||||||
|
|
||||||
"Убрать"
|
|
||||||
mods_id = ""
|
mods_id = ""
|
||||||
listen_server = True
|
listen_server = True
|
||||||
|
|
||||||
@ -39,7 +38,6 @@ def find_file(path):
|
|||||||
|
|
||||||
|
|
||||||
list_config = find_file(config_hlna)
|
list_config = find_file(config_hlna)
|
||||||
|
|
||||||
delist_config = find_file(config_hlna+"deactivated")
|
delist_config = find_file(config_hlna+"deactivated")
|
||||||
|
|
||||||
|
|
||||||
@ -49,8 +47,6 @@ def print_line(text):
|
|||||||
print(f"{colorama.Fore.GREEN} + {text}")
|
print(f"{colorama.Fore.GREEN} + {text}")
|
||||||
print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL)
|
print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL)
|
||||||
|
|
||||||
print_line(f"list_config=, {list_config}")
|
|
||||||
|
|
||||||
|
|
||||||
def create_dir(directory):
|
def create_dir(directory):
|
||||||
"""Проверка и создание директории"""
|
"""Проверка и создание директории"""
|
||||||
@ -78,14 +74,15 @@ create_dir(config_hlna)
|
|||||||
|
|
||||||
|
|
||||||
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
||||||
def config(name_server=list_config):
|
def config(list_config=list_config):
|
||||||
port_s = []
|
|
||||||
query_p = []
|
|
||||||
id_srv = {}
|
|
||||||
data = {}
|
data = {}
|
||||||
cluster_dir_override = ""
|
id_srv = {}
|
||||||
cluster_id = ""
|
port_s = []
|
||||||
rcon_p = []
|
rcon_p = []
|
||||||
|
query_p = []
|
||||||
|
|
||||||
|
cluster_id = ""
|
||||||
|
cluster_dir_override = ""
|
||||||
|
|
||||||
count_cluster = check_int("""Укажите требуется ли кластер?
|
count_cluster = check_int("""Укажите требуется ли кластер?
|
||||||
1. Да
|
1. Да
|
||||||
@ -100,7 +97,7 @@ def config(name_server=list_config):
|
|||||||
else:
|
else:
|
||||||
cluster_server = False
|
cluster_server = False
|
||||||
|
|
||||||
if name_server != []:
|
if list_config:
|
||||||
print("Уже установленные карты: ")
|
print("Уже установленные карты: ")
|
||||||
for i in name_server:
|
for i in name_server:
|
||||||
data = read_yaml(i)
|
data = read_yaml(i)
|
||||||
@ -135,12 +132,13 @@ def config(name_server=list_config):
|
|||||||
if 0 < amount_map <= 12:
|
if 0 < amount_map <= 12:
|
||||||
break
|
break
|
||||||
|
|
||||||
if name_server != []:
|
if list_config:
|
||||||
for i in name_server:
|
for i in list_config:
|
||||||
data = read_yaml(i)
|
data = read_yaml(i)
|
||||||
port_s.append(data['Port'])
|
port_s.append(data['Port'])
|
||||||
query_p.append(data['QueryPort'])
|
|
||||||
rcon_p.append(data['RCONPort'])
|
rcon_p.append(data['RCONPort'])
|
||||||
|
query_p.append(data['QueryPort'])
|
||||||
|
|
||||||
|
|
||||||
if amount_map == 1:
|
if amount_map == 1:
|
||||||
map_s = "TheIsland"
|
map_s = "TheIsland"
|
||||||
@ -170,15 +168,41 @@ def config(name_server=list_config):
|
|||||||
# Если вдруг каким-то боком проверка не отработает и не будет нужной цифры
|
# Если вдруг каким-то боком проверка не отработает и не будет нужной цифры
|
||||||
map_s = 'TheIsland'
|
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"))
|
name_server.append(input("Укажите название Сервера: \n"))
|
||||||
if name_server[-1] == '':
|
if name_server[-1] == '':
|
||||||
if map_s in name_server:
|
if map_s in name_server:
|
||||||
name_server.pop(); name_server.append(map_s + str(name_server.count(map_s)))
|
name_server.pop(); name_server.append(map_s + str(name_server.count(map_s)))
|
||||||
else:
|
else:
|
||||||
name_server.pop(); name_server.append(map_s) # если enter, то ставим последним элементом карту
|
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:
|
while True:
|
||||||
port_server = check_int("Укажите порт Сервера <7777>: \n")
|
port_server = check_int("Укажите порт Сервера <7777>: \n")
|
||||||
if port_server == 0:
|
if port_server == 0:
|
||||||
@ -202,7 +226,7 @@ def config(name_server=list_config):
|
|||||||
print("Этот порт уже занят")
|
print("Этот порт уже занят")
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
'''
|
||||||
rcon_enabled = True
|
rcon_enabled = True
|
||||||
if rcon_p == []:
|
if rcon_p == []:
|
||||||
rcon_port = 27020
|
rcon_port = 27020
|
||||||
|
50
pytest.py
Normal file
50
pytest.py
Normal file
@ -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)
|
||||||
|
|
Reference in New Issue
Block a user