MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / remove_resource

Method remove_resource

src/commoncode/resource.py:983–1014  ·  view source on GitHub ↗

Remove the `resource` Resource object and all its children from the codebase. Return a set of removed Resource paths.

(self, resource)

Source from the content-addressed store, hash-verified

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 """

Callers 1

removeMethod · 0.80

Calls 7

_remove_resourceMethod · 0.95
addMethod · 0.80
parentMethod · 0.80
logger_debugFunction · 0.70
removeMethod · 0.65
walkMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected