pygcam.config
¶
See the configuration system page for a detailed description of available configuration variables. This page documents the API to the configuration system.
API¶
-
pygcam.config.
getConfig
()¶ 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.
Returns: a SafeConfigParser instance.
-
pygcam.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 Returns: (dict) all variables defined in the section (which includes those defined in DEFAULT.)
-
pygcam.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.
- 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 thegetParam
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
-
pygcam.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 toTrue
, and any value in the set{'false','no','off','0'}
is converted toFalse
. Any other value raises an exception. CallsgetConfig()
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 thegetParam
variants.
Returns: (bool) the value of the variable
Raises:
-
pygcam.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 thegetParam
variants.
Returns: (float) the value of the variable
-
pygcam.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 thegetParam
variants.
Returns: (int) the value of the variable
-
pygcam.config.
readConfigFiles
()¶ Read the pygcam configuration files, starting with
pygcam/etc/system.cfg
, followed bypygcam/etc/{platform}.cfg
if present. If the environment variablePYGCAM_SITE_CONFIG
is defined, its value should be a config file, which is read next. Finally, the user’s config file,~/.pygcam.cfg
, is read. Each successive file overrides values for any variable defined in an earlier file.Returns: a populated SafeConfigParser instance
-
pygcam.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: none
-
pygcam.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