def _getfile_py(req, recid=0, docid=0, version="", name="", format="", ln=CFG_SITE_LANG):
     if not recid:
         ## Let's obtain the recid from the docid
         if docid:
             try:
                 bibdoc = BibDoc(docid=docid)
                 recid = bibdoc.get_recid()
             except InvenioWebSubmitFileError, e:
                 return warningMsg(
                     _("An error has happened in trying to retrieve the requested file."), req, CFG_SITE_NAME, ln
                 )
         else:
             return warningMsg(_("Not enough information to retrieve the document"), req, CFG_SITE_NAME, ln)
Example #2
0
def clean_documents():
    """Delete all the bibdocs that have been set as deleted and have not been
    modified since CFG_DELETED_BIBDOC_MAXLIFE days. Returns the number of
    bibdocs involved."""
    write_message("""CLEANING OF OBSOLETED DELETED DOCUMENTS STARTED""")
    write_message("select id from bibdoc where status='DELETED' and NOW()>ADDTIME(modification_date, '%s 0:0:0')" % CFG_DELETED_BIBDOC_MAXLIFE, verbose=9)
    records = run_sql("select id from bibdoc where status='DELETED' and NOW()>ADDTIME(modification_date, '%s 0:0:0')" % CFG_DELETED_BIBDOC_MAXLIFE)
    for record in records:
        bibdoc = BibDoc(record[0])
        bibdoc.expunge()
        write_message("DELETE FROM bibdoc WHERE id=%i" % int(record[0]), verbose=9)
        run_sql("DELETE FROM bibdoc WHERE id=%s", (record[0], ))
    write_message("""%s obsoleted deleted documents cleaned""" % len(records))
    write_message("""CLEANING OF OBSOLETED DELETED DOCUMENTS FINISHED""")
    return len(records)
def bst_openaire_icon_creator():
    """
    """
    docs = run_sql("""
        SELECT f.id_bibdoc
        FROM bibdocfsinfo AS f
        LEFT OUTER JOIN (
            SELECT DISTINCT id_bibdoc, 1
            FROM bibdocfsinfo
            WHERE format LIKE '%;icon' AND last_version=1
        ) AS i ON i.id_bibdoc=f.id_bibdoc
        WHERE i.id_bibdoc is null""")

    icon_size = "90"
    format = "png"

    for docid, in docs:
        d = BibDoc(docid)
        if not d.get_icon():
            for f in d.list_latest_files():
                if not f.is_icon():
                    file_path = f.get_full_path()
                    try:
                        filename = os.path.splitext(os.path.basename(file_path))[0]
                        (icon_dir, icon_name) = create_icon(
                            {'input-file': file_path,
                             'icon-name': "icon-%s" % filename,
                             'multipage-icon': False,
                             'multipage-icon-delay': 0,
                             'icon-scale': icon_size,
                             'icon-file-format': format,
                             'verbosity': 0})
                        icon_path = os.path.join(icon_dir, icon_name)
                    except InvenioWebSubmitIconCreatorError, e:
                        register_exception(prefix='Icon for file %s could not be created: %s' % \
                                           (file_path, str(e)),
                                           alert_admin=False)

                    try:
                        if os.path.exists(icon_path):
                            d.add_icon(icon_path)
                    except InvenioBibDocFileError, e:
                        register_exception(prefix='Icon %s for file %s could not be added to document: %s' % \
                                           (icon_path, f, str(e)),
                                           alert_admin=False)
def fix_bibdoc_bibdoc(id_bibdoc1, id_bibdoc2, logfile):
    """
    Migrate an icon.
    """

    try:
        the_bibdoc = BibDoc.create_instance(id_bibdoc1)
    except Exception, err:
        msg = "WARNING: when opening docid %s: %s" % (id_bibdoc1, err)
        print >> logfile, msg
        print msg
        return True
    def _getfile_py(req, recid=0, docid=0, version="", name="", format="", ln=CFG_SITE_LANG):
        if not recid:
            ## Let's obtain the recid from the docid
            if docid:
                try:
                    bibdoc = BibDoc(docid=docid)
                    recid = bibdoc.get_recid()
                except InvenioBibDocFileError:
                    return warning_page(_("An error has happened in trying to retrieve the requested file."), req, ln)
            else:
                return warning_page(_('Not enough information to retrieve the document'), req, ln)
        else:
            if not name and docid:
                ## Let's obtain the name from the docid
                try:
                    bibdoc = BibDoc(docid)
                    name = bibdoc.get_docname()
                except InvenioBibDocFileError:
                    return warning_page(_("An error has happened in trying to retrieving the requested file."), req, ln)

        format = normalize_format(format)

        redirect_to_url(req, '%s/%s/%s/files/%s%s?ln=%s%s' % (CFG_SITE_URL, CFG_SITE_RECORD, recid, name, format, ln, version and 'version=%s' % version or ''), apache.HTTP_MOVED_PERMANENTLY)
            ## Let's obtain the recid from the docid
            if docid:
                try:
                    bibdoc = BibDoc(docid=docid)
                    recid = bibdoc.get_recid()
                except InvenioWebSubmitFileError, e:
                    return warningMsg(
                        _("An error has happened in trying to retrieve the requested file."), req, CFG_SITE_NAME, ln
                    )
            else:
                return warningMsg(_("Not enough information to retrieve the document"), req, CFG_SITE_NAME, ln)
        else:
            if not name and docid:
                ## Let's obtain the name from the docid
                try:
                    bibdoc = BibDoc(docid)
                    name = bibdoc.get_docname()
                except InvenioWebSubmitFileError, e:
                    return warningMsg(
                        _("An error has happened in trying to retrieving the requested file."), req, CFG_SITE_NAME, ln
                    )

        format = normalize_format(format)

        redirect_to_url(
            req,
            "%s/%s/%s/files/%s%s?ln=%s%s"
            % (CFG_SITE_URL, CFG_SITE_RECORD, recid, name, format, ln, version and "version=%s" % version or ""),
            apache.HTTP_MOVED_PERMANENTLY,
        )
Example #7
0
    Migrate an icon.
    """

    try:
        the_bibdoc = BibDoc(id_bibdoc1)
    except Exception, err:
        msg = "WARNING: when opening docid %s: %s" % (id_bibdoc1, err)
        print >> logfile, msg
        print msg
        return True
    try:
        recid = the_bibdoc.get_recid()
        msg = "Fixing icon for recid %s: document %s (docid %s)" % (recid, the_bibdoc.get_docname(), id_bibdoc1)
        print msg,
        print >> logfile, msg,
        the_icon = BibDoc(id_bibdoc2)
        for a_file in the_icon.list_latest_files():
            the_bibdoc.add_icon(a_file.get_full_path(), format=a_file.get_format())
        the_icon.delete()
        run_sql("DELETE FROM bibdoc_bibdoc WHERE id_bibdoc1=%s AND id_bibdoc2=%s", (id_bibdoc1, id_bibdoc2))
        print "OK"
        print >> logfile, "OK"
        return True
    except Exception, err:
        print "ERROR: %s" % err
        print >> logfile, "ERROR: %s" % err
        register_exception()
        return False

def main():
    """Core loop."""
 def foo(docid):
     bd = BibDoc(docid)
     dummy_bf = bd.list_all_files()
    """
    Migrate an icon.
    """

    try:
        the_bibdoc = BibDoc.create_instance(id_bibdoc1)
    except Exception, err:
        msg = "WARNING: when opening docid %s: %s" % (id_bibdoc1, err)
        print >> logfile, msg
        print msg
        return True
    try:
        msg = "Fixing icon for the document %s" % (id_bibdoc1,)
        print msg,
        print >> logfile, msg,
        the_icon = BibDoc.create_instance(id_bibdoc2)
        for a_file in the_icon.list_latest_files():
            the_bibdoc.add_icon(a_file.get_full_path(), format=a_file.get_format())
        the_icon.delete()
        run_sql("DELETE FROM bibdoc_bibdoc WHERE id_bibdoc1=%s AND id_bibdoc2=%s", (id_bibdoc1, id_bibdoc2))
        print "OK"
        print >> logfile, "OK"
        return True
    except Exception, err:
        print "ERROR: %s" % err
        print >> logfile, "ERROR: %s" % err
        register_exception()
        return False


def main():
atypes = ('Main', '') # list of initial doctypes to be changed from
btype = 'INSPIRE-PUBLIC' # final doctype value to be changed into

import os
from invenio.bibdocfile import BibDoc
from invenio.dbquery import run_sql

for atype in atypes:
    res = run_sql("SELECT id_bibrec,id_bibdoc FROM bibrec_bibdoc WHERE type=%s",(atype,))
    for row in res:
        id_bibrec, id_bibdoc = row
        abibdoc = BibDoc(recid=id_bibrec, docid=id_bibdoc)
        abibdoc_type_pathname = os.path.join(abibdoc.get_base_dir(), '.type')
        # update DB value:
        run_sql("""UPDATE bibrec_bibdoc SET type=%s WHERE type=%s AND id_bibrec=%s AND id_bibdoc=%s""", 
        (btype, atype, id_bibrec, id_bibdoc))
        # update file value:
        fdesc = open(abibdoc_type_pathname, 'w')
        fdesc.write(btype)
        fdesc.close()
        # print info
        print "I: updated record %s file %s" % (id_bibrec, abibdoc_type_pathname)