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

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

Add code to allow ingest of docs when harvest button clicked - NB,
harvest completes first of all, then the ingest is ran asynchronously
since it can take some time. If the user has provided an email
address for the provider, the results are then mailed to them.

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