Пример #1
0
 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)
Пример #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)
Пример #3
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)
Пример #4
0
def check(id_):
    """Check bibdocs."""
    BibRecDocs, BibDoc = _import_bibdoc()

    try:
        BibDoc(id_).list_all_files()
    except Exception:
        click.secho("BibDoc {0} failed check.".format(id_), fg='red')
Пример #5
0
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
Пример #6
0
def fix_bibdoc_bibdoc(id_bibdoc1, id_bibdoc2, logfile):
    """
    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
Пример #7
0
    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)
Пример #8
0
def get_bibdoc(recid):
    """
    Retrieves using BibDoc all the files related with a given record

    @param recid

    @return BibDoc of the given record
    """
    if not recid or recid < 0:
        return None

    from invenio.bibdocfile import BibDoc, InvenioBibDocFileError
    try:
        return BibDoc(int(recid))
    except InvenioBibDocFileError:
        return None
Пример #9
0
    def _getfile_py(req,
                    recid=0,
                    docid=0,
                    version="",
                    name="",
                    docformat="",
                    ln=CFG_SITE_LANG):
        if not recid:
            ## Let's obtain the recid from the docid
            if docid:
                try:
                    bibdoc = BibDoc(docid=docid)
                    recid = bibdoc.bibrec_links[0]["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:
            brd = BibRecDocs(recid)
            if not name and docid:
                ## Let's obtain the name from the docid
                try:
                    name = brd.get_docname(docid)
                except InvenioBibDocFileError:
                    return warning_page(
                        _("An error has happened in trying to retrieving the requested file."
                          ), req, ln)

        docformat = normalize_format(docformat)

        redirect_to_url(
            req, '%s/%s/%s/files/%s%s?ln=%s%s' %
            (CFG_SITE_URL, CFG_SITE_RECORD, recid, name, docformat, ln,
             version and 'version=%s' % version or ''),
            apache.HTTP_MOVED_PERMANENTLY)
Пример #10
0
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)
Пример #11
0
            ## 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,
        )
Пример #12
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."""
Пример #13
0
 def foo(docid):
     bd = BibDoc(docid)
     dummy_bf = bd.list_all_files()
Пример #14
0
    """

    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
Пример #15
0
def openaire_create_icon(docid=None, recid=None, reformat=True):
    """
    Celery task to create an icon for all documents in a given record or for
    just a specific document.
    """
    if recid:
        docs = BibRecDocs(recid).list_bibdocs()
    else:
        docs = [BibDoc(docid)]

    # Celery task will fail if BibDoc does not exists (on purpose ;-)
    for d in docs:
        logger.debug("Checking document %s" % d)
        if not d.get_icon(subformat_re=re.compile(ICON_SUBFORMAT)):
            logger.debug("Document has no icon")
            for f in d.list_latest_files():
                logger.debug("Checking file %s" % f)
                if not f.is_icon():
                    logger.debug("File not an icon")
                    file_path = f.get_full_path()
                    icon_path = None
                    try:
                        filename = os.path.splitext(
                            os.path.basename(file_path))[0]
                        logger.info("Creating icon from file %s" % file_path)
                        (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':
                            ICON_FILEFORMAT,
                            'verbosity':
                            0
                        })
                        icon_path = os.path.join(icon_dir, icon_name)
                    except InvenioWebSubmitIconCreatorError, e:
                        logger.warning(
                            'Icon for file %s could not be created: %s' %
                            (file_path, str(e)))
                        register_exception(
                            prefix='Icon for file %s could not be created: %s'
                            % (file_path, str(e)),
                            alert_admin=False)

                    try:
                        if icon_path and os.path.exists(icon_path):
                            logger.debug("Adding icon %s to document" %
                                         icon_path)
                            d.add_icon(icon_path, subformat=ICON_SUBFORMAT)
                            recid_list = ",".join(
                                [str(x['recid']) for x in d.bibrec_links])
                            if reformat:
                                task_low_level_submission(
                                    'bibreformat', 'openaire', '-i',
                                    recid_list)

                    except InvenioBibDocFileError, e:
                        logger.warning(
                            'Icon %s for file %s could not be added to document: %s'
                            % (icon_path, f, str(e)))
                        register_exception(
                            prefix=
                            'Icon %s for file %s could not be added to document: %s'
                            % (icon_path, f, str(e)),
                            alert_admin=False)
Пример #16
0
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)
Пример #17
0
    """
    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():
    """Core loop."""
Пример #18
0
 def foo(docid):
     bd = BibDoc(docid)
     dummy_bf = bd.list_all_files()
Пример #19
0
    """
    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():