Commit c6e772a7 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Finalise the action wizard/harvester.

parent 0b7a9fb0
......@@ -8,8 +8,10 @@ import re
from check_tools import check_publication
from gluon.storage import Storage
from harvest_tools import DRY_RUN
from plugin_dbui import (is_foreign_field,
from plugin_dbui import (CALLBACK_ERRORS,
is_foreign_field,
get_foreign_field,
get_id,
Selector,
to_fields)
......@@ -28,7 +30,7 @@ def check_validate():
"""
counters = {}
logs = []
id_ok = db(db.status.code=='OK').select().first().id
id_ok = db(db.status.code == 'OK').select().first().id
# get user requirement
selector = Selector(virtdb.check_selector, exclude_fields=('mode'))
......@@ -192,5 +194,112 @@ def extract_authors():
def harvester():
print request.vars
"""Process the data send by the wizard harvester and fill the
harvesters table. The data block contains the keys:
* automaton (str)
* collaboration (str)
* collection (str)
* people (list)
* producer (str) either 'collaboration' or 'people'
* project (int)
* store (str) either cds.cern.ch or inspirehep.net
The logic to interpret the data depends on the store.
"""
# shortcuts
vars = request.vars
automaton = vars.automaton
organisation = db.organisation
project = vars.project
store = vars.store
# protection
if store not in ("cds.cern.ch", "inspirehep.net"):
raise HTTP(500, "Invalid store !")
values = Storage(controller=automaton,
host=store,
id_projects=project)
# the team
rec_id = get_id(organisation, id_projects=project)
if rec_id is None:
raise HTTP(500, "Project is unknown !")
values.id_teams = organisation[rec_id].id_teams
# the collection
if store == "cds.cern.ch":
values.collections = vars.collection
elif store == "inspirehep.net":
collection = []
collaboration = vars.collaboration
if collaboration:
collection.append("cn %s" % collaboration)
else:
collection.append("(a %s)" % " or ".join(vars.people))
if automaton == "articles":
collection.append("tp p and not tc c")
elif automaton == "proceedings":
collection.append("tp p and tc c")
values.collections = "find %s" % " and ".join(collection)
# the publication category
if automaton == "articles":
id_category = get_id(db.categories, code="ACL")
elif automaton in ("notes", "reports"):
id_category = get_id(db.categories, code="AP")
elif automaton == "preprints":
id_category = get_id(db.categories, code="PRE")
elif automaton == "proceedings":
id_category = get_id(db.categories, code="ACTI")
elif automaton == "talks":
id_category = get_id(db.categories, code="COM")
elif automaton == "theses":
id_category = get_id(db.categories, code="PHD")
if id_category is None:
raise HTTP(500, "Category is unknown !")
values.id_categories = id_category
# insert new values in the database
msg = None
try:
rec_id = db.harvesters.insert(**values)
if rec_id:
return
# operation can be reject by callback table._before_insert
else:
msg = "Fail to insert the new harvester in the database."
if CALLBACK_ERRORS in db.harvesters:
msg = db.harvesters._callback_errors
# reduce the error message
if isinstance(msg, list):
msg = "%s %s" % (msg[0], msg[-1])
# operation is rejected by the database
except Exception as dbe:
raise HTTP(500, dbe.message)
# operation is rejected by the callback
# NOTE in the else branch to avoid recursive exception generation
if msg is not None:
raise HTTP(500, msg)
return
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