"Returns the first MySQL BIB ID for the OAI identifier 'identifier', if it exists."
sysno=None
ifidentifier:
query="SELECT DISTINCT(bb.id_bibrec) FROM bib%sx AS bx, bibrec_bib%sx AS bb WHERE bx.tag='%s' AND bb.id_bibxxx=bx.id AND bx.value='%s'"%(oaiidfield[0:2],oaiidfield[0:2],oaiidfield,identifier)
res=run_sql(query)
forrowinres:
sysno=row[0]
returnsysno
defOAIGetSysnoList(set,fromDate,untilDate):
"Returns list of system numbers for the OAI set 'set', modified from 'date_from' until 'date_until'."
out_dict={}# dict to hold list of out sysnos as its keys
ifset:
query="SELECT DISTINCT bibx.id_bibrec FROM bib%sx AS bx LEFT JOIN bibrec_bib%sx AS bibx ON bx.id=bibx.id_bibxxx LEFT JOIN bibrec AS b ON b.id=bibx.id_bibrec WHERE bx.tag='%s' AND bx.value='%s'"%(oaiidfield[0:2],oaiidfield[0:2],oaisetfield,set)
else:
query="SELECT DISTINCT bibx.id_bibrec FROM bib%sx AS bx LEFT JOIN bibrec_bib%sx AS bibx ON bx.id=bibx.id_bibxxx LEFT JOIN bibrec AS b ON b.id=bibx.id_bibrec WHERE bx.tag='%s'"%(oaiidfield[0:2],oaiidfield[0:2],oaiidfield)
ifuntilDate:
query=query+" AND b.modification_date <= '%s'"%untilDate
iffromDate:
query=query+" AND b.modification_date >= '%s'"%fromDate
res=run_sql(query)
forrowinres:
out_dict[row[0]]=1
returnout_dict.keys()
defis_deleted(recId):
"Check if record with recId has been deleted. Return 1 if deleted."
query="select a.id from bibrec as a left join bibrec_bib98x as b on a.id=b.id_bibrec left join bib98x as c on b.id_bibxxx=c.id where c.value='DELETED' and a.id=%s"%recId
res=run_sql(query)
foriteminres:
ifitem==None:
return0
else:
return1
defOAIGenResumptionToken():
"Generates unique ID for resumption token management."
returnmd5.new(str(time.time())).hexdigest()
defOAICacheIn(resumptionToken,sysnos):
"Stores or adds sysnos in cache. Input is a string of sysnos separated by commas."
filename="%s/RTdata/%s"%(logdir,resumptionToken)
fil=open(filename,"w")
cPickle.dump(sysnos,fil)
fil.close()
return1
defOAICacheOut(resumptionToken):
"Restores string of comma-separated system numbers from cache."
sysnos=[]
filename="%s/RTdata/%s"%(logdir,resumptionToken)
ifOAICacheStatus(resumptionToken):
fil=open(filename,"r")
sysnos=cPickle.load(fil)
fil.close()
else:
return0
returnsysnos
defOAICacheClean():
"Removes cached resumptionTokens older than specified"
</protect>
oai_rt_expire=<OAIEXPIRE>
<protect>
directory="%s/RTdata"%logdir
files=os.listdir(directory)
forfinfiles:
filename=directory+"/"+f
# cache entry expires when not modified during a specified period of time