## Let's set a reasonable timeout for URL request (e.g. FFT)
socket.setdefaulttimeout(40)
defparse_identifier(identifier):
"""Parse the identifier and determine if it is temporary or fixed"""
id_str=str(identifier)
ifnotid_str.startswith("TMP:"):
return(False,identifier)
else:
return(True,id_str[4:])
defresolve_identifier(tmps,identifier):
"""Resolves an identifier. If the identifier is not temporary, this
function is an identity on the second argument. Otherwise, a resolved
value is returned or an exception raised"""
is_tmp,tmp_id=parse_identifier(identifier)
ifis_tmp:
ifnottmp_idintmps:
raiseStandardError("Temporary identifier %s not present in the dictionary"%(tmp_id,))
iftmps[tmp_id]==-1:
# the identifier has been signalised but never assigned a value - probably error during processing
raiseStandardError("Temporary identifier %s has been declared, but never assigned a value. Probably an error during processign of an appropriate FFT has happened. Please see the log"%(tmp_id,))
bibcatalog_system.ticket_submit(subject="%s: %s by %s"%(msg,rec_id,user),recordid=rec_id,text=text,queue=CFG_BIBUPLOAD_CONFLICTING_REVISION_TICKET_QUEUE,owner=uid)
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
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
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,))
ifres:
returnres[0][0]
else:
returnNone
deffind_record_from_doi(doi):
"""
Try to find record in the database from the given DOI.
write_message('Just updating description and comment for %s with format %s with description %s, comment %s and flags %s'%(docname,docformat,description,comment,flags),verbose=9)
try:
ifnotpretend:
bibdoc.set_description(description,docformat)
bibdoc.set_comment(comment,docformat)
forflaginCFG_BIBDOCFILE_AVAILABLE_FLAGS:
ifflaginflags:
bibdoc.set_flag(flag,docformat)
else:
bibdoc.unset_flag(flag,docformat)
exceptStandardError,e:
write_message("('%s', '%s', '%s', '%s', '%s') description and comment not updated because '%s'."%(docname,docformat,description,comment,flags,e))
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"""