1 from plomrogue.io_websocket import PlomWebSocketServer
2 from plomrogue.io_tcp import PlomTCPServer, PlomTCPServerSSL
3 from plomrogue.errors import ArgError
5 def parse_command_line_arguments():
7 parser = argparse.ArgumentParser()
8 parser.add_argument('savefile')
9 parser.add_argument('--server-type', nargs='+', required=True,
10 choices=['tcp', 'tcp_ssl', 'ws'])
11 parser.add_argument('--port', nargs='+', required=True, type=int)
12 parser.add_argument('--keyfile')
13 parser.add_argument('--certfile')
14 opts = parser.parse_args()
15 if len(opts.server_type) != len(opts.port):
16 raise ArgError('number of ports unequal to number of server types')
17 if 'tcp_ssl' in opts.server_type and not (opts.keyfile or opts.certfile):
18 raise ArgError('need key and cert file for tcp_ssl server')
20 'savefile': opts.savefile,
22 'keyfile': opts.keyfile,
23 'certfile': opts.certfile,
25 for i in range(len(opts.port)):
26 server_type = opts.server_type[i]
27 if server_type == 'ws':
28 config['servers'][opts.port[i]] = PlomWebSocketServer
29 elif server_type == 'tcp':
30 config['servers'][opts.port[i]] = PlomTCPServer
31 elif server_type == 'tcp_ssl':
32 config['servers'][opts.port[i]] = PlomTCPServerSSL
35 config = parse_command_line_arguments()