summaryrefslogtreecommitdiff
path: root/rtemsspec
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-06-01 13:57:37 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-06-14 13:58:42 +0200
commit52d5b008c4c500c3e4a9ef39aaea6f8897f7af10 (patch)
tree15220b8ba7a098165023c04bcd8a7f03cd03966e /rtemsspec
parent1c72d54e4a409b6a466deedaa4132d7632376375 (diff)
items: Return the UIDs of the loaded items
Diffstat (limited to 'rtemsspec')
-rw-r--r--rtemsspec/items.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 34a37a8e..eef4f29e 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -859,7 +859,7 @@ class ItemCache(dict):
return item
def _load_items_in_dir(self, base: str, path: str, cache_file: str,
- update_cache: bool) -> None:
+ update_cache: bool) -> Set[str]:
data_by_uid: Dict[str, Any] = {}
if update_cache:
self._updates += 1
@@ -877,9 +877,11 @@ class ItemCache(dict):
data_by_uid = pickle.load(pickle_src)
for uid, data in iter(data_by_uid.items()):
self._add_item(uid, data)
+ return set(data_by_uid.keys())
def _load_items_recursive(self, index: str, base: str, path: str,
- cache_dir: str) -> None:
+ cache_dir: str) -> Set[str]:
+ uids: Set[str] = set()
mid = os.path.abspath(path)
mid = mid.replace(os.path.commonpath([cache_dir, mid]), "").strip("/")
cache_file = os.path.join(cache_dir, index, mid, "spec.pickle")
@@ -896,15 +898,18 @@ class ItemCache(dict):
if not update_cache:
update_cache = mtime <= os.path.getmtime(path2)
elif stat.S_ISDIR(os.lstat(path2).st_mode):
- self._load_items_recursive(index, base, path2, cache_dir)
- self._load_items_in_dir(base, path, cache_file, update_cache)
+ uids.update(
+ self._load_items_recursive(index, base, path2, cache_dir))
+ uids.update(
+ self._load_items_in_dir(base, path, cache_file, update_cache))
+ return uids
- def load_items(self, path: str):
+ def load_items(self, path: str) -> Set[str]:
""" Recursively loads the items in the directory path. """
index = self._cache_index
self._cache_index = index + 1
- self._load_items_recursive(str(index), path, path,
- self._cache_directory)
+ return self._load_items_recursive(str(index), path, path,
+ self._cache_directory)
def load_data(self, path: str, uid: str) -> Any:
""" Loads the item data from the file specified by path. """
@@ -968,17 +973,19 @@ class EmptyItemCache(ItemCache):
class JSONItemCache(ItemCache):
""" This class provides a cache of specification items using JSON. """
- def _load_json_items(self, base: str, path: str) -> None:
+ def _load_json_items(self, base: str, path: str) -> Set[str]:
+ uids: Set[str] = set()
for name in os.listdir(path):
path2 = os.path.join(path, name)
if name.endswith(".json") and not name.startswith("."):
uid = "/" + os.path.relpath(path2, base).replace(".json", "")
self._add_item(uid, _load_json_data(path2, uid))
elif stat.S_ISDIR(os.lstat(path2).st_mode):
- self._load_json_items(base, path2)
+ uids.update(self._load_json_items(base, path2))
+ return uids
- def load_items(self, path: str):
- self._load_json_items(path, path)
+ def load_items(self, path: str) -> Set[str]:
+ return self._load_json_items(path, path)
def load_data(self, path: str, uid: str) -> Any:
return _load_json_data(path, uid)