scenario.args module¶
Base module for program arguments management.
Args.getinstance() gives the only only instance of program arguments,
May actually be a scenarioargs.ExecArgs or a CampaignArgs instance.
- class Args¶
Bases:
Logger,CommonConfigArgs,CommonLoggingArgsCommon program arguments management.
Handles:
--helpoption,Configuration file options,
Logging options.
- static setinstance(instance, warn_reset=True)¶
Sets the main instance of
Args.- Parameters:
instance –
Argsinstance.warn_reset – Set to
Falsein order to avoid the warning to be logged.
When consecutive calls occur, the latest overwrites the previous, and a warning is displayed unless
warn_resetis set toFalse.
- classmethod getinstance()¶
Singleton.
- Returns:
Main
Argsinstance.
Warning
The main
Argsinstance is not created automatically by this method, and should be set withsetinstance()prior to anygetinstance()call.
- classmethod isset()¶
Checks whether the single instance of
Argsis set and of theclstype.- Parameters:
cls – Expected type.
- Returns:
Trueif the singleArgsinstance is of the given type,Falseotherwise.
- __init__(class_debugging)¶
Defines common program arguments.
- Parameters:
class_debugging – See
CommonLoggingArgs.
- __arg_parser¶
argparseparser object.
- __arg_infos¶
Arguments information.
- parsed¶
Parsed flag. Tells whether arguments have been successfully parsed yet or not.
- error_code¶
Argument parsing error code.
- setprog(name)¶
Overwrites program name.
- Parameters:
name – Program name to be displayed with usage info.
- setdescription(description)¶
Overwrites program description.
- Parameters:
description – Program description to be displayed with usage info.
- addarg(member_desc, member_name, member_type)¶
Adds a program argument.
- Parameters:
member_desc – Textual description of the program argument(s).
member_name – Corresponding member name in the owner
Argsinstance.member_type – Type of the program argument, or base type of the program arguments list, or conversion handler. When defined as a 2 items tuple, the argument feeds a dictionary: the first item of the tuple shall be
str(for the dictionary keys), and the second item gives the type of the dictionary values.
- Returns:
Args.ArgInfoinstance whoseArgInfo.define()should be called onto.
ArgInfo.define()should be called on theArgInfoobject returned:self.addarg("Configuration files", "config_paths", Path).define( "--config-file", metavar="CONFIG_PATH", action="append", type=str, default=[], help="Input configuration file path. " "This option may be called several times.", )
- parse(args)¶
Parses program arguments.
- Parameters:
args – Argument list, without the program name.
- Returns:
Truefor success,Falseotherwise.
- _checkargs(args)¶
Handler for special verifications on program arguments.
- Parameters:
args – The untyped object returned by
argparse.ArgumentParser.parse_args().- Returns:
Truefor success,Falseotherwise.
Shall be overridden in subclasses.
- class ArgInfo¶
Bases:
objectClass that describes a single program argument (single value, list or dictionary).
Whether the program argument is a single value, or a list of value, depends on the
argparsedefinition made throughArgInfo.define().- __init__(arg_parser, member_desc, member_name, member_type)¶
- Parameters:
arg_parser – Related
argparse.ArgumentParserinstance.member_desc – Textual description of the program argument(s).
member_name – Corresponding member name in the owner
Argsinstance.member_type – Base type of the program argument(s). See
Args.addarg()for a detailed description of this parameter.
Args.ArgInfo.define()should be called onto eachArgs.ArgInfoinstance newly created.See also
Args.addarg(),Args.ArgInfo.define()
- arg_parser¶
Related
argparse.ArgumentParserinstance.
- member_desc¶
Textual description of the program argument(s).
- key_type¶
Key type, when the argument feeds a dictionary.
- value_type¶
Base type of the program argument(s).
- parser_arg¶
argparse.Actioninstance defined by theArgs.ArgInfo.define()method.
- define(*args, **kwargs)¶
Defines the
argparsecommand line argument.- Parameters:
args – List of positional arguments.
kwargs – Dictionary of named arguments.
Refer to the regular
argparsedocumentation, except for thedestparameter which should not be set. TheArgs.ArgInfo.member_namemember will be used for the purpose.Should be called on the
Args.ArgInforeturned theArgs.addarg()method.See also