has_bibdocs=run_sql("SELECT count(id_bibdoc) FROM bibrec_bibdoc JOIN bibdoc ON id_bibdoc=id WHERE id_bibrec=%s AND status<>'DELETED'",(rec_id,))[0][0]>0
write_message('Found recid %s for extoaiid="%s" with provenance="%s"'%(id_bibrec,extoaiid,extoaisrc),verbose=9)
ret.add(id_bibrec)
break
ifthis_extoaisrcisNone:
write_message('WARNING: Found recid %s for extoaiid="%s" that doesn\'t specify any provenance, while input record does.'%(id_bibrec,extoaiid),stream=sys.stderr)
ifextoaisrcisNone:
write_message('WARNING: Found recid %s for extoaiid="%s" that specify a provenance (%s), while input record does not have a provenance.'%(id_bibrec,extoaiid,this_extoaisrc),stream=sys.stderr)
returnret
exceptError,error:
write_message(" Error during find_records_from_extoaiid(): %s "
%error,verbose=1,stream=sys.stderr)
raise
deffind_record_from_oaiid(oaiid):
"""
Try to find record in the database from the OAI ID number and OAI SRC.
Return record ID if found, None otherwise.
"""
bibxxx='bib'+CFG_OAI_ID_FIELD[0:2]+'x'
bibrec_bibxxx='bibrec_'+bibxxx
try:
res=run_sql("""SELECT bb.id_bibrec FROM %(bibrec_bibxxx)s AS bb,
%(bibxxx)s AS b WHERE b.tag=%%s AND b.value=%%s
AND bb.id_bibxxx=b.id"""% \
{'bibxxx':bibxxx,
'bibrec_bibxxx':bibrec_bibxxx},
(CFG_OAI_ID_FIELD,oaiid,))
exceptError,error:
write_message(" Error during find_record_from_oaiid(): %s "%error,
verbose=1,stream=sys.stderr)
ifres:
returnres[0][0]
else:
returnNone
defextract_tag_from_record(record,tag_number):
""" Extract the tag_number for record."""
# first step verify if the record is not already in the database
write_message("('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') not inserted because format already exists (%s)."%(url,format,docname,doctype,newname,description,comment,flags,e),stream=sys.stderr)
raise
exceptException,e:
write_message("Error in adding '%s' as a new format because of: %s"%(url,e),stream=sys.stderr)
write_message('Just updating description and comment for %s with format %s with description %s, comment %s and flags %s'%(docname,format,description,comment,flags),verbose=9)
try:
ifnotpretend:
bibdoc.set_description(description,format)
bibdoc.set_comment(comment,format)
forflaginCFG_BIBDOCFILE_AVAILABLE_FLAGS:
ifflaginflags:
bibdoc.set_flag(flag,format)
else:
bibdoc.unset_flag(flag,format)
exceptStandardError,e:
write_message("('%s', '%s', '%s', '%s', '%s') description and comment not updated because '%s'."%(docname,format,description,comment,flags,e))
raise
returnTrue
ifmode=='delete':
raiseStandardError('FFT tag specified but bibupload executed in --delete mode')
query="""UPDATE oaiHARVESTLOG SET date_inserted=NOW(), inserted_to_db=%s, id_bibrec=%s WHERE oai_id = %s AND bibupload_task_id = %s ORDER BY date_harvested LIMIT 1"""