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)
""" 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.""" check_running_process_user()
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