(self)
Organize objects and namespaces
Organize objects and namespaces
Organize objects and namespaces
def organize_objects(self):
        """Organize objects and namespaces"""

        def _render_children(obj):
            for child in obj.children_strings:
                child_object = self.objects.get(child)
                if child_object:
                    obj.item_map[child_object.plural].append(child_object)
                    obj.children.append(child_object)

            for key in obj.item_map:
                obj.item_map[key].sort()

        def _recurse_ns(obj):
            if not obj:
                return
            namespace = obj.top_namespace
            if namespace is not None:
                ns_obj = self.top_namespaces.get(namespace)
                if ns_obj is None or not isinstance(ns_obj, DotNetNamespace):
                    for ns_obj in self.create_class(
                        {"uid": namespace, "type": "namespace"}
                    ):
                        self.top_namespaces[ns_obj.id] = ns_obj
                if obj not in ns_obj.children and namespace != obj.id:
                    ns_obj.children.append(obj)

        for obj in self.objects.values():
            _render_children(obj)
            _recurse_ns(obj)

        # Clean out dead namespaces
        for key, namespace in self.top_namespaces.copy().items():
            if not namespace.children:
                del self.top_namespaces[key]

        for key, namespace in self.namespaces.copy().items():
            if not namespace.children:
                del self.namespaces[key]
def organize_objects ( self ) : def _render_children ( obj ) : for child in obj . children_strings : child_object = self . objects . get ( child ) if child_object : obj . item_map [ child_object . plural ] . append ( child_object ) obj . children . append ( child_object ) for key in obj . item_map : obj . item_map [ key ] . sort ( ) def _recurse_ns ( obj ) : if not obj : return namespace = obj . top_namespace if namespace is not None : ns_obj = self . top_namespaces . get ( namespace ) if ns_obj is None or not isinstance ( ns_obj , DotNetNamespace ) : for ns_obj in self . create_class ( { "uid" : namespace , "type" : "namespace" } ) : self . top_namespaces [ ns_obj . id ] = ns_obj if obj not in ns_obj . children and namespace != obj . id : ns_obj . children . append ( obj ) for obj in self . objects . values ( ) : _render_children ( obj ) _recurse_ns ( obj ) # Clean out dead namespaces for key , namespace in self . top_namespaces . copy ( ) . items ( ) : if not namespace . children : del self . top_namespaces [ key ] for key , namespace in self . namespaces . copy ( ) . items ( ) : if not namespace . children : del self . namespaces [ key ]