Config

From PyWPS
Jump to: navigation, search

The pywps configuration file can be read or manipulated inside the process execution

Import

To access the configuration file during run time the config object has to be loaded into the code:

import pywps.config

Reading

The pywps.config is based on the ConfigParser (Configuration File Parser) [1], basically the configuration file consists of sections, led by a [section] header and followed by name=value entries.

The method getConfigValue(<section>,<name>) will return the value contained in the pywps configuration file, for example a section like:

[mapserver]
mapserveraddress=http://localhost/mapserv.cgi
projdatapath=/usr/lib/proj/
projs=epsg:4326,epsg:102067,epsg:3059,epsg:900913

The projs values can be read as follows:

projs=pywps.config.getConfigValue("mapserver","projs")

The pywps config class extends ConfigParser and will differenciate between boolean and string, for example the following situation:

phoneVoice=False
phoneFacsimile=+1 555 325 125

The getConfigValue("provider","phoneVoice") will return a python boolean that can be used in any logic system (if, while etc), while the getConfigValue("provider","phoneFacsimile") will return a python string type.

Writting

The running process can overwrite configurationvalues, note that the value will be overwritten on the process instance (code being run) and not the file it self. The setConfigValue(<section>,<name>,<value>) For example to overwrite the maxfilesize:

pywps.config.setConfigValue("server","maxfilesize", str(0))

NOTE: the <value> argument has to be string-type and shouldn't be numerical or None

Reset

In case of need the configuration file can be reloaded and any modified values will return to their originals.

pywps.config.loadConfiguration()

the loadConfiguration() by default will try to read the configuration file defined in the pywps install (PYWPS_CFG). If necessay the method will accept a new configuration file to read:

pywps.config.loadConfiguration(cfgfiles='/etc/pywps_new_file.cfg')