Commit bebc7105 authored by Leon Riesebos's avatar Leon Riesebos
Browse files

introduced format specifiers for argparse

parent d62c7e1d
Pipeline #340993323 passed with stage
in 2 minutes and 47 seconds
......@@ -20,7 +20,7 @@ def get_argparser() -> argparse.ArgumentParser:
default_baud_rate = max(Agilent3631PowerSupply.VALID_BAUD_RATES)
parser.add_argument("--baudrate", type=int, default=default_baud_rate,
choices=sorted(Agilent3631PowerSupply.VALID_BAUD_RATES),
help=f"Connection baud rate (default: {default_baud_rate})")
help="Connection baud rate (default: %(default)s)")
parser.add_argument("--bypass-remote-mode", action="store_true", help="Bypass setting device in remote mode")
parser.add_argument("-s", "--simulation", action="store_true",
help="Run in simulation mode")
......
......@@ -18,7 +18,7 @@ def get_argparser() -> argparse.ArgumentParser:
parser.add_argument("device", type=str,
help="Serial device to use, e.g. 'COMxx' on Windows or '/dev/ttyUSBx' on Linux")
parser.add_argument("--baudrate", type=int, default=ButtonPresserDriver.DEFAULT_BAUD_RATE,
help=f"Connection baud rate (default: {ButtonPresserDriver.DEFAULT_BAUD_RATE})")
help="Connection baud rate (default: %(default)s)")
parser.add_argument("-s", "--simulation", action="store_true",
help="Run in simulation mode")
return parser
......
......@@ -16,7 +16,7 @@ def get_argparser() -> argparse.ArgumentParser:
simple_network_args(parser, 3283)
verbosity_args(parser) # This adds the -q and -v handling
parser.add_argument("--config", default="paladin_config.json", type=str,
help="Config file for paladin controller")
help="Config file for paladin controller (default: %(default)s)")
parser.add_argument("-s", "--simulation", action="store_true",
help="Run in simulation mode")
return parser
......
......@@ -16,7 +16,7 @@ def get_argparser() -> argparse.ArgumentParser:
simple_network_args(parser, 3283)
verbosity_args(parser) # This adds the -q and -v handling
parser.add_argument("--config", default="paladin_config.json", type=str,
help="Config file for paladin controller")
help="Config file for paladin controller (default: %(default)s)")
parser.add_argument("-s", "--simulation", action="store_true",
help="Run in simulation mode")
return parser
......
......@@ -18,22 +18,22 @@ def get_argparser() -> argparse.ArgumentParser:
parser.add_argument("address", type=str,
help="IP address of the signal generator")
parser.add_argument("--device-port", type=int, default=SMC100.DEFAULT_PORT,
help=f"TCP port of the signal generator (default: {SMC100.DEFAULT_PORT})")
help="TCP port of the signal generator (default: %(default)s)")
parser.add_argument("--slope", type=float, default=SMC100.DEFAULT_SLOPE,
help=f"ramp slope in dbm/s (default: {SMC100.DEFAULT_SLOPE} dbm/s)")
help="ramp slope in dbm/s (default: %(default)s} dbm/s)")
parser.add_argument("--cutoff", type=float, default=SMC100.DEFAULT_CUTOFF,
help=f"cutoff power level (default: {SMC100.DEFAULT_CUTOFF} dbm)")
help="cutoff power level (default: %(default)s dbm)")
parser.add_argument("--offset", type=float, default=SMC100.DEFAULT_OFFSET,
help=f"power offset (default: {SMC100.DEFAULT_OFFSET} dbm)")
help="power offset (default: %(default)s dbm)")
limit = parser.add_mutually_exclusive_group()
limit.add_argument("--limit-level", type=float, default=None,
help=f"power level limit, includes offset (default: {SMC100.DEFAULT_LIMIT} dbm)")
limit.add_argument("--limit-power", type=float, default=None,
help="power limit, without offset")
parser.add_argument("--freq-step-limit", type=float, default=SMC100.DEFAULT_FREQ_STEP_LIMIT,
help=f"frequency step limit (default: {SMC100.DEFAULT_FREQ_STEP_LIMIT} Hz)")
help="frequency step limit (default: %(default)s Hz)")
parser.add_argument("--ref-osc-src", choices=SMC100.REF_OSC_SRC, default=SMC100.DEFAULT_REF_OSC_SRC,
help=f"reference oscillator source (default: {SMC100.DEFAULT_REF_OSC_SRC})")
help="reference oscillator source (default: %(default)s)")
parser.add_argument("-s", "--simulation", action="store_true",
help="run in simulation mode")
return parser
......
......@@ -16,10 +16,9 @@ def get_argparser() -> argparse.ArgumentParser:
simple_network_args(parser, 3284)
verbosity_args(parser) # This adds the -q and -v handling
parser.add_argument("--device-host", type=str, default=SpectronixDriver.DEFAULT_IP,
help=f"host name of the device (default: {SpectronixDriver.DEFAULT_IP})")
help="host name of the device (default: %(default)s)")
parser.add_argument("--device-port", type=int, default=SpectronixDriver.DEFAULT_PORT,
help=f"port number for the network communication to the device "
f"(default: {SpectronixDriver.DEFAULT_PORT})")
help="port number for the network communication to the device (default: %(default)s)")
parser.add_argument("-s", "--simulation", action="store_true",
help="Run in simulation mode")
return parser
......
......@@ -144,15 +144,15 @@ def _get_args() -> argparse.Namespace:
group = parser.add_argument_group('Core device')
group.add_argument('port', type=str, help='Serial port to connect to')
group.add_argument('--baud-rate', type=baud_rate, default=CoreLogger.DEFAULT_BAUD_RATE,
help=f'Baud rate (default: {CoreLogger.DEFAULT_BAUD_RATE})')
help='Baud rate (default: %(default)s)')
group = parser.add_argument_group('Output')
group.add_argument('--output-dir', type=str, default=CoreLogger.DEFAULT_OUTPUT_DIR,
help=f'Output directory (default: "{CoreLogger.DEFAULT_OUTPUT_DIR}")')
help='Output directory (default: "%(default)s")')
group = parser.add_argument_group('Connection')
group.add_argument('--reconnect-delay', type=positive_float, default=CoreLogger.DEFAULT_RECONNECT_DELAY,
help=f'Delay before reconnecting in seconds (default: {CoreLogger.DEFAULT_RECONNECT_DELAY})')
help='Delay before reconnecting in seconds (default: %(default)s)')
# Add standard arguments
dax_comtools.util.args.logger_args(parser)
......
......@@ -15,9 +15,9 @@ from dax_comtools.util.args import influx_args, get_influx_args, monitoring_tags
def get_argparser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Montana Instruments CryoStation reader for InfluxDb")
parser.add_argument("-i", "--ip", type=str, default='localhost',
help="IP address of the CryoStation laptop (default: localhost)")
help="IP address of the CryoStation laptop (default: %(default)s)")
parser.add_argument("-p", "--port", type=int, default=CryoComm.DEFAULT_PORT,
help=f"Port to connect to (default: {CryoComm.DEFAULT_PORT})")
help="Port to connect to (default: %(default)s)")
parser.add_argument('--dry-run', '-n', action='store_true', help='Read data but do not write to influx DB')
logger_args(parser)
......
......@@ -225,13 +225,13 @@ def _get_args() -> argparse.Namespace:
group = parser.add_argument_group('Stream configuration')
group.add_argument('--ch1', '-1', action='store_true', help='Enable input channel 1')
group.add_argument('--ch2', '-2', action='store_true', help='Enable input channel 2')
group.add_argument('--sample-rate', type=int, default=10, help='Data sample rate in Hz (default: 10)')
group.add_argument('--sample-rate', type=int, default=10, help='Data sample rate in Hz (default: %(default)s)')
group.add_argument('--duration', type=int, default=0,
help='Streaming duration in seconds, 0 for infinite stream (default: 0)')
help='Streaming duration in seconds, 0 for infinite stream (default: %(default)s)')
group = parser.add_argument_group('Advanced settings')
group.add_argument('--progress', action='store_true', help='Print periodic progress messages (INFO level)')
group.add_argument('--buffer_size', type=int, default=15, help='The buffer size in seconds (default: 15)')
group.add_argument('--buffer_size', type=int, default=15, help='The buffer size in seconds (default: %(default)s)')
group.add_argument('--timeout', type=int, default=None, help='Connection timeout when streaming data in seconds')
group.add_argument('--latency-compensation', type=float, default=0.0,
help='Compensation for latency between starting the capture and fixing the timestamp')
......
......@@ -500,11 +500,12 @@ _PLOT_PANEL: typing.Dict[str, typing.Any] = {
def get_argparser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Tool to generate a Grafana dashboard from the sensor JSON file."
parser = argparse.ArgumentParser(description="Tool to generate a Grafana dashboard from the sensor JSON file. "
"Outputs a JSON dashboard model that can be imported in Grafana.")
parser.add_argument("sensor_file", type=str, help="Path to JSON file used with dct_sensorpush_to_influx")
parser.add_argument("--output-file", type=str, default="dashboard.json", help="Output file, defaults to "
"dashboard.json")
parser.add_argument("sensor_file", type=str,
help="Path to JSON file used with dct_sensorpush_to_influx")
parser.add_argument("--output-file", type=str, default="dashboard.json",
help="Output file (default: %(default)s)")
return parser
......
......@@ -210,10 +210,11 @@ def get_argparser() -> argparse.ArgumentParser:
", the most recent samples will be retrieved.")
sp.add_argument("--stop-time", type=str, help="End of period over which to retrieve samples. If not provided"
", the most recent samples will be retrieved.")
sp.add_argument("--limit", type=int, default=10, help="Number of samples to retrieve")
sp.add_argument("--limit", type=int, default=10, help="Number of samples to retrieve (default: %(default)s)")
other = parser.add_argument_group("Other options")
other.add_argument("--buffer-size", type=int, default=10000, help='The buffer size for writes to InfluxDB')
other.add_argument("--buffer-size", type=int, default=10000,
help='The buffer size for writes to InfluxDB (default: %(default)s)')
return parser
......
......@@ -17,7 +17,7 @@ def get_argparser() -> argparse.ArgumentParser:
# Arguments
sht2x = parser.add_argument_group('SHT2x arguments')
sht2x.add_argument('i2c', default='/dev/i2c-1', type=str, help='Path to the I2C bus (e.g. "/dev/i2c-1")')
sht2x.add_argument('i2c', default='/dev/i2c-1', type=str, help='Path to the I2C bus (default: "%(default)s")')
sht2x.add_argument('--no-soft-reset', action='store_false',
help='Do not reboot the sensor system and reset to default configuration before measuring')
parser.add_argument('--dry-run', '-n', action='store_true', help='Read data but do not write to influx DB')
......
......@@ -12,15 +12,15 @@ def influx_args(parser: argparse.ArgumentParser) -> None:
"""Add connection arguments for InfluxDB."""
idb = parser.add_argument_group("InfluxDB arguments")
idb.add_argument("--db", type=str, default="dax_data_store",
help="Database name (default: dax_data_store)")
help="Database name (default: %(default)s)")
idb.add_argument("--server-db", type=str, default="localhost",
help="IP address of InfluxDB server (default: localhost)")
help="IP address of InfluxDB server (default: %(default)s)")
idb.add_argument("--port-db", type=int, default=8086,
help="Port for InfluxDB HTTP Server (default: 8086)")
help="Port for InfluxDB HTTP Server (default: %(default)s)")
idb.add_argument("--user-db", type=str, default="root",
help="User name for InfluxDB (default: root)")
help="User name for InfluxDB (default: %(default)s)")
idb.add_argument("--password-db", type=str, default="root",
help="Password for InfluxDB (default: root)")
help="Password for InfluxDB (default: %(default)s)")
def get_influx_args(args: argparse.Namespace) -> typing.Dict[str, typing.Any]:
......
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