From 79a5d8a12a0fe73de1eaa0fe4203769de3c78b6e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 15 Feb 2015 14:55:43 -0700 Subject: [PATCH] tools,frontend: common network arguments --- artiq/frontend/artiq_master.py | 7 ++++--- artiq/frontend/lda_controller.py | 7 ++----- artiq/frontend/pdq2_controller.py | 8 ++------ artiq/tools.py | 8 ++++++++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index c9e7f6f86..32a8c1000 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -16,13 +16,14 @@ from artiq.tools import verbosity_args, init_logger def get_argparser(): parser = argparse.ArgumentParser(description="ARTIQ master") - parser.add_argument( + group = parser.add_argument_group("network") + group.add_argument( "--bind", default="::1", help="hostname or IP address to bind to") - parser.add_argument( + group.add_argument( "--port-notify", default=3250, type=int, help="TCP port to listen to for notifications") - parser.add_argument( + group.add_argument( "--port-control", default=3251, type=int, help="TCP port to listen to for control") verbosity_args(parser) diff --git a/artiq/frontend/lda_controller.py b/artiq/frontend/lda_controller.py index 65ebfaf1a..e96151bab 100755 --- a/artiq/frontend/lda_controller.py +++ b/artiq/frontend/lda_controller.py @@ -4,17 +4,14 @@ import argparse from artiq.devices.lda.driver import Lda, Ldasim from artiq.protocols.pc_rpc import simple_server_loop -from artiq.tools import verbosity_args, init_logger +from artiq.tools import verbosity_args, simple_network_args, init_logger def get_argparser(): parser = argparse.ArgumentParser() parser.add_argument('-d', '--device', default="LDA-102", choices=["LDA-102", "LDA-602", "sim"]) - parser.add_argument('--bind', default="::1", - help="hostname or IP address to bind to") - parser.add_argument('-p', '--port', default=3253, type=int, - help="TCP port to listen to") + simple_network_args(parser, 3253) parser.add_argument('-s', '--serial', default=None, help="USB serial number of the device") verbosity_args(parser) diff --git a/artiq/frontend/pdq2_controller.py b/artiq/frontend/pdq2_controller.py index dd86de0ce..8885b2d04 100755 --- a/artiq/frontend/pdq2_controller.py +++ b/artiq/frontend/pdq2_controller.py @@ -4,15 +4,12 @@ import argparse from artiq.devices.pdq2.driver import Pdq2 from artiq.protocols.pc_rpc import simple_server_loop -from artiq.tools import verbosity_args, init_logger +from artiq.tools import verbosity_args, init_logger, simple_network_args def get_argparser(): parser = argparse.ArgumentParser(description="PDQ2 controller") - parser.add_argument("--bind", default="::1", - help="hostname or IP address to bind to") - parser.add_argument("-p", "--port", default=3252, type=int, - help="TCP port to listen to") + simple_network_args(parser, 3252) parser.add_argument( "-s", "--serial", default=None, help="device (FT245R) serial string [first]") @@ -25,7 +22,6 @@ def get_argparser(): def main(): args = get_argparser().parse_args() - init_logger(args) dev = Pdq2(serial=args.serial) diff --git a/artiq/tools.py b/artiq/tools.py index 384ae9f09..f8e5a24b7 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -38,5 +38,13 @@ def verbosity_args(parser): help="decrease logging level") +def simple_network_args(parser, default_port): + group = parser.add_argument_group("network") + group.add_argument("--bind", default="::1", + help="hostname or IP address to bind to") + group.add_argument("-p", "--port", default=default_port, type=int, + help="TCP port to listen to") + + def init_logger(args): logging.basicConfig(level=logging.WARNING + args.quiet*10 - args.verbose*10)