1
0
Fork 0

- cleaned class argparser

- commented and cleaned asrc-server.py
- renamed includes/content.py to includes/comm.py
- renamed class content to comm
- made some vars (aliases, server_version, protocol_version, verbiosity) global in class comm
- added init() to class comm for setting lobal vars
- moved motd() from asrc-server-py to class comm
- conformed comm.motd() to reference
- added comm.header() for building the headers
- added includes/statuscodes.py with class statuscodes with dict description for storing the status codes and their description
- added docstrings
This commit is contained in:
fanir 2013-04-26 12:55:37 +02:00
parent fbb4653740
commit 1207c6b225
6 changed files with 306 additions and 297 deletions

View file

@ -1,2 +1,2 @@
from .argparser import argparser
from .content import content
from .comm import comm

View file

@ -1,78 +1,77 @@
# includes/argparser.py
#
# module version: 1.0.20130424
# module version: 1.0.20130425
#
class argparser:
def parse(program_version, protocol_version):
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),
# default = -1,
help = "increase output verbosity. Can be from 0 "\
"(only default output) to 3 (debug messages).")
parser.add_argument(
"-h",
"--host",
# default = -1,
help = "IP or hostname (use 0.0.0.0 for all interfaces) on which "\
"the server should listen")
parser.add_argument(
"-p",
"--port",
# default = -1,
help = "the port on which the server should listen")
parser.add_argument(
"-t",
"--timeout",
# default = -1,
help = "timeout of a connection in seconds - still "\
"doesn't work obviously...")
parser.add_argument(
"-e",
"--encoding",
# default = -1,
help = "encoding to be used when communicating with clients")
return parser.parse_args()
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")
return parser.parse_args()

View file

@ -1,18 +1,59 @@
# includes/content.py
# includes/comm.py
#
# module version: 0.0.20130424
# module version: 0.0.20130426
#
class content:
import statuscodes
class comm:
# handler the content
def handler(client_address, data, aliases, server_version, protocol_version, verbosity):
ret = ""
aliases = dict()
server_version = ""
protocol_version = ""
verbosity = 0
# initializes global settings
def init(ServerVersion, ProtocolVersion, Verbosity, Aliases):
ret = ret +\
aliases = Aliases
server_version = ServerVersion
protocol_version = ProtocolVersion
verbosity = Verbosity
def header(statuscode, AdditionalHeaderLines = ""):
"""
returns the header
"""
ret =\
"{BEGIN}\n"\
"asrcp" + protocol_version + "\n"
"asrcp" + protocol_version + "\n"\
statuscode + " " + statuscodes.description[statuscodes] + "\n"\
"ServerVersion:" + server_version + "\n"
if AdditionalHeaderLines != "": ret += AdditionalHeaderLines + "\n"
ret += "\n\n"
return ret
# returns the motd
def motd(motd):
"""
builds and returns a motd package
"""
ret = motd
return ret
# handles the content
def command(client_address, data):
"""
processes a command
"""
ret = ""
# Look if the received message is an
# valid alias or a predefined command

37
include/statuscodes.py Normal file
View file

@ -0,0 +1,37 @@
class statuscodes:
description = dict(
# 000 - 400 server side
# 000 information
001 = "OK",
002 = "Version",
003 = "MOTD",
# 100 authentication and maintenance
101 = "Challenge",
102 = "Success",
103 = "Failure",
104 = "To Many Tries",
# 200 command
201 = "Valid",
202 = "Valid Service Command",
203 = "Invalid",
204 = "Failure",
205 = "Continue",
# 300 server
301 = "Unhandled Exception",
302 = "Shutting Down",
303 = "Restarting",
304 = "Encoding Error",
305 = "SSL Error",
# 500 - 900 client side
# 500 information
501 = "OK",
502 = "Version",
# 600 authentication and maintenance
601 = "Response",
602 = "Failure",
# 700 command
701 = "Reqiuest",
702 = "Cancel",
# 800 client
801 = "SSL Error"
)