Update readme and changelog

further parsing cleanup
This commit is contained in:
Matteo ℱan 2020-02-05 00:37:58 +01:00
parent 5f9f7fa784
commit b88a46a67d
No known key found for this signature in database
GPG Key ID: 3C30A05BC133D9B6
6 changed files with 101 additions and 80 deletions

View File

@ -1,3 +1,10 @@
### py-kms_2020-02-02
- Optimized pretty-print messages process.
- Added -F FILESTDOUT option.
- Added deamonization options (via [Etrigan](https://github.com/SystemRage/Etrigan) project).
- py-kms GUI resurrected (and improved).
- Cleaned, cleaned, cleaned.
### py-kms_2019-05-15 ### py-kms_2019-05-15
- Merging for Python2 / Python3 compatibility all-in-one. - Merging for Python2 / Python3 compatibility all-in-one.
- Added new options: - Added new options:

View File

@ -8,7 +8,7 @@ _py-kms_ is a port of node-kms created by [cyrozap](http://forums.mydigitallife.
- Windows 7 - Windows 7
- Windows 8 - Windows 8
- Windows 8.1 - Windows 8.1
- Windows 10 ( 1511 / 1607 / 1703 / 1709 / 1803 / 1809 / 1903 ) - Windows 10 ( 1511 / 1607 / 1703 / 1709 / 1803 / 1809 / 1903 / 1909 )
- Windows Server 2008 - Windows Server 2008
- Windows Server 2008 R2 - Windows Server 2008 R2
- Windows Server 2012 - Windows Server 2012
@ -39,16 +39,19 @@ _py-kms_ is a port of node-kms created by [cyrozap](http://forums.mydigitallife.
# Usage # Usage
- __NOTE__: Pay attention to how invoke scripts, if you want to run with python2 use ```python...``` while for python3 use ```python3...```, also depending on the Python versions that resides in your PC. - __NOTE__: Pay attention to how invoke scripts, if you want to run with python2 use ```python...``` while for python3 use ```python3...```, also depending on the Python versions that resides in your PC.
- To start the server, execute ```python pykms_Server.py [IPADDRESS] [PORT]```. - To start the server, execute ```python pykms_Server.py [IPADDRESS] [PORT]```, the default _IPADDRESS_ is "0.0.0.0" ( all interfaces ) and the default _PORT_ is "1688".
The default _IPADDRESS_ is "0.0.0.0" ( all interfaces ) and the default _PORT_ is "1688". - To run the client (only for testing purposes), use ```python pykms_Client.py [IPADDRESS] [PORT]```, with the same defaults of ```pykms_Server.py```.
- To run the client (only for testing purposes), use ```python pykms_Client.py IPADDRESS [PORT]```. - To show the help pages type: ```python pykms_Server.py -h``` and ```python pykms_Client.py -h```.
Argument _IPADDRESS_ is always required, while the default _PORT_ is "1688", so a valid command is: ```python pykms_Client.py 0.0.0.0``` - To generate a random HWID use ```-w``` option: ```python pykms_Server.py -w RANDOM```.
- To show the help pages type: ```python pykms_Server.py -h``` and ```python pykms_Client.py -h``` - To get the HWID from any server use the client, for example type: ```python pykms_Client.py 0.0.0.0 1688 -m Windows8.1 -V INFO```.
- To generate a random HWID use ```-w``` option: ```python pykms_Server.py -w RANDOM``` - To view a minimal set of logging information use ```-V MINI``` option, for example: ```python pykms_Server.py -F /path/to/your/logfile.log -V MINI```.
- To get the HWID from any server use the client, for example type: ```python pykms_Client.py 0.0.0.0 1688 -m Windows8.1 -V INFO``` - To redirect logging on stdout use ```-F STDOUT``` option, for example: ```python pykms_Server.py -F STDOUT -V DEBUG```.
- To view a minimal set of logging information use ```-V MINI``` option, for example: ```python pykms_Server.py -V MINI``` - You can create logfile and view logging information on stdout at the same time with ```-F FILESTDOUT``` option, for example: ```python pykms_Server.py -F FILESTDOUT /path/to/your/logfile.log -V DEBUG```.
- To redirect logging on stdout use ```-F STDOUT``` option, for example: ```python pykms_Server.py -F STDOUT``` - Select timeout (seconds) for py-kms with ```-t``` option, for example ```python pykms_Server.py -t 10```
- For launching py-kms GUI make executable all _.py_ files in _py-kms_ directory ```chmod +x /path/to/scripts/py-kms/*.py```, then simply run ```pykms_Server.py``` double-clicking. - For launching py-kms GUI make executable ```pykms_Server.py``` file with ```chmod +x /path/to/folder/py-kms/pykms_Server.py```, then simply run ```pykms_Server.py``` double-clicking.
- You can run py-kms deamonized (via [Etrigan](https://github.com/SystemRage/Etrigan)) using a command like: ```python pykms_Server.py etrigan start``` and stop it with: ```python pykms_Server.py etrigan stop```.
- With Etrigan you have another way to launch py-kms GUI (specially suitable if you're using a virtualenv), so: ```python pykms_Server.py etrigan start -g```
and stop the GUI with the same precedent command (or interact with EXIT button).
# Other Important Stuff # Other Important Stuff
Consult the [Wiki](https://github.com/SystemRage/py-kms/wiki) for more information about activation with _py-kms_ and to get GVLK keys. Consult the [Wiki](https://github.com/SystemRage/py-kms/wiki) for more information about activation with _py-kms_ and to get GVLK keys.

View File

@ -22,7 +22,7 @@ from pykms_RequestV6 import kmsRequestV6
from pykms_RpcBase import rpcBase from pykms_RpcBase import rpcBase
from pykms_DB2Dict import kmsDB2Dict from pykms_DB2Dict import kmsDB2Dict
from pykms_Misc import logger_create, check_logfile 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 from pykms_Format import justify, byterize, enco, deco, ShellMessage, pretty_printer
clt_version = "py-kms_2020-02-02" clt_version = "py-kms_2020-02-02"
@ -66,35 +66,39 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.',
} }
def client_options(): def client_options():
parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version) try:
parser.add_argument("ip", nargs = "?", action = "store", default = clt_options['ip']['def'], help = clt_options['ip']['help'], type = str) client_parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version, add_help = False, allow_abbrew = False)
parser.add_argument("port", nargs = "?", action = "store", default = clt_options['port']['def'], help = clt_options['port']['help'], type = int) except TypeError:
parser.add_argument("-m", "--mode", dest = clt_options['mode']['des'], default = clt_options['mode']['def'], choices = clt_options['mode']['choi'], client_parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version, add_help = False)
help = clt_options['mode']['help'], type = str) client_parser.add_argument("ip", nargs = "?", action = "store", default = clt_options['ip']['def'],
parser.add_argument("-c", "--cmid", dest = clt_options['cmid']['des'], default = clt_options['cmid']['def'], help = clt_options['cmid']['help'], type = str) help = clt_options['ip']['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) client_parser.add_argument("port", nargs = "?", action = "store", default = clt_options['port']['def'],
parser.add_argument("-V", "--loglevel", dest = clt_options['llevel']['des'], action = "store", choices = clt_options['llevel']['choi'], help = clt_options['port']['help'], type = int)
default = clt_options['llevel']['def'], help = clt_options['llevel']['help'], type = str) client_parser.add_argument("-m", "--mode", dest = clt_options['mode']['des'], default = clt_options['mode']['def'],
parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = clt_options['lfile']['des'], default = clt_options['lfile']['def'], choices = clt_options['mode']['choi'], help = clt_options['mode']['help'], type = str)
help = clt_options['lfile']['help'], type = str) client_parser.add_argument("-c", "--cmid", dest = clt_options['cmid']['des'], default = clt_options['cmid']['def'],
parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store", default = clt_options['lsize']['def'], help = clt_options['cmid']['help'], type = str)
help = clt_options['lsize']['help'], type = float) 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: try:
clt_config.update(vars(parser.parse_args())) if "-h" in sys.argv[1:]:
# Check logfile. KmsHelper().printer(parsers = [client_parser])
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt") clt_config.update(vars(client_parser.parse_args()))
except KmsException as e: except KmsException as e:
pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True) pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True)
def client_check(): def client_check():
# Check logfile (only for GUI). # Check logfile.
try: clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt")
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
# Setup hidden or not messages. # Setup hidden or not messages.
ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in clt_config['logfile']) else True ) ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in clt_config['logfile']) else True )

View File

@ -488,7 +488,7 @@ class KmsGui(tk.Tk):
def clt_on_start(self): def clt_on_start(self):
self.clt_actions_start() 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 = threading.Thread(target = self.clt_eject, name = "Thread-CltEjt")
self.clt_eject_thread.setDaemon(True) self.clt_eject_thread.setDaemon(True)
self.clt_eject_thread.start() self.clt_eject_thread.start()
@ -510,14 +510,13 @@ class KmsGui(tk.Tk):
clt_config[clt_options['lsize']['des']] = 0 clt_config[clt_options['lsize']['des']] = 0
# run client (in a thread). # run client (in a thread).
global clientthread self.clientthread = client_thread(name = "Thread-Clt")
clientthread = client_thread(name = "Thread-Clt") self.clientthread.setDaemon(True)
clientthread.setDaemon(True) self.clientthread.with_gui = True
clientthread.with_gui = True self.clientthread.start()
clientthread.start()
def clt_eject(self): def clt_eject(self):
while clientthread.is_alive(): while self.clientthread.is_alive():
sleep(0.1) sleep(0.1)
for widget in self.allopts_clt + [self.runbtnsrv, self.runbtnclt]: for widget in self.allopts_clt + [self.runbtnsrv, self.runbtnclt]:
widget.configure(state = 'normal') widget.configure(state = 'normal')

View File

@ -223,26 +223,34 @@ class KmsParser(argparse.ArgumentParser):
raise KmsException(message) raise KmsException(message)
class KmsHelper(object): class KmsHelper(object):
def replace(self, parser): def replace(self, parser, replace_epilog_with):
text = parser.format_help().splitlines() text = parser.format_help().splitlines()
help_list = [] help_list = []
for line in text: for line in text:
if line == parser.description: if line == parser.description:
continue continue
if line == parser.epilog: if line == parser.epilog:
line = 80 * '*' + '\n' line = replace_epilog_with
help_list.append(line) help_list.append(line)
return help_list return help_list
def printer(self, parsers): 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('\n' + parser_base.description)
print(len(parser_base.description) * '-' + '\n') print(len(parser_base.description) * '-' + '\n')
for line in self.replace(parser_base): for line in self.replace(parser_base, replace_epilog_with):
print(line)
print(parser_adj.description + '\n')
for line in self.replace(parser_sub):
print(line) 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('\n' + len(parser_base.epilog) * '-')
print(parser_base.epilog + '\n') print(parser_base.epilog + '\n')
parser_base.exit() parser_base.exit()

View File

@ -188,35 +188,35 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.',
def server_options(): def server_options():
try: 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: 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) server_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) server_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'], 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) 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'], 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) 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'], 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) help = srv_options['count']['help'], type = int)
main_parser.add_argument("-a", "--activation-interval", action = "store", dest = srv_options['activation']['des'], 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) 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'], 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) 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'], 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']) help = srv_options['sql']['help'])
main_parser.add_argument("-w", "--hwid", action = "store", dest = srv_options['hwid']['des'], default = srv_options['hwid']['def'], 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) 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'], 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) 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'], 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) 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'], 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) 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'], 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) 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("-h", "--help", action = "help", help = "show this help message and exit")
try: try:
daemon_parser = KmsParser(description = "daemon options inherited from Etrigan", add_help = False, allow_abbrev = False) daemon_parser = KmsParser(description = "daemon options inherited from Etrigan", add_help = False, allow_abbrev = False)
@ -234,11 +234,11 @@ def server_options():
try: try:
if "-h" in sys.argv[1:]: 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. # Set defaults for config.
# case: python3 pykms_Server.py # 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. # Eventually set daemon values for config.
if 'etrigan' in sys.argv[1:]: if 'etrigan' in sys.argv[1:]:
if 'etrigan' == 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:]))) srv_config.update(vars(daemon_parser.parse_args(sys.argv[2:])))
else: else:
# case: python3 pykms_Server.py 1.2.3.4 1234 --main_optionals etrigan start --daemon_optionals # 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. # fix for logfile option (at the end) that catchs etrigan parser options.
if 'etrigan' in knw_args.logfile: if 'etrigan' in knw_args.logfile:
indx = knw_args.logfile.index('etrigan') indx = knw_args.logfile.index('etrigan')
@ -265,7 +265,7 @@ def server_options():
else: else:
# Update dict config. # Update dict config.
# case: python3 pykms_Server.py 1.2.3.4 1234 --main_optionals # 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 != []: if knw_extras != []:
raise KmsException("unrecognized arguments: %s" %' '.join(knw_extras)) raise KmsException("unrecognized arguments: %s" %' '.join(knw_extras))
else: else: