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

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

Added bin/create_policy_file.py
To allow auto-generation of policy.xml NDG-security 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 logging
12
13# local imports
14from cows_wps.utils.case_sensitive_ordered_config_parser import CaseSensitiveConfigParser
15
16# When running in pylons the following import works but if run
17# from a script outside pylons we need to define an empty dict
18# so that it works.
19try:
20    from cows_wps.utils.parse_wps_config import wps_config_dict
21except:
22    wps_config_dict = {}
23
24log = logging.getLogger(__name__)
25
26
27def parseRolesConfig(config_file):
28    """
29    Returns a dictionary from a simple config file.
30    """
31    c = CaseSensitiveConfigParser()
32    c.read(config_file)
33
34    rd = {}
35
36    for section in ("roles", "proc_role_map", "pattern_role_map"):
37
38        rd[section] = {}
39
40        for key in c.options(section):
41
42            rd[section][key] = c.get(section, key)
43
44    return rd
45
46
47def setRolesDict():
48    """
49    Sets the global variable "roles_info" if not already set:
50
51        roles_info = {"roles": {...}, "proc_role_map": {...}, "pattern_role_map": {...}}
52    """
53    global roles_info
54   
55    if roles_info == None:
56        try:
57            roles_ini = wps_config_dict['roles_info_ini']
58        except KeyError:
59            log.warn('No roles_info_ini configuration in wps.ini')
60            base_dir = os.environ.get("WPS_BASE", ".")
61            roles_ini  = os.path.join(base_dir, "roles_info.ini")
62   
63    roles_info = parseRolesConfig(roles_ini)
64
65
66roles_info = None
67setRolesDict()
68
69if __name__ == "__main__":
70
71    print roles_info
Note: See TracBrowser for help on using the repository browser.