Commit 982e67fd authored by Vincent Michel's avatar Vincent Michel
Browse files

Improve handel-server using argparse

parent 45679f35
Pipeline #1342 passed with stages
in 1 minute and 22 seconds
...@@ -112,12 +112,6 @@ A few scripts are provided: ...@@ -112,12 +112,6 @@ A few scripts are provided:
* msgpack_numpy * msgpack_numpy
TODO
----
- Improve `handel-server` using argparse.
Contact Contact
------- -------
......
...@@ -16,7 +16,7 @@ Test on the client machine using: ...@@ -16,7 +16,7 @@ Test on the client machine using:
# Imports # Imports
import sys import argparse
import zerorpc import zerorpc
import msgpack_numpy import msgpack_numpy
...@@ -24,12 +24,6 @@ import msgpack_numpy ...@@ -24,12 +24,6 @@ import msgpack_numpy
import handel.gevent import handel.gevent
import handel.interface as hi import handel.interface as hi
# Patching
handel.gevent.patch()
msgpack_numpy.patch()
# Run server # Run server
def run(bind='0.0.0.0', port=8000): def run(bind='0.0.0.0', port=8000):
...@@ -49,15 +43,28 @@ def run(bind='0.0.0.0', port=8000): ...@@ -49,15 +43,28 @@ def run(bind='0.0.0.0', port=8000):
hi.exit() hi.exit()
# Parsing
def parse_args(args=None):
parser = argparse.ArgumentParser(
prog='handel-server',
description='Serve the handel interface over the network using zerorpc')
parser.add_argument(
'--bind', '-b', default='', metavar='address',
help='Specify alternate bind address [default: all interfaces]')
parser.add_argument(
'port', action='store', default=8000, type=int, nargs='?',
help='Specify alternate port [default: 8000]')
return parser.parse_args(args)
# Main function # Main function
def main(args=None): def main(args=None):
if args is None: namespace = parse_args(args)
args = sys.argv handel.gevent.patch()
if len(args) > 1: msgpack_numpy.patch()
run(port=int(args[1])) run(namespace.bind, namespace.port)
else:
run()
if __name__ == '__main__': if __name__ == '__main__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment