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

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

Simplify and tidy up the configuration of the OAI Info editor +
remove some unecessary debugging code elsewhere in the controllers.

  • 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.dal.providerinfodao import *
10from oai_info_editor.lib.harvester import Harvester
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.baseUrl = cf.get('DEFAULT', 'baseurl')
32       
33        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
34        self.globals.ndgImage=cf.get('layout','ndgImage',None)
35        self.globals.helpIcon=cf.get('layout','helpIcon')
36        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
37        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
38        self.globals.pageLogo="bodcHdr"
39        self.globals.disclaimer=cf.get('default','disclaimer')
40        self.globals.xmlIcon=cf.get('layout','XMLicon')
41        self.globals.loadingIcon=cf.get('layout','loadingIcon')
42       
43        self.globals.server=cf.get('DEFAULT','server','')
44        self.globals.toggleJavascript = cf.get('layout','toggleJavascript')
45        self.globals.ndgJavascript = cf.get('layout','ndgJavascript')
46        self.globals.styleCss = cf.get('layout','styleCss')
47       
48        self.globals.proxy = cf.get('SERVERS','proxyServer')
49        self.globals.mailServer = cf.get('SERVERS', 'mailserver')
50       
51        self.globals.dataDir = cf.get('DATA_STORE', 'appDataFileDir')
52        self.globals.backupDir = cf.get('DATA_STORE', 'backupFileDir')
53        harvestDir = cf.get('DATA_STORE', 'harvestDir')
54        if not harvestDir:
55            raise ValueError("No harvest directory config data has been specified - so cannot harvest files.")
56       
57        self.globals.harvester = Harvester(self.globals.mailServer, outDir = harvestDir)
58
59        # store a data access object to general use
60        logging.info("Set up central data access object for reuse across editor")
61        self.globals.dao = createDAOWithClient(client = FILE_CLIENT_TYPE, configFile = cf)
62        logging.info("DAO set up")
63           
64        self.config=cf
65        logging.info("- editor configuration complete")
66       
67    def __call__(self,environ,start_response):
68       
69        environ['appConfig']=self.config
70        return self.app(environ,start_response)
71   
Note: See TracBrowser for help on using the repository browser.