Commit 1ef89c74 authored by MEESSEN Christophe's avatar MEESSEN Christophe
Browse files

Move xml as PublicationTools constructor argument

parent 0789b0b9
......@@ -224,11 +224,12 @@ def insert_marcxml():
selector.id_projects,
selector.controller,
selector.id_categories,
xml=selector.xml,
year_start=selector.year_start,
year_end=selector.year_end,
dry_run=(selector.mode == DRY_RUN),
debug=False)
tool(selector.xml)
tool()
except ToolException, e:
return T(str(e))
......
......@@ -408,7 +408,7 @@ class PublicationsTool(object):
"""
def __init__(self, db, id_team, id_project, controller, id_category, host=None, collections=None,
year_start=None, year_end=None, dry_run=True, debug=False):
xml=None, year_start=None, year_end=None, dry_run=True, debug=False):
"""
@type db: gluon.dal.DAL
......@@ -432,6 +432,9 @@ class PublicationsTool(object):
@type collections: unicode
@keyword collections: Request string to send to the host to get the publications
@type xml: unicode
@keyword xml: marc12 xml encoding of the publication record
@type year_start: int
@keyword year_start: Start year of search (i.e. '2014')
......@@ -444,6 +447,8 @@ class PublicationsTool(object):
@type debug: bool
@param debug: activate the debug mode
The constructor expect that host and collections is provided or xml is provided instead.
"""
self.collection_logs = []
self.db = db
......@@ -453,17 +458,31 @@ class PublicationsTool(object):
self.id_category = id_category
self.host = host
self.collections = collections
self.xml = xml
self.year_start = year_start
self.year_end = year_end
self.dbg = debug
self.harvester = None
self.logs = []
self.check = CheckAndFix()
self.marc12 = Marc12()
# check parameters
# protection team, project and/or category have to be defined
if not self.id_team:
raise ToolException(MSG_NO_TEAM)
# Construct harvester Storage needed for the log
if not self.id_project:
raise ToolException(MSG_NO_PROJECT)
if not self.id_category:
raise ToolException(MSG_NO_CAT)
# xml or (host and collections) keyargs must be provided
if not ((xml and not host and not collections) or (not xml and host and collections)):
raise ToolException(MSG_MISSING_PARAMETER)
# Construct harvester Storage needed for the log
if host and collections:
self.harvester = Storage(id_teams=self.id_team,
id_projects=self.id_project,
......@@ -917,26 +936,15 @@ class PublicationsTool(object):
if self.dbg:
print "start processing", self.__class__.__name__
print "decode request"
# protection team, project and/or category have to be defined
if not self.id_project:
raise ToolException(MSG_NO_PROJECT)
if not self.id_team:
raise ToolException(MSG_NO_TEAM)
if self.dbg:
print "get harvest parameters"
# process an XML request
if xml:
if not self.id_category:
raise ToolException(MSG_NO_CAT)
self.xml = xml
if self.xml:
self.collection_logs.append(MsgCollection(found=1))
self.process_xml(xml)
self.process_xml(self.xml)
return
# retrieve the harvester parameter in the database
......
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