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

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

Extend harvest functionality to also include ingest of harvested docs
+ improve error handling and catch special cases when creating
providers with names that already exist + improve UI look and feel.

  • 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        ri = g.dao.getRepositoryInfo(providerName, repositoryName)
25        if not ri:
26            raise ValueError("Could not find repository, '%s' for provider, '%s'" \
27                             %(repositoryName, providerName))
28
29        try:
30            status, result = g.harvester.runHarvestAndIngest(providerName, ri)
31        except Exception, e:
32            c.errors = {'System error': e}
33            return render('genshi', 'error')
34
35        outMessage = "Repository data, %s, for provider with name, %s, successfully harvested. (Details: %s)" \
36            %(repositoryName, providerName, result)
37        if not status:
38            outMessage = "A problem (%s) occurred whilst harvesting the data - please retry later" \
39                %result
40
41        # now return to the home page - and display pop up
42        session[const.POP_UP_MESSAGE_SESSION_KEY] = outMessage
43        session.save()
44
45        # now, return to the view page
46        h.redirect_to('home')
Note: See TracBrowser for help on using the repository browser.