source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/config/oiemiddleware.py @ 5226

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/config/oiemiddleware.py@5226
Revision 5226, 3.2 KB checked in by cbyrom, 11 years ago (diff)

Initial check in of code for the OAI Info Editor pylons based web app.

This includes basic controllers for viewing provider info - with the
associated repository info. Also included is the model and dal layer,
allowing the provider info to be processed and imported/exported to
XML file. Unit tests for the dal and model packages are included.
Templates for rendering provider and repository info are included.

  • Property svn:executable set to *
Line 
1'''
2 Middleware controller extension for the OAI info editor
3 
4 @author: C Byrom, Tessella Apr 2009
5'''
6import logging, urllib, os
7from paste.deploy import CONFIG
8from ndg.common.src.models.myconfig import myConfig
9from oai_info_editor.model.user import *
10from oai_info_editor.dal.providerinfodao import *
11   
12class OIEMiddleware(object):
13   
14    MISSING_HELP_TEXT_ERROR = 'Error: Help text missing from config file'
15
16    # flags to lookup in config files - and to refer to data stored in global constants
17    MANDATORY_DATA = 'mandatory'
18    FIXED_DATA = 'fixed'
19    HELP_DATA = 'help_text'
20   
21    def __init__(self, app, g, app_conf):
22        logging.debug("Setting up editor configuration")
23        #this is the next application in the wsgi stack
24        self.app=app
25       
26        #set up the app configuration file
27        cf=app_conf['configfile']
28        cf=myConfig(cf)
29     
30        self.globals=g
31        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
32        self.globals.ndgImage=cf.get('layout','ndgImage',None)
33        self.globals.helpIcon=cf.get('layout','helpIcon')
34        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
35        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
36        self.globals.pageLogo="bodcHdr"
37        self.globals.disclaimer=cf.get('default','disclaimer')
38        self.globals.xslt=cf.get('layout','xslt','')
39        self.globals.xmlIcon=cf.get('layout','XMLicon')
40        self.globals.loadingIcon=cf.get('layout','loadingIcon')
41       
42        self.globals.server=cf.get('SERVERS','server','')
43        self.globals.proxy = cf.get('SERVERS','proxyServer')
44        self.globals.mailServer = cf.get('SERVERS', 'mailserver')
45       
46        self.globals.dataDir = cf.get('DATA_STORE', 'appDataFileDir')
47        self.globals.backupDir = cf.get('DATA_STORE', 'backupFileDir')
48
49        self.globals.users = {}
50        users = cf.get('USER_LIST', 'userIDs')
51       
52        if not users:
53            raise ValueError("No user config data has been specified - so no one can use the editor")
54       
55        logging.debug("Setting up users for editor")
56        for userID in users.split():
57            pw = cf.get(userID, 'pw')
58            providerNames = cf.get(userID, 'providerNames').split(';')
59            names = []
60            for name in providerNames:
61                names.append(name.strip())
62           
63            providerNames = names
64       
65            if self.globals.users.has_key(userID):
66                raise ValueError("Two identical users ('%s') specified in config file - this is not allowed"
67                                 %userID)
68           
69            self.globals.users[userID] = User(userID, providerNames)
70        logging.debug("- editor user objects set up")
71
72        # store a data access object to general use
73        logging.info("Set up central data access object for reuse across editor")
74        self.globals.dao = createDAOWithClient(client = FILE_CLIENT_TYPE, configFile = cf)
75        logging.info("DAO set up")
76           
77        self.config=cf
78        logging.info("- editor configuration complete")
79       
80    def __call__(self,environ,start_response):
81       
82        environ['appConfig']=self.config
83        return self.app(environ,start_response)
84   
Note: See TracBrowser for help on using the repository browser.