- if pdh not in self.collections:
- logger.debug("Creating collection reader for %s", pdh)
- self.collections[pdh] = arvados.collection.CollectionReader(pdh, api_client=self.api_client,
- keep_client=self.keep_client)
- return self.collections[pdh]
+ if locator not in self.collections:
+ m = pdh_size.match(locator)
+ if m:
+ self.cap_cache(int(m.group(2)) * 128)
+ logger.debug("Creating collection reader for %s", locator)
+ try:
+ cr = arvados.collection.CollectionReader(locator, api_client=self.api_client,
+ keep_client=self.keep_client,
+ num_retries=self.num_retries)
+ except arvados.errors.ApiError as ap:
+ raise IOError(errno.ENOENT, "Could not access collection '%s': %s" % (locator, str(ap._get_reason())))
+ sz = len(cr.manifest_text()) * 128
+ self.collections[locator] = (cr, sz)
+ self.total += sz
+ else:
+ cr, sz = self.collections[locator]
+ # bump it to the back
+ del self.collections[locator]
+ self.collections[locator] = (cr, sz)
+ return cr