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

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

46
hlna.py

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

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