[models] Add get_chunk_by_path to CDL

This commit is contained in:
derrod 2020-05-09 11:02:31 +02:00
parent d94d07a26b
commit 3257b869e2

View file

@ -277,6 +277,18 @@ class CDL:
self._manifest_version = 17 self._manifest_version = 17
self._guid_map = None self._guid_map = None
self._guid_int_map = None self._guid_int_map = None
self._path_map = None
def get_chunk_by_path(self, path):
if not self._path_map:
self._path_map = dict()
for index, chunk in enumerate(self.elements):
self._path_map[chunk.path] = index
index = self._path_map.get(path, None)
if index is None:
raise ValueError(f'Invalid path! "{path}"')
return self.elements[index]
def get_chunk_by_guid(self, guid): def get_chunk_by_guid(self, guid):
""" """