Example #1
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)