[rtems-central commit] items: Add ItemCache.types
Sebastian Huber
sebh at rtems.org
Fri May 28 12:42:06 UTC 2021
Module: rtems-central
Branch: master
Commit: 0fe547cd982c616b08c2a21c9ae7d4ab72619037
Changeset: http://git.rtems.org/rtems-central/commit/?id=0fe547cd982c616b08c2a21c9ae7d4ab72619037
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri May 28 11:31:03 2021 +0200
items: Add ItemCache.types
---
rtemsspec/items.py | 14 +++++++++++---
rtemsspec/tests/test_items_itemcache.py | 2 ++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index bfd0dac..ee5a9fb 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: BSD-2-Clause
""" This module provides specification items and an item cache. """
-# Copyright (C) 2019, 2020 embedded brains GmbH (http://www.embedded-brains.de)
+# Copyright (C) 2019, 2021 embedded brains GmbH (http://www.embedded-brains.de)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -31,7 +31,7 @@ import pickle
import string
import stat
from typing import Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, \
- Optional, Tuple, Union
+ Optional, Set, Tuple, Union
import yaml
@@ -592,6 +592,7 @@ class ItemCache:
post_process_load: Optional[Callable[[ItemMap],
None]] = None):
self._items = {} # type: ItemMap
+ self._types = set() # type: Set[str]
self._updates = 0
cache_dir = os.path.abspath(config["cache-directory"])
for index, path in enumerate(config["paths"]):
@@ -624,6 +625,11 @@ class ItemCache:
""" Returns the map of all specification items. """
return self._items
+ @property
+ def types(self) -> Set[str]:
+ """ Returns the types of the items. """
+ return self._types
+
def add_volatile_item(self, path: str, uid: str) -> Item:
"""
Adds an item stored in the specified file to the cache and returns it.
@@ -700,7 +706,9 @@ class ItemCache:
type_name = value[spec_type.key]
path.append(type_name)
spec_type = spec_type.refinements[type_name]
- item["_type"] = "/".join(path)
+ the_type = "/".join(path)
+ item["_type"] = the_type
+ self._types.add(the_type)
class EmptyItemCache(ItemCache):
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 2e6c64c..81e2db7 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -45,6 +45,8 @@ def test_load(tmpdir):
item_count = len(items)
item_cache = ItemCache(config, post_process_load)
+ assert len(item_cache.types) == 1
+ assert list(item_cache.types)[0] == ""
assert item_count == len(item_cache.all)
assert item_cache.updates
cache_dir = config["cache-directory"]
More information about the vc
mailing list