111 self._needs_iface[obj] = ifaces |
111 self._needs_iface[obj] = ifaces |
112 |
112 |
113 def register_objects(self, path, force_reload=None): |
113 def register_objects(self, path, force_reload=None): |
114 """overriden to remove objects requiring a missing interface""" |
114 """overriden to remove objects requiring a missing interface""" |
115 if super(CubicWebRegistry, self).register_objects(path, force_reload): |
115 if super(CubicWebRegistry, self).register_objects(path, force_reload): |
116 # clear etype cache if you don't want to run into deep weirdness |
116 self.initialization_completed() |
117 clear_cache(self, 'etype_class') |
|
118 # we may want to keep interface dependent objects (e.g.for i18n |
|
119 # catalog generation) |
|
120 if self.config.cleanup_interface_sobjects: |
|
121 # remove vobjects that don't support any available interface |
|
122 implemented_interfaces = set() |
|
123 for etype in self.schema.entities(): |
|
124 cls = self.etype_class(etype) |
|
125 for iface in cls.__implements__: |
|
126 implemented_interfaces.update(iface.__mro__) |
|
127 implemented_interfaces.update(cls.__mro__) |
|
128 for obj, ifaces in self._needs_iface.items(): |
|
129 ifaces = frozenset(isinstance(iface, basestring) |
|
130 and iface in self.schema |
|
131 and self.etype_class(iface) |
|
132 or iface |
|
133 for iface in ifaces) |
|
134 if not ('Any' in ifaces or ifaces & implemented_interfaces): |
|
135 self.debug('kicking vobject %s (no implemented ' |
|
136 'interface among %s)', obj, ifaces) |
|
137 self.unregister(obj) |
|
138 # clear needs_iface so we don't try to remove some not-anymore-in |
|
139 # objects on automatic reloading |
|
140 self._needs_iface.clear() |
|
141 # print registry content |
117 # print registry content |
142 for registry, objects in self.items(): |
118 for registry, objects in self.items(): |
143 self.debug('available in registry %s: %s', registry, |
119 self.debug('available in registry %s: %s', registry, |
144 sorted(objects)) |
120 sorted(objects)) |
145 for appobjects in objects.itervalues(): |
121 for appobjects in objects.itervalues(): |
146 for appobject in appobjects: |
122 for appobject in appobjects: |
147 appobject.vreg_initialization_completed() |
123 appobject.vreg_initialization_completed() |
|
124 |
|
125 def initialization_completed(self): |
|
126 # clear etype cache if you don't want to run into deep weirdness |
|
127 clear_cache(self, 'etype_class') |
|
128 # we may want to keep interface dependent objects (e.g.for i18n |
|
129 # catalog generation) |
|
130 if self.config.cleanup_interface_sobjects: |
|
131 # remove vobjects that don't support any available interface |
|
132 implemented_interfaces = set() |
|
133 if 'Any' in self.get('etypes', ()): |
|
134 for etype in self.schema.entities(): |
|
135 cls = self.etype_class(etype) |
|
136 for iface in cls.__implements__: |
|
137 implemented_interfaces.update(iface.__mro__) |
|
138 implemented_interfaces.update(cls.__mro__) |
|
139 for obj, ifaces in self._needs_iface.items(): |
|
140 ifaces = frozenset(isinstance(iface, basestring) |
|
141 and iface in self.schema |
|
142 and self.etype_class(iface) |
|
143 or iface |
|
144 for iface in ifaces) |
|
145 if not ('Any' in ifaces or ifaces & implemented_interfaces): |
|
146 self.debug('kicking vobject %s (no implemented ' |
|
147 'interface among %s)', obj, ifaces) |
|
148 self.unregister(obj) |
|
149 # clear needs_iface so we don't try to remove some not-anymore-in |
|
150 # objects on automatic reloading |
|
151 self._needs_iface.clear() |
148 |
152 |
149 @cached |
153 @cached |
150 def etype_class(self, etype): |
154 def etype_class(self, etype): |
151 """return an entity class for the given entity type. |
155 """return an entity class for the given entity type. |
152 Try to find out a specific class for this kind of entity or |
156 Try to find out a specific class for this kind of entity or |