[rtems-central commit] items: Optional post-process load in ItemCache

Sebastian Huber sebh at rtems.org
Mon Dec 14 11:05:09 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    15498b0ad01264d32b4b0989e6cfb4abb98ab537
Changeset: http://git.rtems.org/rtems-central/commit/?id=15498b0ad01264d32b4b0989e6cfb4abb98ab537

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sun Dec 13 14:39:09 2020 +0100

items: Optional post-process load in ItemCache

---

 rtemsspec/items.py                      | 20 +++++++++++---------
 rtemsspec/tests/test_items_itemcache.py |  9 ++++++++-
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 7a789c7..3796641 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 0dbe0c6..93afb8b 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"))



More information about the vc mailing list