source: cows_wps/trunk/cows_wps/utils/user_roles_dict.py @ 6872

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

Added user roles info, parser. Also added test code to check that WPS
controller aborts POST requests.

Line 
1"""
2user_roles_dict.py
3==================
4
5Provides parser and utility globals for dictionary containing user roles base on ini file:
6
7 user_roles.ini
8
9"""
10
11import os
12import re
13import ConfigParser
14
15from cows_wps.utils.parse_wps_config import wps_config_dict
16
17import logging
18log = logging.getLogger(__name__)
19
20
21def parseUserRolesConfig(roles_ini = None): 
22    """
23    Parses config file for user roles.
24    """
25    global user_roles_config_dict
26
27    if roles_ini == None:
28        try:
29#            user_roles_config_dict = str(wps_config_dict) ; return
30            roles_ini = wps_config_dict['roles_ini']
31        except KeyError:
32            log.warn('No user_roles.ini in wps.ini')
33            base_dir = os.environ.get("WPS_BASE", "..")
34            roles_ini = os.path.join(base_dir, "user_roles.ini")
35
36    if not os.path.isfile(roles_ini):
37        raise Exception("No such configuration file: %s" % roles_ini)
38
39    roles = {}
40    conf = ConfigParser.ConfigParser() 
41    conf.read(roles_ini)
42
43    for indx in conf.options("roles"):
44        i = int(indx)
45        value = conf.get("roles", indx)
46        roles[i] = value
47
48    user_roles_config_dict = roles
49
50
51user_roles_config_dict = None
52parseUserRolesConfig()
53
54
55if __name__ == "__main__":
56
57    print user_roles_config_dict
Note: See TracBrowser for help on using the repository browser.