Remove the `resource` Resource object and all its children from the codebase. Return a set of removed Resource paths.
(self, resource)
| 981 | logger_debug("Codebase._remove_resource:", resource) |
| 982 | |
| 983 | def remove_resource(self, resource): |
| 984 | """ |
| 985 | Remove the `resource` Resource object and all its children from the |
| 986 | codebase. Return a set of removed Resource paths. |
| 987 | """ |
| 988 | if TRACE: |
| 989 | logger_debug("Codebase.remove_resource") |
| 990 | logger_debug(" resource", resource) |
| 991 | |
| 992 | if resource.is_root: |
| 993 | raise TypeError(f"Cannot remove the root resource from codebase: {resource!r}") |
| 994 | |
| 995 | removed_paths = set() |
| 996 | |
| 997 | # remove all descendants bottom up to avoid out-of-order access to |
| 998 | # removed resources |
| 999 | for descendant in resource.walk(self, topdown=False): |
| 1000 | self._remove_resource(descendant) |
| 1001 | removed_paths.add(descendant.location) |
| 1002 | |
| 1003 | # remove resource from parent |
| 1004 | parent = resource.parent(self) |
| 1005 | if TRACE: |
| 1006 | logger_debug(" parent", parent) |
| 1007 | parent.children_names.remove(resource.name) |
| 1008 | parent.save(self) |
| 1009 | |
| 1010 | # remove resource proper |
| 1011 | self._remove_resource(resource) |
| 1012 | removed_paths.add(resource.location) |
| 1013 | |
| 1014 | return removed_paths |
| 1015 | |
| 1016 | def walk(self, topdown=True, skip_root=False, ignored=ignore_nothing): |
| 1017 | """ |
no test coverage detected