Example #1
0
	def iter_all(self, etype, eids = []):
		eids = set(eids)
		coll_path, ext = self._entity_meta(etype)
		if not os.path.exists(coll_path):
			return

		for filename in os.listdir(coll_path):
			path = os.path.join(coll_path, filename)
			if not path.endswith("." + ext):
				continue

			try:
				if ext == "xml":
					root = etree.parse(path).getroot()
					data = dataelement_from_xml(root)
				else:
					data = dataelement_from_json_path(path)
			except:
				self.log.error("Error loading and parsing document {}".format(path))
				raise
			
			if len(eids) == 0 or data["id"] in eids:
				data["__doc_path"] = path
				data["__type"] = etype
				yield data
Example #2
0
	def find(self, eid, etype):
		coll_path, ext = self._entity_meta(etype)
		path = os.path.join(coll_path, "%s.%s" % (eid, ext))
		if not os.path.exists(path):
			self.log.error("%s with id %s not found at %s" % (etype, eid, path))
			return None

		if ext == "xml":
			root = etree.parse(path).getroot()
			data = dataelement_from_xml(root)
		else:
			data = dataelement_from_json_path(path)

		data["__doc_path"] = path
		data["__type"] = etype
		return data