source: cows_wps/trunk/cows_wps/utils/parse_wps_config.py @ 6877

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/utils/parse_wps_config.py@7575
Revision 6877, 1.5 KB checked in by astephen, 9 years ago (diff)

added more work on getting async jobs running

Line 
1"""
2parse_wps_config.py
3===================
4
5Parses config file for WPS.
6
7"""
8# Standard library imports
9import ConfigParser
10import os
11import pylons
12
13import logging
14log = logging.getLogger(__name__)
15
16from collections import defaultdict
17
18class LazyWPSConfigDict(defaultdict):
19    def __missing__(self, key):
20        if pylons.config is None:
21            raise RuntimeError("Trying to access WPS configuration options before the pylons configuration is initialised")
22     
23        try:
24            val = pylons.config['app_conf']['wps.%s' % key]
25        except KeyError:
26            raise KeyError("WPS configuration option wps.%s is not found in pylons configuration." % key)
27       
28        log.debug('Accessing WPS config option %s=%s' % (key, val))
29       
30        self[key] = val
31        return val
32       
33    def get(self, key, default=None):
34        log.debug("getting key = %s" % (key,))
35        if pylons.config is None:
36            raise RuntimeError("Trying to access WPS configuration options before the pylons configuration is initialised")
37       
38        pylonsKey = 'wps.%s' % key
39       
40        if pylonsKey in pylons.config['app_conf']:
41            val =  pylons.config['app_conf'][pylonsKey]
42        else:
43            val = default
44           
45        return val
46
47    def has_key(self, key):
48        log.debug("checking for key = %s" % (key,))
49        return pylons.config['app_conf'].has_key('wps.%s' % key)
50       
51# Global variables
52wps_config_dict = LazyWPSConfigDict()
Note: See TracBrowser for help on using the repository browser.