Return the Resource with `path` or None if it does not exists. The ``path`` must be relative to the root (and including the root name as its first segment).
(self, path)
| 858 | |
| 859 | # FIXME: the PATH SHOULD NOT INCLUDE THE ROOT NAME |
| 860 | def get_resource(self, path): |
| 861 | """ |
| 862 | Return the Resource with `path` or None if it does not exists. |
| 863 | The ``path`` must be relative to the root (and including the root |
| 864 | name as its first segment). |
| 865 | """ |
| 866 | assert isinstance(path, str), f"Invalid path: {path!r} is not a string." |
| 867 | path = clean_path(path) |
| 868 | if TRACE: |
| 869 | msg = [" Codebase.get_resource:", "path:", path] |
| 870 | if not path or path not in self.resources_by_path: |
| 871 | msg.append("not in resources!") |
| 872 | else: |
| 873 | msg.extend(["exists on disk:", self._exists_on_disk(path)]) |
| 874 | msg.extend(["exists in memo:", self._exists_in_memory(path)]) |
| 875 | logger_debug(*msg) |
| 876 | |
| 877 | # we use Codebase.CACHED_RESOURCE as a semaphore for existing but only |
| 878 | # on-disk, non-in-memory resource that we need to load from the disk |
| 879 | # cache to differentiate from None which means missing |
| 880 | res = self.resources_by_path.get(path) |
| 881 | if res is Codebase.CACHED_RESOURCE: |
| 882 | res = self._load_resource(path) |
| 883 | |
| 884 | elif isinstance(res, Resource): |
| 885 | res = attr.evolve(res) |
| 886 | |
| 887 | elif res is None: |
| 888 | pass |
| 889 | else: |
| 890 | # this should never happen |
| 891 | raise Exception(f"get_resource: Internal error when getting {path!r}") |
| 892 | |
| 893 | if TRACE: |
| 894 | logger_debug(" Resource:", res) |
| 895 | return res |
| 896 | |
| 897 | def save_resource(self, resource): |
| 898 | """ |