source: cows_wps/trunk/cows_wps/utils/parse_roles_config.py @ 7520

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/utils/parse_roles_config.py@7520
Revision 7520, 1.3 KB checked in by astephen, 10 years ago (diff)

Added parser for roles_info.ini file.

Line 
1"""
2parse_role_configs.py
3======================
4
5Holds parsers for role configuration files.
6
7"""
8
9# Standard library imports
10import os
11import ConfigParser
12
13from cows_wps.utils.parse_wps_config import wps_config_dict
14
15import logging
16log = logging.getLogger(__name__)
17
18
19def parseRolesConfig(config_file):
20    """
21    Returns a dictionary from a simple config file.
22    """
23    print config_file
24    c = ConfigParser.ConfigParser()
25    c.read(config_file)
26
27    rd = {}
28
29    for section in ("roles", "proc_role_map", "pattern_role_map"):
30
31        rd[section] = {}
32
33        for key in c.options(section):
34
35            rd[section][key] = c.get(section, key)
36
37    return rd
38
39
40def setRolesDict():
41    """
42    Sets the global variable "roles_info" if not already set:
43
44        roles_info = {"roles": {...}, "proc_role_map": {...}, "pattern_role_map": {...}}
45    """
46    global roles_info
47   
48    if roles_info == None:
49        try:
50            roles_ini = wps_config_dict['roles_info_ini']
51        except KeyError:
52            log.warn('No roles_info_ini configuration in wps.ini')
53            base_dir = os.environ.get("WPS_BASE", ".")
54            roles_ini  = os.path.join(base_dir, "roles_info.ini")
55   
56    roles_info = parseRolesConfig(roles_ini)
57
58
59roles_info = None
60setRolesDict()
61
62if __name__ == "__main__":
63
64    print roles_info
Note: See TracBrowser for help on using the repository browser.