From 3257b869e2026c798aa720462e30caba3eaa9a35 Mon Sep 17 00:00:00 2001 From: derrod Date: Sat, 9 May 2020 11:02:31 +0200 Subject: [PATCH] [models] Add get_chunk_by_path to CDL --- legendary/models/manifest.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/legendary/models/manifest.py b/legendary/models/manifest.py index 54fe2c4..ed775b8 100644 --- a/legendary/models/manifest.py +++ b/legendary/models/manifest.py @@ -277,6 +277,18 @@ class CDL: self._manifest_version = 17 self._guid_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): """