The parser module

The parser module contains the OptionsParser class which provides the ability to parse a configuration file and command line given a set of available options.

.

The ConfigFile class

Inheritance diagram of pyamp.config.parser.ConfigFile

class pyamp.config.parser.ConfigFile(configurationFile=None, options=None, variables=None, logger=None)

The ConfigFile class is responsible for parsing a configuration file with the given dictionary of sections and options, and variables.

The ConfigFile class takes a dictionary of options which map the configuration section names to the list of configuration Option objects associated with that section. It also takes a dictionary of variables mapping the name of the variable to the value for the variable. The variable names can then be used in a configuration file by adding a $ before the variable name. This value will then be replaced with the value assigned in the variables dictionary.

This class implements the Loggable interface. This class uses the ConfigParser module to parse the configuration file, and thus parses configuration files of the same format.

  • configurationFile – The configuration file to load
  • options – The dictionary of supported options
  • variables – The dictionary of supported variables
  • logger – The logger
get(section, option, defaultValue=None)

Get the value of the given configuration option from the given section.

  • section – The section name
  • option – The option
  • defaultValue – The default value if the option does not exist
getSettings()

Get the settings dictionary.

parse(filename)

Parse a configuration file.

  • filename – The configuration file to parse

The OptionsParser class

Inheritance diagram of pyamp.config.parser.OptionsParser

class pyamp.config.parser.OptionsParser(*args, **kwargs)[source]

The OptionsParser class is responsible for parsing command line and configuration file options and providing the ability to get the value of a given option.

This class implements the pyamp.patterns.Borg design pattern and also implements the pyamp.logging.Loggable interface.

  • args – The arguments
  • kwargs – The keyword arguments
ClOptions

This property contains the list of options that are only configurable via the command line.

Options

This property contains a dictionary mapping section names to the list of options contained within that section. Options must be a subclass of the Option class. These are the sections and options that will be loaded from the configuration file and the command line arguments.

Note

Any ClOption objects that are given will be configurable via the configuration file and from the command line.

Variables

This property contains a dictionary mapping variable names to their respective values. These variables can be used within the configuration file and will be replaced by the assigned values.

Variables can be used in the configuration file by appending a dollar sign before the name of the variable. The variable will then replaced with its value prior to parsing the file.

Example:

# $HOME will be replaced with the user's home directory before parsing
[Section]
Var = $HOME
classmethod get(section, optionName, defaultValue=None)[source]

Get the value of an option from the given section.

  • section – The name of the section
  • optionName – The name of the option
  • defaultValue – The default value if the option does not exist
classmethod getCl(optionName, defaultValue=None)[source]

Get the value of a command line option.

  • optionName – The name of the command line option
  • defaultValue – The default value if the option does not exist
init(logger=None)[source]

Override the pyamp.patterns.Borg init function.

parse(argv, filename)[source]

Parse the command line options, and the configuration file.

  • argv – The command line options
  • filename – The path to the configuration file
setLogger(logger, color=0)[source]

Set the logger for the OptionsParser.

Table Of Contents

Previous topic

The configFile module

Next topic

The conversions module

This Page