summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-10-28 07:58:00 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-10-28 07:58:00 +0100
commitf0735bbd5c9b24c480f14ea71ea7f413020d2ca0 (patch)
tree5e277e7ac7a46acb0d793082e5359d13d8866cb5
parentitems: Detect file removals in item cache (diff)
downloadrtems-central-f0735bbd5c9b24c480f14ea71ea7f413020d2ca0.tar.bz2
items: Add ItemCache.updates
-rw-r--r--rtemsspec/items.py10
-rw-r--r--rtemsspec/tests/test_items_itemcache.py4
2 files changed, 14 insertions, 0 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index d7f96a4d..84fca2a2 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 0aaacb28..cb0969e0 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"]