2013-04-24 20:25:50 +02:00
|
|
|
# includes/argparser.py
|
|
|
|
#
|
2013-06-25 14:03:28 +02:00
|
|
|
# module version: 1.1.20130625
|
2013-04-24 20:25:50 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
class argparser:
|
2013-04-26 12:55:37 +02:00
|
|
|
|
|
|
|
def parse(program_version, protocol_version):
|
|
|
|
"""
|
|
|
|
Parses comand line arguments
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description = "The server side of the "\
|
|
|
|
"aliased server remote control",
|
|
|
|
add_help = False)
|
|
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--help",
|
|
|
|
action = "help",
|
|
|
|
help = "show this help message and exit")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--version",
|
|
|
|
action = "version",
|
|
|
|
version = "Server version: " + program_version +\
|
|
|
|
" / Protocol version: " + protocol_version)
|
|
|
|
|
|
|
|
grp_pid_file_failure = parser.add_mutually_exclusive_group()
|
|
|
|
grp_pid_file_failure.add_argument(
|
|
|
|
"-n",
|
|
|
|
"--delete-pid-file",
|
|
|
|
action = "store_true",
|
|
|
|
help = "deletes the pid file and starts the server")
|
|
|
|
|
|
|
|
grp_pid_file_failure.add_argument(
|
|
|
|
"-m",
|
|
|
|
"--allow-multiple-instances",
|
|
|
|
action = "store_true",
|
|
|
|
help = "ignores the pid file and starts the server. "\
|
|
|
|
"Will not create another pid file.")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-v",
|
|
|
|
"--verbosity",
|
|
|
|
type = int,
|
|
|
|
choices = range(0, 4),
|
|
|
|
help = "increase output verbosity. Can be from 0 "\
|
|
|
|
"(only default output) to 3 (debug messages).")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-h",
|
|
|
|
"--host",
|
|
|
|
help = "IP or hostname (use 0.0.0.0 for all interfaces) on which "\
|
|
|
|
"the server should listen")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-p",
|
|
|
|
"--port",
|
|
|
|
help = "the port on which the server should listen")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-t",
|
|
|
|
"--timeout",
|
|
|
|
help = "timeout of a connection in seconds - still "\
|
|
|
|
"doesn't work obviously...")
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-e",
|
|
|
|
"--encoding",
|
|
|
|
help = "encoding to be used when communicating with clients")
|
|
|
|
|
2013-06-25 11:51:19 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--mkpasswd",
|
|
|
|
action = "store_true",
|
|
|
|
help = "encode a password with SHA512")
|
|
|
|
|
2013-04-26 12:55:37 +02:00
|
|
|
return parser.parse_args()
|