From 5b5db556b86c633ef1811ccfedcb27bf3cf3b3ff Mon Sep 17 00:00:00 2001 From: sitisll Date: Mon, 15 May 2023 15:56:55 +0300 Subject: [PATCH] =?UTF-8?q?=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B8=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hlna.py | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/hlna.py b/hlna.py index 9222523..00ab10d 100755 --- a/hlna.py +++ b/hlna.py @@ -20,27 +20,11 @@ home_dir = Path.home() logging.basicConfig(stream=sys.stderr, level=logging.CRITICAL) -class UnpackException(Exception): - pass - - -class SignatureUnpackException(UnpackException): - pass - - -class CorruptUnpackException(UnpackException): - pass - - def find_file(path): """Находим все конфиги в зависимости от пути""" arr = next(os.walk(path), (None, None, []))[2] # [] if no file - x = arr.count('.directory') - y = arr.count('logs') - if x > 0: + if '.directory' in arr: arr.remove('.directory') - if y > 0: - arr.remove('logs') return arr @@ -52,11 +36,12 @@ delist_config = find_file(dir_deactivated) def path_server(): + 'Получение пути для хранения файлов серверов, записываем путь в yaml файл' dir_server = input(f"""Укажите путь до каталога, где будут храниться файлы сервера. По-умолчанию {home_dir}/Servers/ :""") - if dir_server == "": + if not dir_server: dir_server = f"{home_dir}/Servers/" - yaml_create(game := "path_server", dir_server) + yaml_create("path_server", dir_server) return dir_server @@ -66,6 +51,7 @@ def hlna(): def unpack(src, dst): + 'Добавить документацию' with open(src, 'rb') as f: sigver = struct.unpack('q', f.read(8))[0] unpacked_chunk = f.read(8) @@ -98,7 +84,8 @@ def unpack(src, dst): if size_unpacked != size_indexed: msg = f"Header-Index mismatch. Header indicates it should only have {size_unpacked} bytes when uncompressed but the index indicates {size_indexed} bytes." logging.critical(msg) - raise CorruptUnpackException(msg) + return print(msg) + # Read the actual archive data data = b'' @@ -116,19 +103,19 @@ def unpack(src, dst): if len(uncompressed_data) != size_unpacked_chunk and read_data != len(compression_index): msg = f"Index contains more than one partial chunk: was {len(uncompressed_data)} when the full chunk size is {size_unpacked_chunk}, chunk {read_data}/{len(compression_index)}" logging.critical(msg) - raise CorruptUnpackException(msg) + return print(msg) else: msg = f"Uncompressed chunk size is not the same as in the index: was {len(uncompressed_data)} but should be {uncompressed}." logging.critical(msg) - raise CorruptUnpackException(msg) + return print(msg) else: msg = f"Data types in the headers should be int's. Size Types: unpacked_chunk({type(size_unpacked_chunk)}), packed({type(size_packed)}), unpacked({type(size_unpacked)})" logging.critical(msg) - raise CorruptUnpackException(msg) + return print(msg) else: msg = "The signature and format version is incorrect. Signature was {} should be 2653586369.".format(sigver) logging.critical(msg) - raise SignatureUnpackException(msg) + return print(msg) # Write the extracted data to disk with open(dst, 'wb') as f: @@ -142,7 +129,7 @@ def create_dir(directory): os.makedirs(directory) -def print_line(text): +def print_line(*text): """Добавление тире вокруг текста, покраска""" print(colorama.Fore.YELLOW + "-" * 30) print(f"{colorama.Fore.GREEN} + {text}") @@ -425,6 +412,7 @@ def systemd_unit_create(game, config_7days="", name_server=list_config): systemd_unit_exec = f"{dir_server_7days}startserver.sh -configfile={config_7days}.xml" unit_file = f"{dir_unit}7days.service".lower() + unit_text = f'''[Unit] Description={game}: Server Wants=network-online.target