harvest.py 2.99 KB
Newer Older
1 2 3
""" Harvest Controllers

"""
4
import traceback
5

legac's avatar
legac committed
6 7 8 9 10 11
from harvest_tools import (Articles,
                           Notes,
                           Preprints,
                           Proceedings,
                           Reports,
                           Talks,
12
                           ToolException,
13
                           Thesis)
14

15
from plugin_dbui import Selector
16 17


18 19
def insert_marcxml():
    """Insert a MarcXML record in the database.
tux091's avatar
tux091 committed
20
    
21
    """
tux091's avatar
tux091 committed
22
    try:
23
        selector = Selector(virtdb.marc12_selector)
24

25 26
        if selector.controller == 'articles':
            Tool = Articles
legac's avatar
legac committed
27

28 29
        elif selector.controller == 'notes':
            Tool = Notes
legac's avatar
legac committed
30
        
31 32 33 34 35 36 37 38 39 40 41 42 43 44
        elif selector.controller == 'preprints':
            Tool = Preprints
        
        elif selector.controller == 'proceedings':
            Tool = Proceedings
        
        elif selector.controller == 'reports':
            Tool = Reports
        
        elif selector.controller == 'talks':
            Tool = Talks
        
        elif selector.controller == 'theses':
            Tool = Thesis
45 46 47
        
        else:
            return T('Select a controller.')
48 49
            
        tool = Tool(selector, debug=False)
50
        tool.process(db)
51
    
52 53 54
    except ToolException, e:
        return T(str(e))
    
55
    except BaseException, e:
56 57 58 59
        msg  = '<br><br><hr/>'
        msg += CODE(traceback.format_exc()).xml()
        msg += '<hr/>'
        return msg
60 61
    
    response.view = 'harvest/layout.html'
62
    return tool.report()
63 64


65 66 67 68
def run():
    """Scan the cds/invenio stores to find articles published during 
    a given range of years and for a given team/project. 
    Insert them in the database if they don't exist.
69
    
70 71
    The scanning is steered using the current request arguments as well as
    the harvest parameters associated to this action.
72

73
    Search arguments are defined via the harvester selector. 
74

Renaud Le Gac's avatar
Renaud Le Gac committed
75 76
    """
    try:
77 78
        selector = Selector(virtdb.harvester_selector,
                            exclude_fields=('year_start', 'year_end'))
Renaud Le Gac's avatar
Renaud Le Gac committed
79

80 81
        if selector.controller == 'articles':
            Tool = Articles
82

83 84 85 86 87 88 89 90
        elif selector.controller == 'notes':
            Tool = Notes
        
        elif selector.controller == 'preprints':
            Tool = Preprints
        
        elif selector.controller == 'proceedings':
            Tool = Proceedings
91
        
92 93 94 95 96 97 98 99
        elif selector.controller == 'reports':
            Tool = Reports
        
        elif selector.controller == 'talks':
            Tool = Talks
        
        elif selector.controller == 'theses':
            Tool = Thesis
100 101 102 103
        
        else:
            return T('Select an harvester.')
         
LE GAC Renaud's avatar
LE GAC Renaud committed
104
        tool = Tool(selector, debug=False)
105 106
        tool.process(db)
    
107 108 109
    except ToolException, e:
        return T(str(e))
    
110
    except BaseException, e:
111 112 113 114
        msg  = '<br><br><hr/>'
        msg += CODE(traceback.format_exc()).xml()
        msg += '<hr/>'
        return msg
115
    
116
    response.view = 'harvest/layout.html'
117
    return tool.report()
118 119