source: nappy/trunk/nappy/utils/parse_wps_config.py @ 3321

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/utils/parse_wps_config.py@3321
Revision 3321, 1.3 KB checked in by astephen, 12 years ago (diff)

First major re-factor.

Line 
1"""
2parse_wps_config.py
3===================
4
5Parses config file for WPS.
6
7"""
8
9# Standard library imports
10import ConfigParser
11import os
12
13# Global variables
14config_file = os.environ["WPS_INI"]
15wps_config_dict = None
16
17def makeConfigDict(cf=config_file):
18    """Parses config file stuff needed in wps.py and return flat dictionary of
19    Keyword-Value pairs."""
20    print "LOOK I'M MAKING CONFIG DICT!" 
21    d = {}
22    conf = ConfigParser.ConfigParser()
23    conf.read(cf)
24
25    """keysNeeded = [("DEFAULT", "basedir"), ("server:main", "host"),
26                  ("server:main", "port"), ("DEFAULT", "htdocs"),
27                  ("DEFAULT", "version"), ("DEFAULT", "proc_base_dir"),
28                  ("DEFAULT", "response_cache_dir"), ("DEFAULT", "jobs_running_dir")]
29    """
30    # Get all defaults
31    for i in conf.defaults():
32        d[i] = conf.get("DEFAULT", i)
33
34    # and other needed
35    keysNeeded = [("server:main", "host"), ("server:main", "port")]
36    for (section, item) in keysNeeded:
37        d[item] = conf.get(section, item)
38
39    return d
40
41
42def getConfigDict(cf=config_file):
43    "Checks if already made and only makes if required."
44    global wps_config_dict
45    if wps_config_dict == None:
46        wps_config_dict = makeConfigDict(cf)
47    return wps_config_dict
48
49
50if __name__=="__main__":
51    print getConfigDict()
Note: See TracBrowser for help on using the repository browser.