[rtems-central commit] items: Add ItemCache.updates
Sebastian Huber
sebh at rtems.org
Wed Oct 28 06:58:20 UTC 2020
Module: rtems-central
Branch: master
Commit: f0735bbd5c9b24c480f14ea71ea7f413020d2ca0
Changeset: http://git.rtems.org/rtems-central/commit/?id=f0735bbd5c9b24c480f14ea71ea7f413020d2ca0
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Oct 28 07:58:00 2020 +0100
items: Add ItemCache.updates
---
rtemsspec/items.py | 10 ++++++++++
rtemsspec/tests/test_items_itemcache.py | 4 ++++
2 files changed, 14 insertions(+)
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index d7f96a4..84fca2a 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -505,6 +505,7 @@ class ItemCache:
def __init__(self, config: Any):
self._items = {} # type: ItemMap
self._top_level = {} # type: ItemMap
+ self._updates = 0
self._load_items(config)
spec_root = config["spec-type-root-uid"]
if spec_root:
@@ -518,6 +519,14 @@ class ItemCache:
return self._items[uid]
@property
+ def updates(self) -> bool:
+ """
+ Returns true if the item cache updates occurred due to new, modified,
+ or removed files.
+ """
+ return self._updates > 0
+
+ @property
def all(self) -> ItemMap:
""" Returns the map of all specification items. """
return self._items
@@ -551,6 +560,7 @@ class ItemCache:
update_cache: bool) -> None:
data_by_uid = {} # type: Dict[str, Any]
if update_cache:
+ self._updates += 1
for name in os.listdir(path):
path2 = os.path.join(path, name)
if name.endswith(".yml") and not name.startswith("."):
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 0aaacb2..cb0969e 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -39,6 +39,7 @@ def test_config_error():
def test_load(tmpdir):
config = create_item_cache_config_and_copy_spec(tmpdir, "spec-item-cache")
item_cache = ItemCache(config)
+ assert item_cache.updates
cache_dir = config["cache-directory"]
assert os.path.exists(os.path.join(cache_dir, "spec", "spec.pickle"))
assert os.path.exists(os.path.join(cache_dir, "spec", "d", "spec.pickle"))
@@ -55,10 +56,12 @@ def test_load(tmpdir):
assert a["/p"]["v"] == "p"
assert a["/d/c"]["v"] == "c"
item_cache_2 = ItemCache(config)
+ assert not item_cache_2.updates
assert item_cache_2["/d/c"]["v"] == "c"
with open(os.path.join(tmpdir, "spec", "d", "c.yml"), "w+") as out:
out.write("links:\n- role: null\n uid: ../p\nv: x\n")
item_cache_3 = ItemCache(config)
+ assert item_cache_3.updates
assert item_cache_3["/d/c"]["v"] == "x"
item = item_cache_3.add_volatile_item(
os.path.join(os.path.dirname(__file__), "spec/root.yml"), "/foo/bar")
@@ -67,6 +70,7 @@ def test_load(tmpdir):
assert item["type"] == "spec"
os.remove(os.path.join(tmpdir, "spec", "d", "c.yml"))
item_cache_4 = ItemCache(config)
+ assert item_cache_4.updates
with pytest.raises(KeyError):
item_cache_4["/d/c"]
More information about the vc
mailing list