vregistry.py
changeset 4490 d45cde54d464
parent 4436 294e084f1263
child 4491 a0f48c31b58a
equal deleted inserted replaced
4483:918fd9931cb7 4490:d45cde54d464
    82         try:
    82         try:
    83             return super(Registry, self).__getitem__(name)
    83             return super(Registry, self).__getitem__(name)
    84         except KeyError:
    84         except KeyError:
    85             raise ObjectNotFound(name), None, sys.exc_info()[-1]
    85             raise ObjectNotFound(name), None, sys.exc_info()[-1]
    86 
    86 
       
    87     def initialization_completed(self):
       
    88         for appobjects in self.itervalues():
       
    89             for appobjectcls in appobjects:
       
    90                 appobjectcls.__registered__(self)
       
    91 
    87     def register(self, obj, oid=None, clear=False):
    92     def register(self, obj, oid=None, clear=False):
    88         """base method to add an object in the registry"""
    93         """base method to add an object in the registry"""
    89         assert not '__abstract__' in obj.__dict__
    94         assert not '__abstract__' in obj.__dict__
    90         oid = oid or class_regid(obj)
    95         oid = oid or class_regid(obj)
    91         assert oid
    96         assert oid
    92         if clear:
    97         if clear:
    93             appobjects = self[oid] =  []
    98             appobjects = self[oid] =  []
    94         else:
    99         else:
    95             appobjects = self.setdefault(oid, [])
   100             appobjects = self.setdefault(oid, [])
    96         appobject = obj.__registered__(self)
   101         assert not obj in appobjects, \
    97         assert not appobject in appobjects, \
   102                'object %s is already registered' % obj
    98                'object %s is already registered' % appobject
   103         appobjects.append(obj)
    99         assert callable(appobject.__select__), appobject
       
   100         appobjects.append(appobject)
       
   101 
   104 
   102     def register_and_replace(self, obj, replaced):
   105     def register_and_replace(self, obj, replaced):
   103         # XXXFIXME this is a duplication of unregister()
   106         # XXXFIXME this is a duplication of unregister()
   104         # remove register_and_replace in favor of unregister + register
   107         # remove register_and_replace in favor of unregister + register
   105         # or simplify by calling unregister then register here
   108         # or simplify by calling unregister then register here
   354         filemods = self.init_registration(path, extrapath)
   357         filemods = self.init_registration(path, extrapath)
   355         change = False
   358         change = False
   356         for filepath, modname in filemods:
   359         for filepath, modname in filemods:
   357             if self.load_file(filepath, modname, force_reload):
   360             if self.load_file(filepath, modname, force_reload):
   358                 change = True
   361                 change = True
       
   362         if change:
       
   363             self.initialization_completed()
   359         return change
   364         return change
       
   365 
       
   366     def initialization_completed(self):
       
   367         for regname, reg in self.iteritems():
       
   368             self.debug('available in registry %s: %s', regname, sorted(reg))
       
   369             reg.initialization_completed()
   360 
   370 
   361     def load_file(self, filepath, modname, force_reload=False):
   371     def load_file(self, filepath, modname, force_reload=False):
   362         """load app objects from a python file"""
   372         """load app objects from a python file"""
   363         from logilab.common.modutils import load_module_from_name
   373         from logilab.common.modutils import load_module_from_name
   364         if modname in self._loadedmods:
   374         if modname in self._loadedmods: