source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/harvest.py @ 5253

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/controllers/harvest.py@5253
Revision 5253, 2.1 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 Class representing pylons controller for the harvesting of provider info
3 
4 @author: C Byrom, Tessella Apr 2009
5'''
6import logging, urllib
7from oai_info_editor.lib.base import *
8from oai_info_editor.controllers.master import MasterController
9import oai_info_editor.lib.constants as const
10
11class HarvestController(MasterController):
12
13    def harvestProviderInfo(self, providerName, repositoryName):
14        '''
15        Harvest the repository info associated with the input name and provider
16        @param providerName: name of provider whose info should be displayed
17        @param repositoryName: name of repository whose info should be displayed
18        '''
19        providerName = urllib.unquote(providerName)
20        repositoryName = urllib.unquote(repositoryName)
21        self._setUpController(providerName = providerName)
22        logging.info("Setting up page to display info for provider, '%s'" %providerName)
23
24        pi = g.dao.getProviderInfo(providerName)
25        ri = g.dao.getRepositoryInfo(providerName, repositoryName)
26        if not ri:
27            raise ValueError("Could not find repository, '%s' for provider, '%s'" \
28                             %(repositoryName, providerName))
29
30        try:
31            status, result = g.harvester.runHarvestAndIngest(providerName, ri,
32                                                             ingestAsynch = True,
33                                                             userEmail = pi.email)
34        except Exception, e:
35            c.errors = {'System error': e}
36            return render('genshi', 'error')
37
38        outMessage = "Repository data, %s, for provider with name, %s, successfully harvested. (Details: %s)" \
39            %(repositoryName, providerName, result)
40        if not status:
41            outMessage = "A problem occurred whilst harvesting the data - please retry later."
42            c.errors = {'Harvest/ingest error': result}
43            return render('genshi', 'error')
44
45        # now return to the home page - and display pop up
46        session[const.POP_UP_MESSAGE_SESSION_KEY] = outMessage
47        session.save()
48
49        # now, return to the view page
50        h.redirect_to('home')
Note: See TracBrowser for help on using the repository browser.