Parsing fix for python2

This commit is contained in:
Matteo ℱan 2020-02-04 00:24:11 +01:00
parent a497d8ddb2
commit 5f9f7fa784
No known key found for this signature in database
GPG Key ID: 3C30A05BC133D9B6
2 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import print_function
import sys import sys
import logging import logging
import os import os
@ -233,7 +234,7 @@ class KmsHelper(object):
help_list.append(line) help_list.append(line)
return help_list return help_list
def print(self, parsers): def printer(self, parsers):
parser_base, parser_adj, parser_sub = parsers parser_base, parser_adj, parser_sub = parsers
print('\n' + parser_base.description) print('\n' + parser_base.description)
print(len(parser_base.description) * '-' + '\n') print(len(parser_base.description) * '-' + '\n')

View File

@ -187,7 +187,11 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.',
} }
def server_options(): def server_options():
try:
main_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False, allow_abbrev = False) main_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)
main_parser.add_argument("ip", nargs = "?", action = "store", default = srv_options['ip']['def'], help = srv_options['ip']['help'], type = str) 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("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'], main_parser.add_argument("-e", "--epid", action = "store", dest = srv_options['epid']['des'], default = srv_options['epid']['def'],
@ -214,16 +218,23 @@ def server_options():
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") main_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) daemon_parser = KmsParser(description = "daemon options inherited from Etrigan", add_help = False, allow_abbrev = False)
except TypeError:
daemon_parser = KmsParser(description = "daemon options inherited from Etrigan", add_help = False)
daemon_subparser = daemon_parser.add_subparsers(dest = "mode") daemon_subparser = daemon_parser.add_subparsers(dest = "mode")
try:
etrigan_parser = daemon_subparser.add_parser("etrigan", add_help = False, allow_abbrev = False) etrigan_parser = daemon_subparser.add_parser("etrigan", add_help = False, allow_abbrev = False)
except TypeError:
etrigan_parser = daemon_subparser.add_parser("etrigan", add_help = False)
etrigan_parser.add_argument("-g", "--gui", action = "store_const", dest = 'gui', const = True, default = False, etrigan_parser.add_argument("-g", "--gui", action = "store_const", dest = 'gui', const = True, default = False,
help = "Enable py-kms GUI usage.") help = "Enable py-kms GUI usage.")
etrigan_parser = Etrigan_parser(parser = etrigan_parser) etrigan_parser = Etrigan_parser(parser = etrigan_parser)
try: try:
if "-h" in sys.argv[1:]: if "-h" in sys.argv[1:]:
KmsHelper().print(parsers = [main_parser, daemon_parser, etrigan_parser]) KmsHelper().printer(parsers = [main_parser, daemon_parser, etrigan_parser])
# Set defaults for config. # Set defaults for config.
# case: python3 pykms_Server.py # case: python3 pykms_Server.py