# $Id$ # $URL$ logger = logging.getLogger('meresco.availability') logger.debug("Starting logger") availabilityConfig = configs['availability'] collectionString = availabilityConfig.get('collectionList', section="collections") if collectionString == None: logger.error("No collections found!") collectionString = "NO,COLLECTIONS,FOUND" exceptionString = availabilityConfig.get('exceptionList', section="collections") if exceptionString == None: logger.error("No exceptions found!") exceptionString = "NO,EXCEPTIONS,FOUND" collections = collectionString.split("\n") exceptions = exceptionString.split("\n") #infra.dd('collections', collections) #FIXME: config namespaceMap = { 'mods': 'http://www.loc.gov/mods/v3' } def inDepot(location): global collections global exceptions # logging.debug("location:" + location) for exception in exceptions: # logging.debug("exception: " + exception) if re.match(exception+'\s',location): return False for collection in collections: # logging.debug("collection: " + collection) if re.match(collection+'\s',location): return True return False def getLocator(recordId, mods): sid = any.getSid(recordId) locator = any.createOpenURL(mods) # TP: use the following for testing with locator @ bzv.uvt.nl # locator = "/availability/?" + any.createOpenURL(mods).split('?')[1] return locator + '&sid=' + sid def getAvailabilityByOpenurl(recordId, mods, ID): locator = getLocator(recordId, mods) yield """ """ % {'locator' : locator, 'id' : ID } def getAvailabilityByUitleencode(mods, genre, recordId, ID ): # uitleencodes # a = titel in bestelling # c = niet balie, wel IBL # d = wel balie, niet IBL # e = elektronisch beschikbaar # g = geblokkeerd # o = onbekend # s = speciale toestemming # z = boek zoek # f = niet uitleenbaar, wel fotokopie # i = niet uitleenbaar, geen fotokopie, wel inzage # u = normaal uitleenbaar # b = beperkt uitleenbaar depot = availabilityConfig.get('depot', section="storageList",default='IN DEPOT') library = availabilityConfig.get('library', section="storageList",default='IN LIBRARY') journal = availabilityConfig.get('journal', section="storageList",default='JOURNAL') data = {} documentStorageList = ['locator','depot','library','journal'] for storage in documentStorageList: data[storage] = [] for copyInformation in mods.xpath("//mods:location/mods:holdingSimple/mods:copyInformation", namespaceMap): uitleencode = copyInformation.xpath("mods:note[@type='status']/text()", namespaceMap) ######### Er zijn ook elektronische boeken, hebben geen shelfLocator, maar een electronicLocator ######### met URL. l = copyInformation.xpath("mods:shelfLocator/text()", namespaceMap) if l: location = l[0] else: u = copyInformation.xpath("mods:electronicLocator/text()", namespaceMap) if u: url = u[0] if uitleencode and location: # niet uitleenbaar if uitleencode[0] == 'i' or uitleencode[0] == 'f': if inDepot(location): # FIXME: config (tucat) data['depot'].append('%(loc)s' %{'loc': location}) # niet in depot: elif genre == 'journal': # FIXME: config (tuts) data['journal'].append('%(loc)s' %{'loc': location}) else: data['library'].append(location) elif uitleencode[0] == 'u' or uitleencode[0] == 'b': data['locator'].append(copyInformation) elif url: yield 'Electronic book' %(url) for storage in documentStorageList: if storage == 'locator' and data[storage]: for copyInformation in data['locator']: EPN = copyInformation.xpath("mods:note[@type='epn']/text()", namespaceMap)[0] if EPN: location = copyInformation.xpath("mods:shelfLocator/text()", namespaceMap) location = location and location[0] or '' if location: locator = getLocator(recordId, mods) + "&epn=" + EPN yield """ """ %{'id':ID, 'loc': location, 'inDepot': inDepot(location), 'genre': genre, 'locator': locator} elif storage == 'depot' and data[storage]: yield '
  • %(title)s
  • ' %{'title':depot} for el in data[storage]: yield '
  • %(el)s
  • ' %{'el':el} elif storage == 'library' and data[storage]: yield '
  • %(title)s
  • ' %{'title':library} for el in data[storage]: yield '
  • %(el)s
  • ' %{'el':el} elif storage == 'journal' and data[storage]: yield '
  • %(title)s
  • ' %{'title':journal} for el in data[storage]: yield '
  • %(el)s
  • ' %{'el':el} def main(index=0, record={}, recordId=''): fulltext = availabilityConfig.get('fulltext', section="storageList",default='DIRECT LINK') db, rid = recordId.split(':', 1) urls = 0 if 'URL(s)' in record: urls = 1 genre = '' if 'Publication type' in record: genre = record['Publication type'] mods = any.getMods(recordId) # Note: 'id' is a python builtin # NOTE: 'id' IS A PYTHON BUILTIN!!!!!! ID = 'AvID' + str(index) yield ''