get_opts

opthandler.get_opts(argparser, conf_file='hpcssrc.ini', secs_known=None, secs_unknown='sbatch', create_missing_secs=True, ignore_unknown_opts=True, convert=True, **kwargs)[source]

Gather all options from command line and Configuration File.

Gather all options given via the command-line interface and via a config file, merge them and return them in one dictionary.

Options explicitly given via the command-line interface take precedence over options specified in the config file. Options specified in the config file take precedence over default values of the command-line interface.

Parameters:
  • argparser (argparse.ArgumentParser) – The ArgumentParser instance that implements the command-line interface. Note: All possible command-line arguments must be contained in the Namespace, i.e. not-given arguments must not be suppressed with argparse.SUPPRESS.

  • conf_file (str, optional) – The name of the Configuration File.

  • secs_known (list or tuple or str or None, optional) – Sections of the config file that contain options that can also be specified via the command-line interface (“known” to argparser). If None, use all sections. The options of all known sections will be merged into one sub-dictionary. Options that are given in multiple sections take precedence over each other in reverse order as they appear in secs_known. This means, options in the last given section have the highest preference and options in the first given section have the lowest preference.

  • secs_unknown (list or tuple or str or None, optional) – Sections of the config file that contain options that cannot be specified via the command-line interface (“unknown” to argparser), but that should still be parsed to the calling script. If you don’t have such sections, set secs_unknown to None. The options of all unknown sections will be merged into one sub-dictionary. Options that are given in multiple sections take precedence over each other in reverse order as they appear in secs_unknown (see secs_known).

  • create_missing_secs (bool, optional) – If True, don’t raise an exception if a given section is not contained in the config file but instead create the section (and leave it empty).

  • ignore_unknown_opts (bool, optional) – If True, don’t raise an exception if any option in the given known sections (secs_known) is unknown to argparser, but instead simply ignore it.

  • convert (bool, optional) – If True, apply convert_str() to the values of all config-file options and all unknown options. This will convert strings to their corresponding Python data types. If False, all config-file options and all unknown options will be parsed as strings.

  • kwargs (dict, optional) – Keyword arguments to parse to convert_str().

Returns:

options (dict of dict) – A dictionary of two dictionaries. The first key (given by the first known section in sections) contains as value a sub-dictionary of all known options and their respective values. The second key (given by sec_unknown) contains as value a dictionary of all unknown options and their respective values.

See also

argparse.ArgumentParser.parse_known_args()

Get known and unknown options from the command-line interface

Notes

Known options

Options that can also be parsed via the command-line interface (i.e. options that are known to the input ArgumentParser).

Unknown options

Options that are not contained in the Namespace of the input ArgumentParser (i.e. options that are unknown to the input ArgumentParser).