<commit_before>## $Id$
## Administrator interface for the OAI repository and archive

## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 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 OAI Repository and Archive Administrator Interface."""

__revision__ = "$Id$"

import sys
import cgi
import re
import Numeric
import os
import string
import ConfigParser
import time
import random
import urllib
import sre
from mod_python import apache

from invenio.config import \
     cdslang, \
     tmpdir, \
     version, \
     weburl
import invenio.access_control_engine as access_manager
from invenio.dbquery import run_sql, escape_string
from invenio.webpage import page, pageheaderonly, pagefooteronly
from invenio.webuser import getUid, get_email
from invenio.oaiarchive_engine import parse_set_definition
import invenio.template
bibharvest_templates = invenio.template.load('bibharvest')

tmppath = tmpdir + '/oaiarchiveadmin.' + str(os.getpid())
guideurl = "admin/bibharvest/guide.html"

def getnavtrail(previous = ''):
    """Get navtrail"""
    return bibharvest_templates.tmpl_getnavtrail(previous = previous, ln = cdslang)

def perform_request_index(ln=cdslang):
    """OAI archive admin index"""

    titlebar = bibharvest_templates.tmpl_draw_titlebar(ln = cdslang,
                                                       weburl = weburl,
                                                       title = "OAI repository",
                                                       guideurl = guideurl,
                                                       extraname = "add new OAI set",
                                                       extraurl = "admin/bibharvest/oaiarchiveadmin.py/addset")

    header = ['id','setSpec','setName','setCollection','p1','f1','m1','p2','f2','m2','p3','f3','m3','','','']

    oai_set = get_oai_set()
    sets = []
    
    for (id, setSpec, setName, setCollection, setDescription, p1, f1, m1, p2, f2, m2, p3, f3, m3) in oai_set:

        del_request = '<a href="' + weburl + "/" + "admin/bibharvest/oaiarchiveadmin.py/delset?ln=" + ln + "&oai_set_id=" + str(id) + '">delete</a>'
        
        edit_request = '<a href="' + weburl + "/" + "admin/bibharvest/oaiarchiveadmin.py/editset?ln=" + ln + "&oai_set_id=" + str(id) + '">edit</a>'

        sets.append([id, setSpec, setName, setCollection, p1,f1,m1, p2,f2,m2, p3,f3,m3, del_request, edit_request])

    add_request = '<a href="' + weburl + "/" + "admin/bibharvest/oaiarchiveadmin.py/addset?ln=" + ln + '">Add new OAI set definition</a>'
    
    sets.append(['',add_request,'','','','','','','','','','','',''])

    out = transform_tuple(header=header, tuple=sets)
    
    out += "<br /><br />"

    return out


def perform_request_addset(oai_set_name='', oai_set_spec='', oai_set_collection='', oai_set_description='', oai_set_definition='', oai_set_reclist='', oai_set_p1='', oai_set_f1='',oai_set_m1='', oai_set_p2='', oai_set_f2='', oai_set_m2='', oai_set_p3='', oai_set_f3='', oai_set_m3='', ln=cdslang, func=0):
    """add a new OAI set"""

    out  = ""<commit_msg>Added notice of the need to run oaiarchive utility for the settings in 'OAI Repository Interface' to be taken into account.<commit_after>## $Id$
## Administrator interface for the OAI repository and archive

## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 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 OAI Repository and Archive Administrator Interface."""

__revision__ = "$Id$"

import sys
import cgi
import re
import Numeric
import os
import string
import ConfigParser
import time
import random
import urllib
import sre
from mod_python import apache

from invenio.config import \
     cdslang, \
     tmpdir, \
     version, \
     weburl
import invenio.access_control_engine as access_manager
from invenio.dbquery import run_sql, escape_string
from invenio.webpage import page, pageheaderonly, pagefooteronly
from invenio.webuser import getUid, get_email
from invenio.oaiarchive_engine import parse_set_definition
import invenio.template
bibharvest_templates = invenio.template.load('bibharvest')

tmppath = tmpdir + '/oaiarchiveadmin.' + str(os.getpid())
guideurl = "admin/bibharvest/guide.html"

def getnavtrail(previous = ''):
    """Get navtrail"""
    return bibharvest_templates.tmpl_getnavtrail(previous = previous, ln = cdslang)

def perform_request_index(ln=cdslang):
    """OAI archive admin index"""

    out = '''<p>Define below the sets to expose through the OAI harvesting
    protocol. <br /> You will have to run the
    <a href="guide.html#3.2"><code>oaiarchive</code></a>
    utility to apply the settings you have defined here.</p>'''

    titlebar = bibharvest_templates.tmpl_draw_titlebar(ln = cdslang,
                                                       weburl = weburl,
                                                       title = "OAI repository",
                                                       guideurl = guideurl,
                                                       extraname = "add new OAI set",
                                                       extraurl = "admin/bibharvest/oaiarchiveadmin.py/addset")

    header = ['id','setSpec','setName','setCollection','p1','f1','m1','p2','f2','m2','p3','f3','m3','','','']

    oai_set = get_oai_set()
    sets = []
    
    for (id, setSpec, setName, setCollection, setDescription, p1, f1, m1, p2, f2, m2, p3, f3, m3) in oai_set:

        del_request = '<a href="' + weburl + "/" + "admin/bibharvest/oaiarchiveadmin.py/delset?ln=" + ln + "&oai_set_id=" + str(id) + '">delete</a>'
        
        edit_request = '<a href="' + weburl + "/" + "admin/bibharvest/oaiarchiveadmin.py/editset?ln=" + ln + "&oai_set_id=" + str(id) + '">edit</a>'

        sets.append([id, setSpec, setName, setCollection, p1,f1,m1, p2,f2,m2, p3,f3,m3, del_request, edit_request])

    add_request = '<a href="' + weburl + "/" + "admin/bibharvest/oaiarchiveadmin.py/addset?ln=" + ln + '">Add new OAI set definition</a>'
    
    sets.append(['',add_request,'','','','','','','','','','','',''])

    out += transform_tuple(header=header, tuple=sets)
    
    out += "<br /><br />"

    return out


def perform_request_addset(oai_set_name='', oai_set_spec='', oai_set_collection='', oai_set_description='', oai_set_definition='', oai_set_reclist='', oai_set_p1='', oai_set_f1='',oai_set_m1='', oai_set_p2='', oai_set_f2='', oai_set_m2='', oai_set_p3='', oai_set_f3='', oai_set_m3='', ln=cdslang, func=0):
    """add a new OAI set"""

    out  = ""
{'fraction_non_alphanumeric': 0.13282038345105954, 'fraction_numerical': 0.018415741675075682, 'mean_word_length': 3.251474530831099, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140463', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2506, 'n_words': 728}