diff --git a/hlna.py b/hlna.py index 4f50fb4..e31dc76 100755 --- a/hlna.py +++ b/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,23 +174,39 @@ 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] == '': - if map_s in list_config: - list_config.pop(); list_config.append(map_s + str(list_config.count(map_s))) + + while True: + name_server = input("Укажите название Сервера: \n") + 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: - 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) 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() diff --git a/pytest.py b/pytest.py index 72e2464..9445842 100644 --- a/pytest.py +++ b/pytest.py @@ -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()