summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-12-13 14:39:09 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-12-13 16:46:01 +0100
commit15498b0ad01264d32b4b0989e6cfb4abb98ab537 (patch)
tree58000d30d5a5a8af30e0aa7e913567dc12b2951a
parentitems: Remove unused ItemCache.top_level (diff)
downloadrtems-central-15498b0ad01264d32b4b0989e6cfb4abb98ab537.tar.bz2
items: Optional post-process load in ItemCache
-rw-r--r--rtemsspec/items.py20
-rw-r--r--rtemsspec/tests/test_items_itemcache.py9
2 files changed, 19 insertions, 10 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 7a789c7a..37966417 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -537,10 +537,19 @@ def _load_item(path: str, uid: str) -> Any:
class ItemCache:
""" This class provides a cache of specification items. """
- def __init__(self, config: Any):
+ def __init__(self,
+ config: Any,
+ post_process_load: Optional[Callable[[ItemMap],
+ None]] = None):
self._items = {} # type: ItemMap
self._updates = 0
- self._load_items(config)
+ cache_dir = os.path.abspath(config["cache-directory"])
+ for path in config["paths"]:
+ self._load_items_recursive(path, path, cache_dir)
+ if post_process_load:
+ post_process_load(self._items)
+ self._init_parents()
+ self._init_children()
spec_root = config["spec-type-root-uid"]
if spec_root:
self._root_type = _gather_spec_refinements(self[spec_root])
@@ -633,13 +642,6 @@ class ItemCache:
for uid in sorted(self._items):
self._items[uid].init_children()
- def _load_items(self, config: Any) -> None:
- cache_dir = os.path.abspath(config["cache-directory"])
- for path in config["paths"]:
- self._load_items_recursive(path, path, cache_dir)
- self._init_parents()
- self._init_children()
-
def _set_type(self, item: Item) -> None:
spec_type = self._root_type
value = item.data
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 0dbe0c69..93afb8bf 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -38,7 +38,14 @@ def test_config_error():
def test_load(tmpdir):
config = create_item_cache_config_and_copy_spec(tmpdir, "spec-item-cache")
- item_cache = ItemCache(config)
+ item_count = 0
+
+ def post_process_load(items):
+ nonlocal item_count
+ item_count = len(items)
+
+ item_cache = ItemCache(config, post_process_load)
+ assert item_count == len(item_cache.all)
assert item_cache.updates
cache_dir = config["cache-directory"]
assert os.path.exists(os.path.join(cache_dir, "spec", "spec.pickle"))