GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

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

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:
* msgpack_numpy
TODO
----
- Improve `handel-server` using argparse.
Contact
-------
......
......@@ -16,7 +16,7 @@ Test on the client machine using:
# Imports
import sys
import argparse
import zerorpc
import msgpack_numpy
......@@ -24,12 +24,6 @@ import msgpack_numpy
import handel.gevent
import handel.interface as hi
# Patching
handel.gevent.patch()
msgpack_numpy.patch()
# Run server
def run(bind='0.0.0.0', port=8000):
......@@ -49,15 +43,28 @@ def run(bind='0.0.0.0', port=8000):
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
def main(args=None):
if args is None:
args = sys.argv
if len(args) > 1:
run(port=int(args[1]))
else:
run()
namespace = parse_args(args)
handel.gevent.patch()
msgpack_numpy.patch()
run(namespace.bind, namespace.port)
if __name__ == '__main__':
......
Markdown is supported
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