cwvreg.py
changeset 5302 dfd147de06b2
parent 5274 16461f675734
parent 5275 32fbb13c06d3
child 5328 c51e8f62652a
equal deleted inserted replaced
5298:66b0987716f9 5302:dfd147de06b2
   474 
   474 
   475     def set_schema(self, schema):
   475     def set_schema(self, schema):
   476         """set instance'schema and load application objects"""
   476         """set instance'schema and load application objects"""
   477         self._set_schema(schema)
   477         self._set_schema(schema)
   478         # now we can load application's web objects
   478         # now we can load application's web objects
   479         self.reload(self.config.vregistry_path())
   479         self.reload(self.config.vregistry_path(), force_reload=False)
   480         # map lowered entity type names to their actual name
   480         # map lowered entity type names to their actual name
   481         self.case_insensitive_etypes = {}
   481         self.case_insensitive_etypes = {}
   482         for eschema in self.schema.entities():
   482         for eschema in self.schema.entities():
   483             etype = str(eschema)
   483             etype = str(eschema)
   484             self.case_insensitive_etypes[etype.lower()] = etype
   484             self.case_insensitive_etypes[etype.lower()] = etype
   488     def reload_if_needed(self):
   488     def reload_if_needed(self):
   489         path = self.config.vregistry_path()
   489         path = self.config.vregistry_path()
   490         if self.is_reload_needed(path):
   490         if self.is_reload_needed(path):
   491             self.reload(path)
   491             self.reload(path)
   492 
   492 
   493     def reload(self, path):
   493     def reload(self, path, force_reload=True):
   494         """modification detected, reset and reload the vreg"""
   494         """modification detected, reset and reload the vreg"""
   495         CW_EVENT_MANAGER.emit('before-registry-reload')
   495         CW_EVENT_MANAGER.emit('before-registry-reload')
   496         cleanup_sys_modules(path)
   496         if force_reload:
   497         cubes = self.config.cubes()
   497             cleanup_sys_modules(path)
   498         # if the fs code use some cubes not yet registered into the instance we
   498             cubes = self.config.cubes()
   499         # should cleanup sys.modules for those as well to avoid potential bad
   499             # if the fs code use some cubes not yet registered into the instance
   500         # class reference pb after reloading
   500             # we should cleanup sys.modules for those as well to avoid potential
   501         cfg = self.config
   501             # bad class reference pb after reloading
   502         for cube in cfg.expand_cubes(cubes, with_recommends=True):
   502             cfg = self.config
   503             if not cube in cubes:
   503             for cube in cfg.expand_cubes(cubes, with_recommends=True):
   504                 cpath = cfg.build_vregistry_cube_path([cfg.cube_dir(cube)])
   504                 if not cube in cubes:
   505                 cleanup_sys_modules(cpath)
   505                     cpath = cfg.build_vregistry_cube_path([cfg.cube_dir(cube)])
       
   506                     cleanup_sys_modules(cpath)
   506         self.reset()
   507         self.reset()
   507         self.register_objects(path, True)
   508         self.register_objects(path, force_reload)
   508         CW_EVENT_MANAGER.emit('after-registry-reload')
   509         CW_EVENT_MANAGER.emit('after-registry-reload')
   509 
   510 
   510     def _set_schema(self, schema):
   511     def _set_schema(self, schema):
   511         """set instance'schema"""
   512         """set instance'schema"""
   512         self.schema = schema
   513         self.schema = schema