чистка принтов и удаление лишнего
This commit is contained in:
38
hlna.py
38
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
|
||||
|
Reference in New Issue
Block a user