summaryrefslogtreecommitdiff
path: root/rtemsspec
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-06-01 13:56:10 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-06-14 13:58:42 +0200
commit1c72d54e4a409b6a466deedaa4132d7632376375 (patch)
tree7656dfc7029b57b3d6785ea69abd34e9ecab9036 /rtemsspec
parent926dda5c9e12cf48947fba95bdd85ebff0099804 (diff)
items: Add ItemCache.set_types()
Diffstat (limited to 'rtemsspec')
-rw-r--r--rtemsspec/items.py17
-rw-r--r--rtemsspec/tests/test_items_itemcache.py3
2 files changed, 17 insertions, 3 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index a3890f6f..34a37a8e 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -24,6 +24,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
+# pylint: disable=too-many-lines
+
from contextlib import contextmanager
import base64
import hashlib
@@ -786,7 +788,7 @@ class ItemCache(dict):
self._enabled = config.get("enabled", [])
self._is_enabled = is_item_enabled
for item in self.values():
- self._set_type(item)
+ self.set_type(item)
item["_enabled"] = is_item_enabled(self._enabled, item)
if config.get("resolve-proxies", False):
self.resolve_proxies()
@@ -839,7 +841,7 @@ class ItemCache(dict):
item = self._add_item(uid, data)
item.init_parents(self)
item.init_children()
- self._set_type(item)
+ self.set_type(item)
item["_enabled"] = self._is_enabled(self._enabled, item)
return item
@@ -929,7 +931,8 @@ class ItemCache(dict):
for item in sorted(self.values()):
item.init_children()
- def _set_type(self, item: Item) -> None:
+ def set_type(self, item: Item) -> None:
+ """ Sets the type of the item. """
spec_type = self._root_type
value = item.data
path: List[str] = []
@@ -942,6 +945,14 @@ class ItemCache(dict):
self._types.add(the_type)
self.items_by_type.setdefault(the_type, []).append(item)
+ def set_types(self, root_type_uid: str) -> None:
+ """
+ Sets the root type of the cache and then sets the type of all items.
+ """
+ self._root_type = _gather_spec_refinements(self[root_type_uid])
+ for item in self.values():
+ self.set_type(item)
+
class EmptyItemCache(ItemCache):
""" This class provides a empty cache of specification items. """
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 2c24d669..864ef70a 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -130,6 +130,9 @@ def test_item_mapper(tmpdir):
config["resolve-proxies"] = True
item_cache = ItemCache(config)
item = item_cache["/p"]
+ assert item.type == "other"
+ item_cache.set_types("/spec/root")
+ assert item.type == "other"
base_mapper = ItemMapper(item)
assert base_mapper["d/c:v"] == "c"
mapper = ItemMapper(item)