Поправил создание уникальных конфигов

This commit is contained in:
sitisll 2023-02-28 12:02:00 +03:00
parent 8589fb0964
commit 03da3ffa1c
2 changed files with 42 additions and 17 deletions

42
hlna.py

@ -99,10 +99,10 @@ def config(list_config=list_config):
if list_config:
print("Уже установленные карты: ")
for i in name_server:
for i in list_config:
data = read_yaml(i)
print(f"{i} : {data['map']}")
id_srv[data['SessionName']] = data['id_server']
# id_srv[data['SessionName']] = data['id_server']
count_maps = check_int("Укажите количество карт: \n")
if count_maps == 0: # 0 возвращает check_int когда, ничего не было введено
@ -112,7 +112,7 @@ def config(list_config=list_config):
while True:
"Проверка на выбор карты из списка"
os.system("clear")
#os.system("clear")
amount_map = check_int("""Выберите карту из списка указав номер
1. The Island
2. The Center
@ -174,22 +174,38 @@ def config(list_config=list_config):
if not ports_arr:
print("Значение по умолчаню")
else:
port = max(ports_arr + 2)
port = max(ports_arr) + 2
if port in ports_arr:
print("Порт уже занят")
else:
return port
if list_config:
data = read_yaml(list_config[-1])
list_config.append(input("Укажите название Сервера: \n"))
if list_config[-1] == '':
while True:
name_server = input("Укажите название Сервера: \n")
if name_server == "":
if map_s in list_config:
list_config.pop(); list_config.append(map_s + str(list_config.count(map_s)))
count = 1
new_name = map_s
print(list_config)
while new_name in list_config:
new_name = f"{map_s}({str(count)})"
count += 1
list_config.append(new_name)
print(list_config)
break
else:
list_config.pop(); list_config.append(map_s) # если enter, то ставим последним элементом карту
list_config.append(map_s)
break
else:
if name_server in list_config:
print("Имя занято")
else:
list_config.append(map_s) # если enter, то ставим последним элементом карту
break
port_server = ports(port_s)
query_port = ports(query_p)
@ -454,7 +470,9 @@ def rcon(m,c):
with Client('127.0.0.1', port, passwd=str(passwd)) as client:
response = client.run(c)
print(response)
def zero(x=""):
return ""
if __name__ == 'hlna':
input = zero
if __name__ == '__main__':
hlna()

@ -5,6 +5,10 @@ import unittest
import time
from threading import Thread
def zero(x=""):
return 0
input = zero
import hlna
"---------------import подменяем через unittest.mock -----------------------"
@ -12,9 +16,10 @@ import hlna
"---------------------------------------------------------------------------"
def config():
x = os.system("./hlna.py config < 1")
print("x=", x)
hlna.config()
def servers():
x = input()
print('x=',x)
x = os.system("./hlna.py servers")
if x == 0:
print("Servers - "+Fore.GREEN + "OK" + Style.RESET_ALL)
@ -23,6 +28,8 @@ def servers():
def delete():
print("Delete - " + Fore.RED + "False" + Style.RESET_ALL)
class TestHlna(unittest.TestCase):
def setUp(self):
self.p1
def test_config(self):
pass
# self.assert _input(hlna.config(input(1), 11))
@ -40,7 +47,7 @@ class TestHlna(unittest.TestCase):
if __name__ == "__main__":
#unittest.main()
servers()
#servers()
config()
delete()