pep8
This commit is contained in:
parent
3de8242305
commit
ad78554061
24
hlna.py
24
hlna.py
@ -1,32 +1,42 @@
|
||||
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import yaml
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
import colorama
|
||||
|
||||
home_dir = Path.home()
|
||||
dir_server = f"{home_dir}/ARK_Servers/"
|
||||
config_hlna = f"{home_dir}/.config/hlna/"
|
||||
mods_id = ""
|
||||
listen_server = True
|
||||
|
||||
|
||||
@click.group()
|
||||
def hlna():
|
||||
pass
|
||||
|
||||
list_config = next(os.walk(config_hlna), (None, None, []))[2] # [] if no file
|
||||
x = list_config.count('.directory')
|
||||
if x>0:
|
||||
list_config.remove('.directory')
|
||||
|
||||
|
||||
def print_line(text):
|
||||
"Добавление тире вокруг текста, покраска"
|
||||
print(colorama.Fore.YELLOW + "-"*30)
|
||||
print(colorama.Fore.GREEN + text)
|
||||
print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL)
|
||||
|
||||
|
||||
def create_dir(directory):
|
||||
"Проверка и создание директории"
|
||||
if not os.path.exists(directory):
|
||||
os.mkdir(directory)
|
||||
|
||||
|
||||
def check_int(number=""):
|
||||
"Проверка на ввод числа"
|
||||
while True:
|
||||
@ -42,6 +52,8 @@ def check_int(number=""):
|
||||
print("Введите число")
|
||||
create_dir(dir_server)
|
||||
create_dir(config_hlna)
|
||||
|
||||
|
||||
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
||||
def config(map_server=list_config):
|
||||
query_p = []
|
||||
@ -153,6 +165,8 @@ def config(map_server=list_config):
|
||||
if max_players == "":
|
||||
max_players = 70
|
||||
yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override)
|
||||
|
||||
|
||||
def yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override):
|
||||
settings_hlna = [
|
||||
{
|
||||
@ -174,6 +188,8 @@ def yaml_create(cluster_server, map_server, name_server, port_server, query_port
|
||||
with open(config_hlna + f"{map_server[-1]}", 'w') as yamlfile:
|
||||
data = yaml.dump(settings_hlna, yamlfile)
|
||||
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
|
||||
|
||||
|
||||
@hlna.command()
|
||||
def servers(map_server=list_config):
|
||||
if map_server==[]:
|
||||
@ -192,6 +208,8 @@ def servers(map_server=list_config):
|
||||
Моды: {mods_id}
|
||||
Кластер id: {cluster_id}""")
|
||||
print("\n")
|
||||
|
||||
|
||||
@hlna.command(help='Для запуска, сконфигурированного сервера или кластера')
|
||||
def start(map_server=list_config):
|
||||
map_choise = []
|
||||
@ -227,6 +245,8 @@ def start(map_server=list_config):
|
||||
os.system(f"./ShooterGameServer {i}?SessionName={name_server}?Port={port_server}?QueryPort={query_port}?MaxPlayers={max_players}?GameModIds={mods_id}?listen={listen_server} -clusterid={cluster_id} -ClusterDirOverride={cluster_dir_ovverride}")
|
||||
threads = threading.Thread(target=start, args=(i,))
|
||||
threads.start()
|
||||
|
||||
|
||||
def read_yaml(map_server):
|
||||
with open(f"{home_dir}/.config/hlna/{map_server}", "r") as yamlfile:
|
||||
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
||||
@ -245,5 +265,7 @@ def read_yaml(map_server):
|
||||
print(cluster_id)
|
||||
print(cluster_dir_ovverride)
|
||||
return cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
hlna()
|
Loading…
Reference in New Issue
Block a user