opgee.config

See the configuration system page for a detailed description of available configuration variables. This page documents the API to the configuration system.

API

opgee.config.ensure_default_config()

Check that config file exists or create default one.

opgee.config.getConfig(reload=False, allowMissing=False, createDefault=False, systemConfigOnly=False)

Return the configuration object. If one has been created already via readConfigFiles, it is returned; otherwise a new one is created and the configuration files are read. Applications generally do not need to use this object directly since the single instance is stored internally and referenced by the other API functions.

Parameters:
  • reload – (bool) if True, instantiate a new global ConfigParser.

  • allowMissing – (bool) if True, a missing config file is not treated as an error. This is used only when generating documentation, e.g., on readthedocs.org.

  • createDefault – (bool) Check that the config file exists, and if not, write the default config file. Optional so we don’t have to check the file on every call.

  • systemConfigOnly – (bool) This is set to True when generating sphinx documentation to avoid presenting user’s settings in the generated pages.

Returns:

a ConfigParser instance.

opgee.config.getConfigDict(section='DEFAULT', raw=False)

Return all variables defined in section as a dictionary.

Parameters:
  • section – (str) the name of a section in the config file

  • raw – (bool) whether to return raw or interpolated values.

Returns:

(dict) all variables defined in the section (which includes those defined in DEFAULT.)

opgee.config.getParam(name, section=None, raw=False, raiseError=True)

Get the value of the configuration parameter name. Calls getConfig() if needed.

Parameters:
  • name – (str) the name of a configuration parameters. Note that variable names are case-insensitive. Note that environment variables are available using the ‘$’ prefix as in a shell. To access the value of environment variable FOO, use getParam(‘$FOO’).

  • section – (str) the name of the section to read from, which defaults to the value used in the first call to getConfig, readConfigFiles, or any of the getParam variants.

Returns:

(str) the value of the variable, or None if the variable doesn’t exist and raiseError is False.

Raises:

NoOptionError – if the variable is not found in the given section and raiseError is True

opgee.config.getParamAsBoolean(name, section=None)

Get the value of the configuration parameter name, coerced into a boolean value, where any (case-insensitive) value in the set {'true','yes','on','1'} are converted to True, and any value in the set {'false','no','off','0'} is converted to False. Any other value raises an exception. Calls getConfig() if needed.

Parameters:
  • name – (str) the name of a configuration parameters.

  • section – (str) the name of the section to read from, which defaults to the value used in the first call to getConfig, readConfigFiles, or any of the getParam variants.

Returns:

(bool) the value of the variable

Raises:

opgee.error.ConfigFileError

opgee.config.getParamAsFloat(name, section=None)

Get the value of the configuration parameter name as a float. Calls getConfig() if needed.

Parameters:
  • name – (str) the name of a configuration parameters.

  • section – (str) the name of the section to read from, which defaults to the value used in the first call to getConfig, readConfigFiles, or any of the getParam variants.

Returns:

(float) the value of the variable

opgee.config.getParamAsInt(name, section=None)

Get the value of the configuration parameter name, coerced to an integer. Calls getConfig() if needed.

Parameters:
  • name – (str) the name of a configuration parameters.

  • section – (str) the name of the section to read from, which defaults to the value used in the first call to getConfig, readConfigFiles, or any of the getParam variants.

Returns:

(int) the value of the variable

opgee.config.readConfigFiles(allowMissing=False, systemConfigOnly=False)

Read the OPGEE configuration files, starting with opgee/etc/system.cfg, followed by opgee/etc/{platform}.cfg if present. If the environment variable PYGCAM_SITE_CONFIG is defined, its value should be a config file, which is read next. Finally, the user’s config file, ~/opgee.cfg, is read. Each successive file overrides values for any variable defined in an earlier file.

Returns:

a populated ConfigParser instance

opgee.config.setParam(name, value, section=None)

Set a configuration parameter in memory.

Parameters:
  • name – (str) parameter name

  • value – (any, coerced to str) parameter value

  • section – (str) if given, the name of the section in which to set the value. If not given, the value is set in the established project section, or DEFAULT if no project section has been set.

Returns:

value

opgee.config.setSection(section)

Set the name of the default config file section to read from.

Parameters:

section – (str) a config file section name.

Returns:

none

opgee.config.unixPath(path, abspath=False)

Convert a path to use Unix-style slashes.

Parameters:
  • path – (str) a pathname

  • abspath – (bool) if True, the path is converted to an absolute path using the current working directory as the starting point.

Returns:

(str) the modified pathname