diff --git a/modules/bibharvest/lib/bibharvestadminlib.py b/modules/bibharvest/lib/bibharvestadminlib.py index 57b5c97c4..5435d133c 100644 --- a/modules/bibharvest/lib/bibharvestadminlib.py +++ b/modules/bibharvest/lib/bibharvestadminlib.py @@ -1,877 +1,875 @@ -1## $Id$ +## $Id$ ## Administrator interface for BibIndex ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """CDS Invenio Bibharvest Administrator Interface.""" __revision__ = "$Id$" import re import os, sys, string import ConfigParser import time import random import urllib import tempfile import datetime from httplib import InvalidURL from invenio.config import \ CFG_SITE_LANG, \ CFG_TMPDIR, \ CFG_VERSION, \ CFG_SITE_URL,\ CFG_ETCDIR, \ CFG_BINDIR from invenio.bibrankadminlib import \ write_outcome,modify_translations,\ get_def_name,\ get_i8n_name,\ get_name,\ get_rnk_nametypes,\ get_languages,\ check_user,\ is_adminuser,\ addadminbox,\ tupletotable,\ tupletotable_onlyselected,\ addcheckboxes,\ createhiddenform from invenio.dbquery import run_sql from invenio.webpage import page, pageheaderonly, pagefooteronly, adderrorbox from invenio.webuser import getUid, get_email from invenio.bibharvest_dblayer import get_history_entries, HistoryEntry import invenio.template bibharvest_templates = invenio.template.load('bibharvest') tmppath = CFG_TMPDIR + '/bibharvestadmin.' + str(os.getpid()) guideurl = "help/admin/bibharvest-admin-guide" freqs = [[0, "never"], [24, "daily"], [168, "weekly"], [720, "monthly"] ] posts = [["h", "harvest only (h)"], ["h-c", "harvest and convert (h-c)"], ["h-u", "harvest and upload (h-u)"], ["h-c-u", "harvest, convert and upload (h-c-u)"], ["h-c-f-u", "harvest, convert, filter, upload (h-c-f-u)"]] dates = [[0, "from beginning"], [1, "from today"]] def getnavtrail(previous = ''): """Get the navtrail""" return bibharvest_templates.tmpl_getnavtrail(previous = previous, ln = CFG_SITE_LANG) def generate_sources_actions_menu(ln, oai_src_id): namelinked_args = [] namelinked_args.append(["oai_src_id", str(oai_src_id)]) namelinked_args.append(["ln", ln]) editACTION = bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/editsource", title = "edit", args = namelinked_args) delACTION = bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/delsource", title = "delete", args = namelinked_args) testACTION = bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/testsource", title = "test", args = namelinked_args) historyACTION = bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/viewhistory", title = "history", args = namelinked_args) harvestACTION = bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/harvest", title = "harvest", args = namelinked_args) return editACTION + " / " + delACTION + " / " + testACTION + " / " + historyACTION + " / " + harvestACTION def generate_oai_source_operations(ln, oai_src_id): result = bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "OAI source operations", guideurl=guideurl) result += generate_sources_actions_menu(ln, oai_src_id) return result def perform_request_index(ln=CFG_SITE_LANG): """start area for administering harvesting from OAI repositories""" titlebar = bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "Overview of sources", guideurl = guideurl, extraname = "add new OAI source" , extraurl = "admin/bibharvest/bibharvestadmin.py/addsource" ) titlebar2 = bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "Harvesting status", guideurl = guideurl) header = ['name', 'baseURL', 'metadataprefix', 'frequency', 'bibconvertfile', 'postprocess', 'actions'] header2 = ['name', 'last update'] oai_src = get_oai_src() upd_status = get_update_status() sources = [] for (oai_src_id,oai_src_name,oai_src_baseurl,oai_src_prefix,oai_src_frequency,oai_src_config,oai_src_post,oai_src_bibfilter,oai_src_setspecs) in oai_src: namelinked_args = [] namelinked_args.append(["oai_src_id", str(oai_src_id)]) namelinked_args.append(["ln", ln]) namelinked = bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/editsource", title = oai_src_name, args = namelinked_args) freq = "Not Set" if oai_src_frequency==0: freq = "never" elif oai_src_frequency==24: freq = "daily" elif oai_src_frequency==168: freq = "weekly" elif oai_src_frequency==720: freq = "monthly" action = generate_sources_actions_menu(ln, oai_src_id) sources.append([namelinked,oai_src_baseurl,oai_src_prefix,freq,oai_src_config,oai_src_post, action]) updates = [] for (upd_name, upd_status) in upd_status: if not upd_status: upd_status = bibharvest_templates.tmpl_print_warning(CFG_SITE_LANG, "Never harvested") else: #cut away leading zeros upd_status = re.sub(r'\.[0-9]+$', '', str(upd_status)) updates.append([upd_name, upd_status]) (schtime, schstatus) = get_next_schedule() if schtime: schtime = re.sub(r'\.[0-9]+$', '', str(schtime)) output = titlebar output += bibharvest_templates.tmpl_output_numbersources(CFG_SITE_LANG, get_tot_oai_src()) output += tupletotable(header=header, tuple=sources) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += titlebar2 output += bibharvest_templates.tmpl_output_schedule(CFG_SITE_LANG, schtime, str(schstatus)) output += tupletotable(header=header2, tuple=updates) return output def perform_request_editsource(oai_src_id=None, oai_src_name='', oai_src_baseurl='', oai_src_prefix='', oai_src_frequency='', oai_src_config='', oai_src_post='',ln=CFG_SITE_LANG, confirm=-1, oai_src_sets=[], oai_src_bibfilter=''): """creates html form to edit a OAI source. this method is calling other methods which again is calling this and sending back the output of the method. confirm - determines the validation status of the data input into the form""" if oai_src_id is None: return "No OAI source ID selected." output = "" subtitle = bibharvest_templates.tmpl_draw_subtitle(ln = CFG_SITE_LANG, title = "edit source", subtitle = "Edit OAI source", guideurl = guideurl) if confirm in [-1, "-1"]: oai_src = get_oai_src(oai_src_id) oai_src_name = oai_src[0][1] oai_src_baseurl = oai_src[0][2] oai_src_prefix = oai_src[0][3] oai_src_frequency = oai_src[0][4] oai_src_config = oai_src[0][5] oai_src_post = oai_src[0][6] oai_src_sets = oai_src[0][7].split() oai_src_bibfilter = oai_src[0][8] text = bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Source name", name = "oai_src_name", value = oai_src_name) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Base URL", name = "oai_src_baseurl", value = oai_src_baseurl) sets = findSets(oai_src_baseurl) if sets: # Show available sets to users sets_specs = [set[0] for set in sets] sets_names = [set[1] for set in sets] sets_labels = [((set[1] and set[0]+' ('+set[1]+')') or set[0]) \ for set in sets] sets_states = [ ((set[0] in oai_src_sets and 1) or 0) for set in sets] text += bibharvest_templates.tmpl_admin_checkboxes(ln=CFG_SITE_LANG, title="Sets", name="oai_src_sets", values=sets_specs, labels=sets_labels, states=sets_states) else: # Let user specify sets in free textbox text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Sets", name='oai_src_sets', value=' '.join(oai_src_sets)) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Metadata prefix", name = "oai_src_prefix", value = oai_src_prefix) text += bibharvest_templates.tmpl_admin_w200_select(ln = CFG_SITE_LANG, title = "Frequency", name = "oai_src_frequency", valuenil = "- select frequency -" , values = freqs, lastval = oai_src_frequency) text += bibharvest_templates.tmpl_admin_w200_select(ln = CFG_SITE_LANG, title = "Postprocess", name = "oai_src_post", valuenil = "- select mode -" , values = posts, lastval = oai_src_post) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "BibConvert configuration file (if needed by postprocess)", name = "oai_src_config", value = oai_src_config) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "BibFilter program (if needed by postprocess)", name = "oai_src_bibfilter", value = oai_src_bibfilter) text += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += createhiddenform(action="editsource#1", text=text, button="Modify", oai_src_id=oai_src_id, ln=ln, confirm=1) if confirm in [1, "1"] and not oai_src_name: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a name for the source.") elif confirm in [1, "1"] and not oai_src_prefix: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a metadata prefix.") elif confirm in [1, "1"] and not oai_src_baseurl: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a base url.") elif confirm in [1, "1"] and not oai_src_frequency: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please choose a frequency of harvesting") elif confirm in [1, "1"] and not oai_src_post: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please choose a postprocess mode") elif confirm in [1, "1"] and oai_src_post.startswith("h-c") and (not oai_src_config or validatefile(oai_src_config)!=0): output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "You selected a postprocess mode which involves conversion.") output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a valid name of or a full path to a BibConvert config file or change postprocess mode.") elif oai_src_id > -1 and confirm in [1, "1"]: if not oai_src_frequency: oai_src_frequency = 0 if not oai_src_config: oai_src_config = "NULL" if not oai_src_post: oai_src_post = "h" res = modify_oai_src(oai_src_id, oai_src_name, oai_src_baseurl, oai_src_prefix, oai_src_frequency, oai_src_config, oai_src_post, oai_src_sets, oai_src_bibfilter) output += write_outcome(res) lnargs = [["ln", ln]] output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/index", title = "Go back to the OAI sources overview", args = lnargs ) body = [output] return addadminbox(subtitle, body) def perform_request_addsource(oai_src_name=None, oai_src_baseurl='', oai_src_prefix='', oai_src_frequency='', oai_src_lastrun='', oai_src_config='', oai_src_post='', ln=CFG_SITE_LANG, confirm=-1, oai_src_sets=[], oai_src_bibfilter=''): """creates html form to add a new source""" if oai_src_name is None: return "No OAI source name selected." subtitle = bibharvest_templates.tmpl_draw_subtitle(ln=CFG_SITE_LANG, title="add source", subtitle="Add new OAI source", guideurl=guideurl) output = "" if confirm <= -1: text = bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) text += bibharvest_templates.tmpl_admin_w200_text(ln=CFG_SITE_LANG, title="Enter the base url", name="oai_src_baseurl", value=oai_src_baseurl+'http://') output = createhiddenform(action="addsource", text=text, ln=ln, button="Validate", confirm=0) if (confirm not in ["-1", -1] and validate(oai_src_baseurl)[0] == 0) or \ confirm in ["1", 1]: output += bibharvest_templates.tmpl_output_validate_info(CFG_SITE_LANG, 0, str(oai_src_baseurl)) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) text = bibharvest_templates.tmpl_admin_w200_text(ln=CFG_SITE_LANG, title="Source name", name="oai_src_name", value=oai_src_name) metadatas = findMetadataFormats(oai_src_baseurl) if metadatas: # Show available metadata to user prefixes = [] for value in metadatas: prefixes.append([value, str(value)]) text += bibharvest_templates.tmpl_admin_w200_select(ln=CFG_SITE_LANG, title="Metadata prefix", name="oai_src_prefix", valuenil="- select prefix -" , values=prefixes, lastval=oai_src_prefix) else: # Let user specify prefix in free textbox text += bibharvest_templates.tmpl_admin_w200_text(ln=CFG_SITE_LANG, title="Metadata prefix", name="oai_src_prefix", value=oai_src_prefix) sets = findSets(oai_src_baseurl) if sets: # Show available sets to users sets_specs = [set[0] for set in sets] sets_names = [set[1] for set in sets] sets_labels = [((set[1] and set[0]+' ('+set[1]+')') or set[0]) \ for set in sets] sets_states = [ ((set[0] in oai_src_sets and 1) or 0) \ for set in sets] text += bibharvest_templates.tmpl_admin_checkboxes(ln=CFG_SITE_LANG, title="Sets", name="oai_src_sets", values=sets_specs, labels=sets_labels, states=sets_states) else: # Let user specify sets in free textbox text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Sets", name='oai_src_sets', value=' '.join(oai_src_sets)) text += bibharvest_templates.tmpl_admin_w200_select(ln = CFG_SITE_LANG, title = "Frequency", name = "oai_src_frequency", valuenil = "- select frequency -" , values = freqs, lastval = oai_src_frequency) text += bibharvest_templates.tmpl_admin_w200_select(ln = CFG_SITE_LANG, title = "Starting date", name = "oai_src_lastrun", valuenil = "- select a date -" , values = dates, lastval = oai_src_lastrun) text += bibharvest_templates.tmpl_admin_w200_select(ln = CFG_SITE_LANG, title = "Postprocess", name = "oai_src_post", valuenil = "- select mode -" , values = posts, lastval = oai_src_post) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "BibConvert configuration file (if needed by postprocess)", name = "oai_src_config", value = oai_src_config) text += bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "BibFilter program (if needed by postprocess)", name = "oai_src_bibfilter", value = oai_src_bibfilter) text += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += createhiddenform(action="addsource#1", text=text, button="Add OAI Source", oai_src_baseurl=oai_src_baseurl, ln=ln, confirm=1) elif confirm in ["0", 0] and validate(oai_src_baseurl)[0] > 0: # Could not perform first url validation lnargs = [["ln", ln]] output += bibharvest_templates.tmpl_output_validate_info(CFG_SITE_LANG, 1, str(oai_src_baseurl)) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/addsource", title = "Try again with another url", args = []) output += """ or """ output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/addsource", title = "Continue anyway", args = [['oai_src_baseurl', urllib.urlencode({'':oai_src_baseurl})[1:]], ['confirm', '1']]) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += """or""" output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/index", title = "Go back to the OAI sources overview", args = lnargs) elif confirm not in ["-1", -1] and validate(oai_src_baseurl)[0] > 0: lnargs = [["ln", ln]] output += bibharvest_templates.tmpl_output_validate_info(CFG_SITE_LANG, 1, str(oai_src_baseurl)) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/addsource", title = "Try again", args = []) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += """or""" output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/index", title = "Go back to the OAI sources overview", args = lnargs) elif confirm not in ["-1", -1]: lnargs = [["ln", ln]] output += bibharvest_templates.tmpl_output_error_info(CFG_SITE_LANG, str(oai_src_baseurl), validate(oai_src_baseurl)[1]) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/addsource", title = "Try again", args = []) output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += """or""" output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/index", title = "Go back to the OAI sources overview", args = lnargs) if confirm in [1, "1"] and not oai_src_name: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a name for the source.") elif confirm in [1, "1"] and not oai_src_prefix: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a metadata prefix.") elif confirm in [1, "1"] and not oai_src_frequency: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please choose a frequency of harvesting") elif confirm in [1, "1"] and not oai_src_lastrun: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please choose the harvesting starting date") elif confirm in [1, "1"] and not oai_src_post: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please choose a postprocess mode") elif confirm in [1, "1"] and oai_src_post.startswith("h-c") and (not oai_src_config or validatefile(oai_src_config)!=0): output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "You selected a postprocess mode which involves conversion.") output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Please enter a valid name of or a full path to a BibConvert config file or change postprocess mode.") elif oai_src_name and confirm in [1, "1"]: if not oai_src_frequency: oai_src_frequency = 0 if not oai_src_lastrun: oai_src_lastrun = 1 if not oai_src_config: oai_src_config = "NULL" if not oai_src_post: oai_src_post = "h" res = add_oai_src(oai_src_name, oai_src_baseurl, oai_src_prefix, oai_src_frequency, oai_src_lastrun, oai_src_config, oai_src_post, oai_src_sets, oai_src_bibfilter) output += write_outcome(res) lnargs = [["ln", ln]] output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/index", title = "Go back to the OAI sources overview", args = lnargs ) body = [output] return addadminbox(subtitle, body) def perform_request_delsource(oai_src_id=None, ln=CFG_SITE_LANG, callback='yes', confirm=0): """creates html form to delete a source """ output = "" subtitle = "" if oai_src_id: oai_src = get_oai_src(oai_src_id) namesrc = (oai_src[0][1]) pagetitle = """Delete OAI source: %s""" % namesrc subtitle = bibharvest_templates.tmpl_draw_subtitle(ln = CFG_SITE_LANG, title = "delete source", subtitle = pagetitle, guideurl = guideurl) output = "" if confirm in ["0", 0]: if oai_src: question = """Do you want to delete the OAI source '%s' and all its definitions?""" % namesrc text = bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, question) text += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 3) output += createhiddenform(action="delsource#5", text=text, button="Confirm", oai_src_id=oai_src_id, confirm=1) else: return bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Source specified does not exist.") elif confirm in ["1", 1]: res = delete_oai_src(oai_src_id) if res[0] == 1: output += bibharvest_templates.tmpl_print_info(CFG_SITE_LANG, "Source removed.") output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 1) output += write_outcome(res) else: output += write_outcome(res) lnargs = [["ln", ln]] output += bibharvest_templates.tmpl_print_brs(CFG_SITE_LANG, 2) output += bibharvest_templates.tmpl_link_with_args(ln = CFG_SITE_LANG, funcurl = "admin/bibharvest/bibharvestadmin.py/index", title = "Go back to the OAI sources overview", args = lnargs ) body = [output] return addadminbox(subtitle, body) def perform_request_testsource(oai_src_id=None, ln=CFG_SITE_LANG, callback='yes', confirm=0, record_id=None): if oai_src_id is None: return "No OAI source ID selected." result = "" guideurl = "help/admin/bibharvest-admin-guide" result += bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "Record ID ( Recognized by the data source )", guideurl=guideurl) record_str = "" if record_id != None: record_str = str(record_id) form_text = bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Record identifier", name = "record_id", value = record_str) result += createhiddenform(action="testsource", text=form_text, button="Test", oai_src_id=oai_src_id, ln=ln, confirm=1) if record_id != None: result += bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "OAI XML downloaded from the source" , guideurl = guideurl) result += bibharvest_templates.tmpl_embed_document( \ "/admin/bibharvest/bibharvestadmin.py/preview_original_xml?oai_src_id=" \ + urllib.quote(str(oai_src_id)) + "&record_id=" \ + urllib.quote(str(record_id))) result += bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "MARC XML after all the transformations", guideurl = guideurl) result += bibharvest_templates.tmpl_embed_document( \ "/admin/bibharvest/bibharvestadmin.py/preview_harvested_xml?oai_src_id=" \ + urllib.quote(str(oai_src_id)) + "&record_id=" \ + urllib.quote(str(record_id))) result += generate_oai_source_operations(ln, oai_src_id) return result ### Probably should be moved to some other data-connection file def format_date(entry): if entry == None: return "(None)" return str(entry.year) + "-" + str(entry.month) + "-" + str(entry.day) def format_time(entry): if entry == None: return "(None)" return str(entry.hour) + ":" + str(entry.minute) + ":" + str(entry.second) def build_history_table(orig_data): headers = ["Date", "record ID", "Reharvest"] result = bibharvest_templates.tmpl_table_begin(headers) last_date = None identifiers = {} for item in orig_data: if last_date == None or last_date.year != item.date.year or last_date.month != item.date.month or last_date.day != item.date.day: result += bibharvest_templates.tmpl_table_row_begin() result += bibharvest_templates.tmpl_table_output_cell("" + format_date(item.date) + "", colspan=2) btn = bibharvest_templates.tmpl_output_select_day_button(item.date.day) result += bibharvest_templates.tmpl_table_output_cell(btn) result += bibharvest_templates.tmpl_table_row_end() result += bibharvest_templates.tmpl_table_row_begin() result += bibharvest_templates.tmpl_table_output_cell(format_date(item.date) + " " + format_time(item.date), cssclass = "oddtablecolumn") result += bibharvest_templates.tmpl_table_output_cell(item.id, cssclass = "pairtablecolumn") identifier = format_date(item.date) + format_time(item.date) + "_" + item.id chkbox = bibharvest_templates.tmpl_output_checkbox(item.id, identifier, "1") result += bibharvest_templates.tmpl_table_output_cell(chkbox, cssclass = "oddtablecolumn") result += bibharvest_templates.tmpl_table_row_end() last_date = item.date if not identifiers.has_key(item.date.day): identifiers[item.date.day] = [] identifiers[item.date.day].append(identifier) result += bibharvest_templates.tmpl_table_end() result += bibharvest_templates.tmpl_output_identifiers(identifiers) return result def perform_request_viewhistory(oai_src_id = None, ln = CFG_SITE_LANG, callback = 'yes', confirm = 0, month = None, year = None): """ Creates html to view the harvesting history """ date = datetime.datetime.now() if year != None and month != None: year = int(year) month = int(month) date = datetime.datetime(year, month, 1) result = "" result += bibharvest_templates.tmpl_output_history_javascript_functions() result += bibharvest_templates.tmpl_output_month_selection_bar(oai_src_id, ln, current_month = month, current_year = year) inner_text = build_history_table(get_history_entries(oai_src_id, date)) inner_text += bibharvest_templates.tmpl_print_brs(ln, 1) inner_text = bibharvest_templates.tmpl_output_scrollable_frame(inner_text) inner_text += bibharvest_templates.tmpl_output_selection_bar() - result += createhiddenform(action="/admin/bibharvest/bibharvestadmin.py/reharvest", text = inner_text, button = "Reharvest selected records", oai_src_id=oai_src_id, ln=ln) + result += createhiddenform(action="/admin/bibharvest/bibharvestadmin.py/reharvest", text = inner_text, button = "Reharvest selected records", oai_src_id = oai_src_id, ln = ln) result += generate_oai_source_operations(ln, oai_src_id) return result ############################################################ ### The functions allowing to preview the harvested XML ### ############################################################ - - def harvest_record(record_id , oai_src_baseurl, oai_src_prefix): """ Harvests given record and returns it's string as a result """ command = CFG_BINDIR + "/bibharvest -vGetRecord -i" + record_id \ + " -p" + oai_src_prefix + " " + oai_src_baseurl program_output = os.popen(command) result = program_output.read(-1) program_output.close() return result def convert_record(oai_src_config, record_to_convert): command = CFG_BINDIR + "/bibconvert -c " + oai_src_config (s_in,s_out,s_err) = os.popen3(command) s_in.write(record_to_convert) s_in.close() s_err.readlines() result = s_out.read(-1) s_err.close() s_out.close() return result def format_record(oai_src_bibfilter, record_to_convert, treat_new = False): """ Formats the record using given formatting program. Returns name of the file containing result, program output, program error output """ (file_descriptor, file_name) = tempfile.mkstemp() f = os.fdopen(file_descriptor, "w") f.write(record_to_convert) f.close() command = oai_src_bibfilter if treat_new: command += " -n" command += " " + file_name (program_input, program_output, program_err) = os.popen3(command) program_input.close() out = program_output.read(-1) err = program_err.read(-1) program_output.close() program_err.close() if os.path.exists(file_name + ".insert.xml"): return (file_name + ".insert.xml", out, err) else: return (None, out, err) def harvest_postprocress_record(oai_src_id, record_id, treat_new = False): oai_src = get_oai_src(oai_src_id) oai_src_baseurl = oai_src[0][2] oai_src_prefix = oai_src[0][3] oai_src_config = oai_src[0][5] oai_src_post = oai_src[0][6] oai_src_sets = oai_src[0][7].split() oai_src_bibfilter = oai_src[0][8] result = harvest_record(record_id, oai_src_baseurl, oai_src_prefix) if result == None: return (False, "Error during harvesting") if oai_src_post.find("c") != -1: result = convert_record(oai_src_config, result) if result == None: return (False, "Error during converting") if oai_src_post.find("f") != -1: fres = format_record(oai_src_bibfilter, result, treat_new = treat_new) fname = fres[0] if fname != None: f = open(fname, "r") result = f.read(-1) f.close() os.remove(fname) else: return (False, "Error during formatting: " + fres[1] + "\n\n" + fres[2]) return (True, result) def upload_record(record = None, uploader_paremeters = "", oai_source_id = None): if record == None: return (file_descriptor, file_name) = tempfile.mkstemp() f = os.fdopen(file_descriptor, "w") f.write(record) f.close() command = CFG_BINDIR + "/bibupload " + uploader_paremeters + " " if oai_source_id != None: command += " -o" + str(oai_source_id) command += " " + file_name out = os.popen(command) output_data = out.read(-1) out.close() def perform_request_preview_original_xml(oai_src_id = None, record_id = None): oai_src = get_oai_src(oai_src_id) oai_src_baseurl = oai_src[0][2] oai_src_prefix = oai_src[0][3] oai_src_config = oai_src[0][5] oai_src_post = oai_src[0][6] oai_src_sets = oai_src[0][7].split() oai_src_bibfilter = oai_src[0][8] record = harvest_record(record_id, oai_src_baseurl, oai_src_prefix) return record def perform_request_preview_harvested_xml(oai_src_id = None, record_id = None): - return harvest_postprocress_record(oai_src_id, record_id) + return harvest_postprocress_record(oai_src_id, record_id, treat_new = True) ############################################################ ### Reharvesting of already existing records ### ############################################################ def perform_request_reharvest_records(oai_src_id = None, ln = CFG_SITE_LANG, confirm=0, record_ids = None): for record_id in record_ids: # 1) Run full harvesing process as in the preview scenarios transformed = harvest_postprocress_record(oai_src_id, record_id, treat_new = True)[1] upload_record(transformed, "-r", oai_src_id) result = bibharvest_templates.tmpl_print_info(ln, "Submitted for inserion into the database") result += generate_oai_source_operations(ln, oai_src_id) return result def perform_request_harvest_record(oai_src_id = None, ln = CFG_SITE_LANG, confirm=0, record_id = None): """ Request for harvesting a new record """ if oai_src_id is None: return "No OAI source ID selected." result = "" guideurl = "help/admin/bibharvest-admin-guide" result += bibharvest_templates.tmpl_draw_titlebar(ln = CFG_SITE_LANG, title = "Record ID ( Recognized by the data source )", guideurl=guideurl) record_str = "" if record_id != None: record_str = str(record_id) form_text = bibharvest_templates.tmpl_admin_w200_text(ln = CFG_SITE_LANG, title = "Record identifier", name = "record_id", value = record_str) result += createhiddenform(action="harvest", text=form_text, button="Harvest", oai_src_id=oai_src_id, ln=ln, confirm=1) if record_id != None: # there was a harvest-request transformed = harvest_postprocress_record(oai_src_id, record_id)[1] upload_record(transformed, "-i", oai_src_id) result += bibharvest_templates.tmpl_print_info(ln, "Submitted for inserion into the database") result += generate_oai_source_operations(ln, oai_src_id) return result ################################################################## ### Here the functions to retrieve, modify, delete and add sources ################################################################## def get_oai_src(oai_src_id=''): """Returns a row parameters for a given id""" sql = "SELECT id,name,baseurl,metadataprefix,frequency,bibconvertcfgfile,postprocess,setspecs,bibfilterprogram FROM oaiHARVEST" try: if oai_src_id: sql += " WHERE id=%s" % oai_src_id sql += " ORDER BY id asc" res = run_sql(sql) return res except StandardError, e: return "" def modify_oai_src(oai_src_id, oai_src_name, oai_src_baseurl, oai_src_prefix, oai_src_frequency, oai_src_config, oai_src_post, oai_src_sets=[], oai_src_bibfilter=''): """Modifies a row's parameters""" try: res = run_sql("UPDATE oaiHARVEST SET name=%s WHERE id=%s", (oai_src_name, oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET baseurl=%s WHERE id=%s", (oai_src_baseurl, oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET metadataprefix=%s WHERE id=%s", (oai_src_prefix, oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET frequency=%s WHERE id=%s", (oai_src_frequency, oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET bibconvertcfgfile=%s WHERE id=%s", (oai_src_config, oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET postprocess=%s WHERE id=%s", (oai_src_post, oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET setspecs=%s WHERE id=%s", (' '.join(oai_src_sets), oai_src_id)) res = run_sql("UPDATE oaiHARVEST SET bibfilterprogram=%s WHERE id=%s", (oai_src_bibfilter, oai_src_id)) return (1, "") except StandardError, e: return (0, e) def add_oai_src(oai_src_name, oai_src_baseurl, oai_src_prefix, oai_src_frequency, oai_src_lastrun, oai_src_config, oai_src_post, oai_src_sets=[], oai_src_bibfilter=''): """Adds a new row to the database with the given parameters""" try: if oai_src_lastrun in [0, "0"]: lastrun_mode = 'NULL' else: lastrun_mode = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # lastrun_mode = "'"+lastrun_mode+"'" run_sql("INSERT INTO oaiHARVEST (id, baseurl, metadataprefix, arguments, comment, bibconvertcfgfile, name, lastrun, frequency, postprocess, bibfilterprogram, setspecs) VALUES (0, %s, %s, NULL, NULL, %s, %s, %s, %s, %s, %s, %s)", \ (oai_src_baseurl, oai_src_prefix, oai_src_config, oai_src_name, lastrun_mode, oai_src_frequency, oai_src_post, oai_src_bibfilter, " ".join(oai_src_sets))) return (1, "") except StandardError, e: return (0, e) def delete_oai_src(oai_src_id): """Deletes a row from the database according to its id""" try: res = run_sql("DELETE FROM oaiHARVEST WHERE id=%s" % oai_src_id) return (1, "") except StandardError, e: return (0, e) def get_tot_oai_src(): """Returns number of rows in the database""" try: sql = "SELECT COUNT(*) FROM oaiHARVEST" res = run_sql(sql) return res[0][0] except StandardError, e: return "" def get_update_status(): """Returns a table showing a list of all rows and their LastUpdate status""" try: sql = "SELECT name,lastrun FROM oaiHARVEST ORDER BY lastrun desc" res = run_sql(sql) return res except StandardError, e: return "" def get_next_schedule(): """Returns the next scheduled oaiharvestrun tasks""" try: sql = "SELECT runtime,status FROM schTASK WHERE proc='oaiharvest' AND runtime > now() ORDER by runtime LIMIT 1" res = run_sql(sql) if len(res)>0: return res[0] else: return ("", "") except StandardError, e: return ("","") def validate(oai_src_baseurl): """This function validates a baseURL by opening its URL and 'greping' for the and tags: Codes: 0 = okay 1 = baseURL not valid 2 = baseURL not found/not existing 3 = tmp directoy is not writable 4 = Unknown error Returns tuple (code, message) """ try: url = oai_src_baseurl + "?verb=Identify" urllib.urlretrieve(url, tmppath) # First check if we have xml oai-pmh output grepOUT1 = os.popen('grep -iwc "" '+tmppath).read() if int(grepOUT2) > 0: #print "Valid!" return (0, '') else: #print "Not valid!" return (1, '') except IOError, (errno, strerror): # Quick error handling for frequent error codes. if errno == 13: return (3, "Please check permission on %s and retry" % CFG_TMPDIR) elif errno == 2 or errno == 'socket error': return (2, "Could not connect with URL %s. Check URL or retry when server is available." % url) return (4, strerror) except StandardError, e: return (4, "An unknown error has occured") except InvalidURL, e: return (2, "Could not connect with URL %s. Check URL or retry when server is available." % url) def validatefile(oai_src_config): """This function checks whether the given path to text file exists or not 0 = okay 1 = file non existing """ CFG_BIBCONVERT_XSL_PATH = "%s%sbibconvert%sconfig" % (CFG_ETCDIR, os.sep, os.sep) path_to_config = (CFG_BIBCONVERT_XSL_PATH + os.sep + oai_src_config) if os.path.exists(path_to_config): # Try to read in config directory try: ftmp = open(path_to_config, 'r') cfgstr= ftmp.read() ftmp.close() if cfgstr!="": #print "Valid!" return 0 except StandardError, e: pass # Try to read as complete path try: ftmp = open(oai_src_config, 'r') cfgstr= ftmp.read() ftmp.close() if cfgstr!="": #print "Valid!" return 0 else: #print "Not valid!" return 1 except StandardError, e: return 1 return 1 def findMetadataFormats(oai_src_baseurl): """This function finds the Metadata formats offered by a OAI repository by analysing the output of verb=ListMetadataFormats""" formats = [] url = oai_src_baseurl + "?verb=ListMetadataFormats" try: urllib.urlretrieve(url, tmppath) except IOError: return formats ftmp = open(tmppath, 'r') xmlstr= ftmp.read() ftmp.close() chunks = xmlstr.split('') count = 0 # first chunk is invalid for chunk in chunks: if count!=0: formats.append(chunk.split('')[0]) count = count + 1 return formats def findSets(oai_src_baseurl): """This function finds the sets offered by a OAI repository by analysing the output of verb=ListSets. Returns list of tuples(SetSpec, SetName)""" url = oai_src_baseurl + "?verb=ListSets" sets = {} try: urllib.urlretrieve(url, tmppath) except IOError: return sets ftmp = open(tmppath, 'r') xmlstr= ftmp.read() ftmp.close() chunks = xmlstr.split('') count = 0 # first chunk is invalid for chunk in chunks: if count!=0: chunks_set = chunk.split('')[1].split("") set_spec = chunks_set[0] #chunks_set[1].split('') check_set_2 = chunks_set[1].split("") set_name = None if len(check_set_2) > 1: set_name = check_set_2[1].split("")[0] sets[set_spec] = [set_spec, set_name] count = count + 1 return sets.values() diff --git a/modules/bibharvest/web/admin/bibharvestadmin.py b/modules/bibharvest/web/admin/bibharvestadmin.py index bc96a9f75..6899f83a4 100644 --- a/modules/bibharvest/web/admin/bibharvestadmin.py +++ b/modules/bibharvest/web/admin/bibharvestadmin.py @@ -1,324 +1,324 @@ ## $Id$ ## ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """CDS Invenio BibHarvest Administrator Interface.""" __revision__ = "$Id$" __lastupdated__ = """$Date$""" import invenio.bibharvestadminlib as bhc from invenio.webpage import page, create_error_box from invenio.config import CFG_SITE_NAME, CFG_SITE_URL, CFG_SITE_LANG from invenio.dbquery import Error from invenio.webuser import getUid, page_not_authorized def index(req, ln=CFG_SITE_LANG): navtrail_previous_links = bhc.getnavtrail() try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: return page(title="BibHarvest Admin Interface", body=bhc.perform_request_index(ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def editsource(req, oai_src_id=None, oai_src_name='', oai_src_baseurl='', oai_src_prefix='', oai_src_frequency='', oai_src_config='', oai_src_post='', ln=CFG_SITE_LANG, mtype='', callback='yes', confirm=-1, oai_src_sets=[], oai_src_bibfilter=''): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: if isinstance(oai_src_sets, str): oai_src_sets = [oai_src_sets] return page(title="Edit OAI Source", body=bhc.perform_request_editsource(oai_src_id=oai_src_id, oai_src_name=oai_src_name, oai_src_baseurl=oai_src_baseurl, oai_src_prefix=oai_src_prefix, oai_src_frequency=oai_src_frequency, oai_src_config=oai_src_config, oai_src_post=oai_src_post, oai_src_sets=oai_src_sets, oai_src_bibfilter=oai_src_bibfilter, ln=ln, confirm=confirm), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def addsource(req, ln=CFG_SITE_LANG, oai_src_name='', oai_src_baseurl ='', oai_src_prefix='', oai_src_frequency='', oai_src_lastrun='', oai_src_config='', oai_src_post='', confirm=-1, oai_src_sets=[], oai_src_bibfilter=''): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: if isinstance(oai_src_sets, str): oai_src_sets = [oai_src_sets] return page(title="Add new OAI Source", body=bhc.perform_request_addsource(oai_src_name=oai_src_name, oai_src_baseurl=oai_src_baseurl, oai_src_prefix=oai_src_prefix, oai_src_frequency=oai_src_frequency, oai_src_lastrun=oai_src_lastrun, oai_src_config=oai_src_config, oai_src_post=oai_src_post, oai_src_sets=oai_src_sets, oai_src_bibfilter=oai_src_bibfilter, ln=ln, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, req=req, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def delsource(req, oai_src_id=None, ln=CFG_SITE_LANG, confirm=0): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: return page(title="Delete OAI Source", body=bhc.perform_request_delsource(oai_src_id=oai_src_id, ln=ln, confirm=confirm), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def testsource(req, oai_src_id=None, ln=CFG_SITE_LANG, confirm=0, record_id = None): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: return page(title="Test OAI Source", body=bhc.perform_request_testsource(oai_src_id=oai_src_id, ln=ln, confirm=confirm, record_id=record_id), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def viewhistory(req, oai_src_id=None, ln=CFG_SITE_LANG, confirm=0, year = None, month = None): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: return page(title="View OAI source harvesting history", body=bhc.perform_request_viewhistory(oai_src_id=oai_src_id, ln=ln, confirm=confirm, year = year, month = month), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def reharvest(req, oai_src_id=None, ln=CFG_SITE_LANG, confirm=0, **records): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: return page(title="OAI source - reharvesting records", body=bhc.perform_request_reharvest_records(oai_src_id=oai_src_id, ln=ln, confirm=confirm, record_ids = records), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) -def harvest(req, oai_src_id=None, ln=CFG_SITE_LANG, confirm=0, record_id=None): +def harvest(req, oai_src_id = None, ln=CFG_SITE_LANG, confirm=0, record_id=None): navtrail_previous_links = bhc.getnavtrail() + """> BibHarvest Admin Interface """ % (CFG_SITE_URL) try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: return page(title="OAI source - harvesting new records", - body=bhc.perform_request_harvest_record(oai_src_id=oai_src_id, + body=bhc.perform_request_harvest_record(oai_src_id = oai_src_id, ln=ln, confirm=confirm, record_id = record_id), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def preview_original_xml(req, oai_src_id = None, ln=CFG_SITE_LANG, record_id = None): try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: if (record_id == None) or (oai_src_id == None): req.content_type = "text/plain"; req.write("No record number provided") return req.content_type = "text/xml" return bhc.perform_request_preview_original_xml(oai_src_id, record_id) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links) def preview_harvested_xml(req, oai_src_id = None, ln=CFG_SITE_LANG, record_id = None): try: uid = getUid(req) except Error, e: return page(title="BibHarvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) auth = bhc.check_user(req,'cfgbibharvest') if not auth[0]: if (record_id == None) or (oai_src_id == None): req.content_type = "text/plain"; req.write("No record number provided") return content = bhc.perform_request_preview_harvested_xml(oai_src_id, record_id) if content[0]: req.content_type = "text/xml" else: req.content_type = "text/plain" return content[1] else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)