luxos.cli.flags#
a collection of argparse type_* and ‘add_arguments_*’ functions
This is a collection of functions can be used with argparser add_argumnet and parser.
Eg.:
# this will validate the `-x` value as HH:MM to datetime.time
parser.add_argument("-x", type=type_hhmm)
Or:
# this will add few arguments to the parser
add_arguments_rexec(parser)
- luxos.cli.flags.add_arguments_config(parser: LuxosParserBase)#
- luxos.cli.flags.add_arguments_database(parser: LuxosParserBase)#
takes a string on a command line and retunr a sa engine.
This is mean to be used as type in add_arguments
args.engine = firmware.cli.process_engine(args.engine)
The text format can be: - a string that will resolve into a Path - any string for sqlalchemy.engine.url.make_url
In the first case a sqlite engine pointing to text Path will be returned, in the second a regular engine.
Example:#
>>> process_engine("foobar.db") >>> process_engine("postgresql+psycopg2://<user>:<password>@<host>/<db>"
- luxos.cli.flags.add_arguments_logging(parser: LuxosParserBase)#
- luxos.cli.flags.add_arguments_new_miners_ips(parser: LuxosParserBase)#
- luxos.cli.flags.add_arguments_rexec(parser: LuxosParserBase)#
adds the rexec timing for timeout/retries/delays
Ex.
- def add_arguments(parser):
cli.flags.add_arguments_rexec(parser)
- def process_args(args):
asyncops.TIMEOUT = args.timeout asyncops.RETRIES = args.retries asyncops.RETRIES_DELAY = args.retries_delay return args
- class luxos.cli.flags.type_database(default=<class 'luxos.cli.shared.ArgumentTypeBase._NA'>)#
Bases:
ArgumentTypeBase
Validate a type as a database string (sqlalchemy)
- Raises:
argparse.ArgumentTypeError – on an invalid input.
- Returns:
datetime.time or None
Example
file.py:
parser.add_argument("-x", type=type_database) options = parser.parse_args() ... assert options.x == sqlalchemy.Engine
shell:
file.py -x sqlite:///foobar.db file.py -x postgresql+psycopg2://<user>:<password>@<host>/<db>
- validate(txt) Any #
- class luxos.cli.flags.type_hhmm(default=<class 'luxos.cli.shared.ArgumentTypeBase._NA'>)#
Bases:
ArgumentTypeBase
Validate a type as a datetime.time in HH:MM format
- Raises:
argparse.ArgumentTypeError – on an invalid input.
- Returns:
datetime.time or None
Example
file.py:
parser.add_argument("-x", type=type_hhmm) options = parser.parse_args() ... assert options.x == datetime.time(12, 13)
shell:
file.py -x 12:13
- validate(txt) None | time #
- class luxos.cli.flags.type_ipaddress(default=<class 'luxos.cli.shared.ArgumentTypeBase._NA'>)#
Bases:
ArgumentTypeBase
Validate a type as an ip addresses.
- Raises:
argparse.ArgumentTypeError – on an invalid input.
- Returns:
tuple[str, None | int] or None
Example
file.py:
parser.add_argument("-x", type=type_ipaddress) options = parser.parse_args() ... assert options.x == ("host", 9999)
shell:
file.py -x host:9999
- validate(txt) None | tuple[str, None | int] #
- luxos.cli.flags.type_range(txt: str) Sequence[tuple[str, int | None]] #
Validate a range of ip addresses.
- Raises:
argparse.ArgumentTypeError – on an invalid input.
- Returns:
Sequence[tuple[str, int | None]]
Example
file.py:
parser.add_argument("-x", type=type_range) options = parser.parse_args() ... assert options.x == [ ("127.0.0.1", 9999), ("127.0.0.2", 9999), ("127.0.0.3", 9999), ]
shell:
file.py -x 127.0.0.1:9999:127.0.0.3
Alternatively you can pass a @filename to read data from a csv file