mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-07-26 03:28:16 +02:00
Update readme and changelog
further parsing cleanup
This commit is contained in:
parent
5f9f7fa784
commit
b88a46a67d
6 changed files with 101 additions and 80 deletions
|
@ -22,7 +22,7 @@ from pykms_RequestV6 import kmsRequestV6
|
|||
from pykms_RpcBase import rpcBase
|
||||
from pykms_DB2Dict import kmsDB2Dict
|
||||
from pykms_Misc import logger_create, check_logfile
|
||||
from pykms_Misc import KmsParser, KmsException
|
||||
from pykms_Misc import KmsParser, KmsException, KmsHelper
|
||||
from pykms_Format import justify, byterize, enco, deco, ShellMessage, pretty_printer
|
||||
|
||||
clt_version = "py-kms_2020-02-02"
|
||||
|
@ -66,35 +66,39 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.',
|
|||
}
|
||||
|
||||
def client_options():
|
||||
parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version)
|
||||
parser.add_argument("ip", nargs = "?", action = "store", default = clt_options['ip']['def'], help = clt_options['ip']['help'], type = str)
|
||||
parser.add_argument("port", nargs = "?", action = "store", default = clt_options['port']['def'], help = clt_options['port']['help'], type = int)
|
||||
parser.add_argument("-m", "--mode", dest = clt_options['mode']['des'], default = clt_options['mode']['def'], choices = clt_options['mode']['choi'],
|
||||
help = clt_options['mode']['help'], type = str)
|
||||
parser.add_argument("-c", "--cmid", dest = clt_options['cmid']['des'], default = clt_options['cmid']['def'], help = clt_options['cmid']['help'], type = str)
|
||||
parser.add_argument("-n", "--name", dest = clt_options['name']['des'] , default = clt_options['name']['def'], help = clt_options['name']['help'], type = str)
|
||||
parser.add_argument("-V", "--loglevel", dest = clt_options['llevel']['des'], action = "store", choices = clt_options['llevel']['choi'],
|
||||
default = clt_options['llevel']['def'], help = clt_options['llevel']['help'], type = str)
|
||||
parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = clt_options['lfile']['des'], default = clt_options['lfile']['def'],
|
||||
help = clt_options['lfile']['help'], type = str)
|
||||
parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store", default = clt_options['lsize']['def'],
|
||||
help = clt_options['lsize']['help'], type = float)
|
||||
try:
|
||||
client_parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version, add_help = False, allow_abbrew = False)
|
||||
except TypeError:
|
||||
client_parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version, add_help = False)
|
||||
client_parser.add_argument("ip", nargs = "?", action = "store", default = clt_options['ip']['def'],
|
||||
help = clt_options['ip']['help'], type = str)
|
||||
client_parser.add_argument("port", nargs = "?", action = "store", default = clt_options['port']['def'],
|
||||
help = clt_options['port']['help'], type = int)
|
||||
client_parser.add_argument("-m", "--mode", dest = clt_options['mode']['des'], default = clt_options['mode']['def'],
|
||||
choices = clt_options['mode']['choi'], help = clt_options['mode']['help'], type = str)
|
||||
client_parser.add_argument("-c", "--cmid", dest = clt_options['cmid']['des'], default = clt_options['cmid']['def'],
|
||||
help = clt_options['cmid']['help'], type = str)
|
||||
client_parser.add_argument("-n", "--name", dest = clt_options['name']['des'] , default = clt_options['name']['def'],
|
||||
help = clt_options['name']['help'], type = str)
|
||||
client_parser.add_argument("-V", "--loglevel", dest = clt_options['llevel']['des'], action = "store",
|
||||
choices = clt_options['llevel']['choi'], default = clt_options['llevel']['def'],
|
||||
help = clt_options['llevel']['help'], type = str)
|
||||
client_parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = clt_options['lfile']['des'],
|
||||
default = clt_options['lfile']['def'], help = clt_options['lfile']['help'], type = str)
|
||||
client_parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store",
|
||||
default = clt_options['lsize']['def'], help = clt_options['lsize']['help'], type = float)
|
||||
client_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit")
|
||||
|
||||
try:
|
||||
clt_config.update(vars(parser.parse_args()))
|
||||
# Check logfile.
|
||||
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt")
|
||||
if "-h" in sys.argv[1:]:
|
||||
KmsHelper().printer(parsers = [client_parser])
|
||||
clt_config.update(vars(client_parser.parse_args()))
|
||||
except KmsException as e:
|
||||
pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True)
|
||||
|
||||
def client_check():
|
||||
# Check logfile (only for GUI).
|
||||
try:
|
||||
from pykms_GuiBase import clientthread
|
||||
if clientthread.with_gui:
|
||||
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt")
|
||||
except ImportError:
|
||||
pass
|
||||
# Check logfile.
|
||||
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt")
|
||||
|
||||
# Setup hidden or not messages.
|
||||
ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in clt_config['logfile']) else True )
|
||||
|
|
|
@ -488,7 +488,7 @@ class KmsGui(tk.Tk):
|
|||
|
||||
def clt_on_start(self):
|
||||
self.clt_actions_start()
|
||||
# run thread for disable interrupting server and client, when client running.
|
||||
# run thread for disabling interrupt server and client, when client running.
|
||||
self.clt_eject_thread = threading.Thread(target = self.clt_eject, name = "Thread-CltEjt")
|
||||
self.clt_eject_thread.setDaemon(True)
|
||||
self.clt_eject_thread.start()
|
||||
|
@ -510,14 +510,13 @@ class KmsGui(tk.Tk):
|
|||
clt_config[clt_options['lsize']['des']] = 0
|
||||
|
||||
# run client (in a thread).
|
||||
global clientthread
|
||||
clientthread = client_thread(name = "Thread-Clt")
|
||||
clientthread.setDaemon(True)
|
||||
clientthread.with_gui = True
|
||||
clientthread.start()
|
||||
self.clientthread = client_thread(name = "Thread-Clt")
|
||||
self.clientthread.setDaemon(True)
|
||||
self.clientthread.with_gui = True
|
||||
self.clientthread.start()
|
||||
|
||||
def clt_eject(self):
|
||||
while clientthread.is_alive():
|
||||
while self.clientthread.is_alive():
|
||||
sleep(0.1)
|
||||
for widget in self.allopts_clt + [self.runbtnsrv, self.runbtnclt]:
|
||||
widget.configure(state = 'normal')
|
||||
|
|
|
@ -223,26 +223,34 @@ class KmsParser(argparse.ArgumentParser):
|
|||
raise KmsException(message)
|
||||
|
||||
class KmsHelper(object):
|
||||
def replace(self, parser):
|
||||
def replace(self, parser, replace_epilog_with):
|
||||
text = parser.format_help().splitlines()
|
||||
help_list = []
|
||||
for line in text:
|
||||
if line == parser.description:
|
||||
continue
|
||||
if line == parser.epilog:
|
||||
line = 80 * '*' + '\n'
|
||||
line = replace_epilog_with
|
||||
help_list.append(line)
|
||||
return help_list
|
||||
|
||||
def printer(self, parsers):
|
||||
parser_base, parser_adj, parser_sub = parsers
|
||||
if len(parsers) == 3:
|
||||
parser_base, parser_adj, parser_sub = parsers
|
||||
replace_epilog_with = 80 * '*' + '\n'
|
||||
elif len(parsers) == 1:
|
||||
parser_base = parsers[0]
|
||||
replace_epilog_with = ''
|
||||
print('\n' + parser_base.description)
|
||||
print(len(parser_base.description) * '-' + '\n')
|
||||
for line in self.replace(parser_base):
|
||||
print(line)
|
||||
print(parser_adj.description + '\n')
|
||||
for line in self.replace(parser_sub):
|
||||
for line in self.replace(parser_base, replace_epilog_with):
|
||||
print(line)
|
||||
try:
|
||||
print(parser_adj.description + '\n')
|
||||
for line in self.replace(parser_sub, replace_epilog_with):
|
||||
print(line)
|
||||
except:
|
||||
pass
|
||||
print('\n' + len(parser_base.epilog) * '-')
|
||||
print(parser_base.epilog + '\n')
|
||||
parser_base.exit()
|
||||
|
|
|
@ -188,35 +188,35 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.',
|
|||
|
||||
def server_options():
|
||||
try:
|
||||
main_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False, allow_abbrev = False)
|
||||
server_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False, allow_abbrev = False)
|
||||
except TypeError:
|
||||
main_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False)
|
||||
server_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False)
|
||||
|
||||
main_parser.add_argument("ip", nargs = "?", action = "store", default = srv_options['ip']['def'], help = srv_options['ip']['help'], type = str)
|
||||
main_parser.add_argument("port", nargs = "?", action = "store", default = srv_options['port']['def'], help = srv_options['port']['help'], type = int)
|
||||
main_parser.add_argument("-e", "--epid", action = "store", dest = srv_options['epid']['des'], default = srv_options['epid']['def'],
|
||||
help = srv_options['epid']['help'], type = str)
|
||||
main_parser.add_argument("-l", "--lcid", action = "store", dest = srv_options['lcid']['des'], default = srv_options['lcid']['def'],
|
||||
help = srv_options['lcid']['help'], type = int)
|
||||
main_parser.add_argument("-c", "--client-count", action = "store", dest = srv_options['count']['des'] , default = srv_options['count']['def'],
|
||||
help = srv_options['count']['help'], type = int)
|
||||
main_parser.add_argument("-a", "--activation-interval", action = "store", dest = srv_options['activation']['des'],
|
||||
default = srv_options['activation']['def'], help = srv_options['activation']['help'], type = int)
|
||||
main_parser.add_argument("-r", "--renewal-interval", action = "store", dest = srv_options['renewal']['des'], default = srv_options['renewal']['def'],
|
||||
help = srv_options['renewal']['help'], type = int)
|
||||
main_parser.add_argument("-s", "--sqlite", action = "store_const", dest = srv_options['sql']['des'], const = True, default = srv_options['sql']['def'],
|
||||
help = srv_options['sql']['help'])
|
||||
main_parser.add_argument("-w", "--hwid", action = "store", dest = srv_options['hwid']['des'], default = srv_options['hwid']['def'],
|
||||
help = srv_options['hwid']['help'], type = str)
|
||||
main_parser.add_argument("-t", "--timeout", action = "store", dest = srv_options['time']['des'], default = srv_options['time']['def'],
|
||||
help = srv_options['time']['help'], type = int)
|
||||
main_parser.add_argument("-V", "--loglevel", action = "store", dest = srv_options['llevel']['des'], choices = srv_options['llevel']['choi'],
|
||||
default = srv_options['llevel']['def'], help = srv_options['llevel']['help'], type = str)
|
||||
main_parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = srv_options['lfile']['des'], default = srv_options['lfile']['def'],
|
||||
help = srv_options['lfile']['help'], type = str)
|
||||
main_parser.add_argument("-S", "--logsize", action = "store", dest = srv_options['lsize']['des'], default = srv_options['lsize']['def'],
|
||||
help = srv_options['lsize']['help'], type = float)
|
||||
main_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit")
|
||||
server_parser.add_argument("ip", nargs = "?", action = "store", default = srv_options['ip']['def'], help = srv_options['ip']['help'], type = str)
|
||||
server_parser.add_argument("port", nargs = "?", action = "store", default = srv_options['port']['def'], help = srv_options['port']['help'], type = int)
|
||||
server_parser.add_argument("-e", "--epid", action = "store", dest = srv_options['epid']['des'], default = srv_options['epid']['def'],
|
||||
help = srv_options['epid']['help'], type = str)
|
||||
server_parser.add_argument("-l", "--lcid", action = "store", dest = srv_options['lcid']['des'], default = srv_options['lcid']['def'],
|
||||
help = srv_options['lcid']['help'], type = int)
|
||||
server_parser.add_argument("-c", "--client-count", action = "store", dest = srv_options['count']['des'] , default = srv_options['count']['def'],
|
||||
help = srv_options['count']['help'], type = int)
|
||||
server_parser.add_argument("-a", "--activation-interval", action = "store", dest = srv_options['activation']['des'],
|
||||
default = srv_options['activation']['def'], help = srv_options['activation']['help'], type = int)
|
||||
server_parser.add_argument("-r", "--renewal-interval", action = "store", dest = srv_options['renewal']['des'], default = srv_options['renewal']['def'],
|
||||
help = srv_options['renewal']['help'], type = int)
|
||||
server_parser.add_argument("-s", "--sqlite", action = "store_const", dest = srv_options['sql']['des'], const = True, default = srv_options['sql']['def'],
|
||||
help = srv_options['sql']['help'])
|
||||
server_parser.add_argument("-w", "--hwid", action = "store", dest = srv_options['hwid']['des'], default = srv_options['hwid']['def'],
|
||||
help = srv_options['hwid']['help'], type = str)
|
||||
server_parser.add_argument("-t", "--timeout", action = "store", dest = srv_options['time']['des'], default = srv_options['time']['def'],
|
||||
help = srv_options['time']['help'], type = int)
|
||||
server_parser.add_argument("-V", "--loglevel", action = "store", dest = srv_options['llevel']['des'], choices = srv_options['llevel']['choi'],
|
||||
default = srv_options['llevel']['def'], help = srv_options['llevel']['help'], type = str)
|
||||
server_parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = srv_options['lfile']['des'], default = srv_options['lfile']['def'],
|
||||
help = srv_options['lfile']['help'], type = str)
|
||||
server_parser.add_argument("-S", "--logsize", action = "store", dest = srv_options['lsize']['des'], default = srv_options['lsize']['def'],
|
||||
help = srv_options['lsize']['help'], type = float)
|
||||
server_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit")
|
||||
|
||||
try:
|
||||
daemon_parser = KmsParser(description = "daemon options inherited from Etrigan", add_help = False, allow_abbrev = False)
|
||||
|
@ -234,11 +234,11 @@ def server_options():
|
|||
|
||||
try:
|
||||
if "-h" in sys.argv[1:]:
|
||||
KmsHelper().printer(parsers = [main_parser, daemon_parser, etrigan_parser])
|
||||
KmsHelper().printer(parsers = [server_parser, daemon_parser, etrigan_parser])
|
||||
|
||||
# Set defaults for config.
|
||||
# case: python3 pykms_Server.py
|
||||
srv_config.update(vars(main_parser.parse_args([])))
|
||||
srv_config.update(vars(server_parser.parse_args([])))
|
||||
# Eventually set daemon values for config.
|
||||
if 'etrigan' in sys.argv[1:]:
|
||||
if 'etrigan' == sys.argv[1]:
|
||||
|
@ -250,7 +250,7 @@ def server_options():
|
|||
srv_config.update(vars(daemon_parser.parse_args(sys.argv[2:])))
|
||||
else:
|
||||
# case: python3 pykms_Server.py 1.2.3.4 1234 --main_optionals etrigan start --daemon_optionals
|
||||
knw_args, knw_extras = main_parser.parse_known_args()
|
||||
knw_args, knw_extras = server_parser.parse_known_args()
|
||||
# fix for logfile option (at the end) that catchs etrigan parser options.
|
||||
if 'etrigan' in knw_args.logfile:
|
||||
indx = knw_args.logfile.index('etrigan')
|
||||
|
@ -265,7 +265,7 @@ def server_options():
|
|||
else:
|
||||
# Update dict config.
|
||||
# case: python3 pykms_Server.py 1.2.3.4 1234 --main_optionals
|
||||
knw_args, knw_extras = main_parser.parse_known_args()
|
||||
knw_args, knw_extras = server_parser.parse_known_args()
|
||||
if knw_extras != []:
|
||||
raise KmsException("unrecognized arguments: %s" %' '.join(knw_extras))
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue