Commit 009c5f94 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Use the preference inspireshep_institute_in in harvesters.

parent 8f8ba09c
......@@ -22,4 +22,9 @@ app = Storage()
for row in db(db.preferences).select():
app[row.property] = row.value
# add local variable
app["reg_institute"] = ""
app["institute"] = None
current.app = app
......@@ -14,26 +14,8 @@ from exception import (CdsException,
RecordException,
XmlException)
from checkandfix import CheckAndFix
from checkandfix import CheckAndFix, load_record
from institute import Institute
from inveniostore import InvenioStore
from marc12 import Marc12
from record import Record
def load_record(host, record_id):
"""Load a record from an invenio store
Args:
host (str): host of the store. Either cds.cern.ch or inspirhep.net.
record_id (integer): the record identifier
Returns:
Record: the decoded record
"""
store = InvenioStore(host)
xml = store.get_record(record_id)
svc = Marc12()
return svc(xml)[0]
......@@ -6,9 +6,9 @@ import re
import regex
from base import OAI_URL, REG_OAI, REG_YEAR
from gluon import current
from exception import CheckException
from filters import CLEAN_REVIEW
from gluon import current
from inveniostore import InvenioStore
from marc12 import Marc12
from plugin_dbui import get_id
......@@ -75,6 +75,24 @@ REG_CONF_DATES = re.compile(regex.REG_CONF_DATES)
REG_SUBMITTED = re.compile(regex.REG_SUBMITTED)
def load_record(host, record_id):
"""Helper function to load a single record from an invenio store.
Args:
host (str): host of the store. Either cds.cern.ch or inspirhep.net.
record_id (integer): the record identifier
Returns:
Record: the decoded record
"""
store = InvenioStore(host)
xml = store.get_record(record_id)
svc = Marc12()
return svc(xml)[0]
class CheckAndFix(object):
"""Tool to check and repair the content of the Marc12 record:
......@@ -482,10 +500,23 @@ class CheckAndFix(object):
"""
# alias
institute = current.app.reg_institute
app = current.app
reg_institute = app.reg_institute
# regular expression for the institute is not defined
# find it using the institute definition in inspirehep
# store the regular expression in current.app for a later use
if not reg_institute:
institute_id = app.inspirehep_institute_id
institute = load_record("inspirehep.net", institute_id)
reg_institute = institute.rex()
app.institute = institute
app.reg_institute = reg_institute
# find authors of my institute signing the record
s = record.find_authors_by_institute(institute, cmpFct)
s = record.find_authors_by_institute(reg_institute, cmpFct)
# nothing found try with the rescue list
if not s and reference:
......@@ -502,7 +533,7 @@ class CheckAndFix(object):
record.my_authors = s
return
raise CheckException(MSG_NO_MY_AUTHOR % institute.encode("utf8"))
raise CheckException(MSG_NO_MY_AUTHOR % reg_institute.encode("utf8"))
def oai(self, record):
"""Check that the OAI field is defined and well formed.
......
......@@ -65,7 +65,7 @@ def test_authors(record):
def test_find_authors_by_institute(record):
rex = current.app.reg_institute
assert rex == "CPPM"
assert rex == "Marseille, CPPM|CPPM, Marseille"
authors = record.find_authors_by_institute(rex, family_name_fr)
authors = authors.split(", ")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment