Commit da2b04fe authored by MEESSEN Christophe's avatar MEESSEN Christophe
Browse files

Refactoring of harvest tools and harvest controllers

Conflicts:
	modules/harvest_tools.py
parent 2913e779
......@@ -25,6 +25,7 @@ MSG_NO_HARVESTER = T("No harvesters for your selection !!!")
INLINE_ALERT = "<script>Ext.Msg.alert('%s', '%s');</script>"
DRY_RUN = current.T("dry run")
def free_run():
"""Run a free harvester.
......@@ -44,6 +45,9 @@ def free_run():
selector = Selector(table,
exclude_fields=('mode', 'year_start', 'year_end'))
#from pprint import pprint
#pprint(selector))
for el in fields:
if not selector[el]:
msg = T('All fields of the form have to be defined !!!')
......@@ -52,12 +56,17 @@ def free_run():
return INLINE_ALERT % (T('Error'), msg)
tool_class = get_harvester_tool(selector.controller)
tool = tool_class(db, selector, debug=False)
tool.harvester = Storage()
for el in fields:
tool.harvester[el] = selector[el]
tool = tool_class(db,
selector.id_teams,
selector.id_projects,
selector.controller,
selector.id_categories,
host=selector.host,
collections=selector.collections,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
tool()
except ToolException, e:
......@@ -70,7 +79,9 @@ def free_run():
return msg
response.view = 'harvest/layout.html'
return tool.report()
r = tool.report()
r['selector'] = selector
return r
def edit_insert():
......@@ -210,9 +221,17 @@ def insert_marcxml():
tool_class = get_harvester_tool(selector.controller)
if not tool_class:
return INLINE_ALERT % (T('Error'), T('Select a controller.'))
tool = tool_class(db, selector, debug=False)
tool()
tool = tool_class(db,
selector.id_teams,
selector.id_projects,
selector.controller,
selector.id_categories,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
tool(selector.xml)
except ToolException, e:
return T(str(e))
......@@ -224,7 +243,9 @@ def insert_marcxml():
return msg
response.view = 'harvest/layout.html'
return tool.report()
r = tool.report()
r['selector'] = selector
return r
def run():
......@@ -247,8 +268,23 @@ def run():
tool_class = get_harvester_tool(selector.controller)
if not tool_class:
return INLINE_ALERT % (T('Error'), T('Select an harvester.'))
tool = tool_class(db, selector, debug=False)
# Get the host and collections
row = selector.select(db.harvesters).first()
if not row:
raise ToolException(MSG_NO_HARVESTER)
tool = tool_class(db,
selector.id_teams,
selector.id_projects,
selector.controller,
row.harvesters.id_categories,
host=row.harvesters.host,
collections=row.harvesters.collections,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
tool()
except ToolException, e:
......@@ -261,7 +297,9 @@ def run():
return msg
response.view = 'harvest/layout.%s' % request.extension
return tool.report()
r = tool.report()
r['selector'] = selector
return r
def run_all():
......@@ -269,7 +307,6 @@ def run_all():
"""
collection_logs = []
collections = []
logs = []
try:
......@@ -290,15 +327,19 @@ def run_all():
return INLINE_ALERT % (T('Error'), MSG_NO_HARVESTER)
for harvester in harvesters:
selector.controller = harvester.controller
selector.id_projects = harvester.id_projects
selector.id_teams = harvester.id_teams
collections.extend(harvester.collections.split(','))
tool_class = get_harvester_tool(selector.controller)
tool = tool_class(db, selector, debug=False)
tool_class = get_harvester_tool(harvester.controller)
tool = tool_class(db,
harvester.id_teams,
harvester.id_projects,
harvester.controller,
harvester.id_categories,
host=harvester.host,
collections=harvester.collections,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
tool()
collection_logs.extend(tool.collection_logs)
......
This diff is collapsed.
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