2024-04-23 18:22:53 -04:00
|
|
|
#!/usr/bin/env python3 -B
|
|
|
|
# coding=utf-8
|
2022-04-01 10:43:22 -04:00
|
|
|
|
2022-04-17 13:48:43 -04:00
|
|
|
"""
|
2024-04-23 18:22:53 -04:00
|
|
|
Copyright (C) 2022-2024 Plato Mavropoulos
|
2022-04-17 13:48:43 -04:00
|
|
|
"""
|
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
import sys
|
|
|
|
|
2022-04-15 11:17:58 -04:00
|
|
|
from common.text_ops import padder, to_string
|
2022-04-06 18:13:07 -04:00
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
def get_py_ver():
|
2024-04-23 18:22:53 -04:00
|
|
|
""" Get Python Version (tuple) """
|
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
return sys.version_info
|
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
def get_os_ver():
|
2024-04-23 18:22:53 -04:00
|
|
|
""" Get OS Platform (string) """
|
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
sys_os = sys.platform
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
is_win = sys_os == 'win32'
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
is_lnx = sys_os.startswith('linux') or sys_os == 'darwin' or sys_os.find('bsd') != -1
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
return sys_os, is_win, is_win or is_lnx
|
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
def is_auto_exit():
|
2024-04-23 18:22:53 -04:00
|
|
|
""" Check for --auto-exit|-e """
|
|
|
|
|
2022-04-06 18:13:07 -04:00
|
|
|
return bool('--auto-exit' in sys.argv or '-e' in sys.argv)
|
2022-04-01 10:43:22 -04:00
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
def check_sys_py():
|
2024-04-23 18:22:53 -04:00
|
|
|
""" # Check Python Version """
|
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
sys_py = get_py_ver()
|
2024-04-23 18:22:53 -04:00
|
|
|
|
|
|
|
if sys_py < (3, 10):
|
2022-10-16 11:21:23 -04:00
|
|
|
sys.stdout.write(f'\nError: Python >= 3.10 required, not {sys_py[0]}.{sys_py[1]}!')
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
if not is_auto_exit():
|
|
|
|
# noinspection PyUnresolvedReferences
|
2024-04-23 18:22:53 -04:00
|
|
|
(raw_input if sys_py[0] <= 2 else input)('\nPress enter to exit') # pylint: disable=E0602
|
|
|
|
|
2022-05-06 06:54:48 -04:00
|
|
|
sys.exit(125)
|
2022-04-01 10:43:22 -04:00
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
def check_sys_os():
|
2024-04-23 18:22:53 -04:00
|
|
|
""" Check OS Platform """
|
|
|
|
|
|
|
|
os_tag, os_win, os_sup = get_os_ver()
|
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
if not os_sup:
|
2022-05-21 17:24:20 -04:00
|
|
|
printer(f'Error: Unsupported platform "{os_tag}"!')
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
if not is_auto_exit():
|
|
|
|
input('\nPress enter to exit')
|
2024-04-23 18:22:53 -04:00
|
|
|
|
|
|
|
sys.exit(126)
|
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
# Fix Windows Unicode console redirection
|
2022-07-06 10:54:17 -04:00
|
|
|
if os_win:
|
2024-04-23 18:22:53 -04:00
|
|
|
# noinspection PyUnresolvedReferences
|
2022-07-06 10:54:17 -04:00
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
2022-04-01 10:43:22 -04:00
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
|
|
|
def printer(message=None, padd=0, new_line=True, pause=False, sep_char=' '):
|
|
|
|
""" Show message(s), controlling padding, newline, pausing & separator """
|
|
|
|
|
|
|
|
message_input = '' if message is None else message
|
|
|
|
|
|
|
|
string = to_string(message_input, sep_char)
|
|
|
|
|
|
|
|
padding = padder(padd)
|
|
|
|
|
2022-04-06 18:13:07 -04:00
|
|
|
newline = '\n' if new_line else ''
|
2024-04-23 18:22:53 -04:00
|
|
|
|
|
|
|
message_output = newline + padding + string
|
|
|
|
|
|
|
|
(input if pause and not is_auto_exit() else print)(message_output)
|