411 # to avoid loading same module twice, especially with the |
411 # to avoid loading same module twice, especially with the |
412 # _load_ancestors_then_object logic but this needs to be checked |
412 # _load_ancestors_then_object logic but this needs to be checked |
413 self._loadedmods = {} |
413 self._loadedmods = {} |
414 return filemods |
414 return filemods |
415 |
415 |
416 def register_objects(self, path, force_reload=False, extrapath=None): |
416 def register_objects(self, path, extrapath=None): |
417 # load views from each directory in the instance's path |
417 # load views from each directory in the instance's path |
418 filemods = self.init_registration(path, extrapath) |
418 filemods = self.init_registration(path, extrapath) |
419 for filepath, modname in filemods: |
419 for filepath, modname in filemods: |
420 self.load_file(filepath, modname, force_reload) |
420 self.load_file(filepath, modname) |
421 self.initialization_completed() |
421 self.initialization_completed() |
422 |
422 |
423 def initialization_completed(self): |
423 def initialization_completed(self): |
424 for regname, reg in self.iteritems(): |
424 for regname, reg in self.iteritems(): |
425 reg.initialization_completed() |
425 reg.initialization_completed() |
453 if fileordir not in lastmodifs or lastmodifs[fileordir] < mdate: |
453 if fileordir not in lastmodifs or lastmodifs[fileordir] < mdate: |
454 self.info('File %s changed since last visit', fileordir) |
454 self.info('File %s changed since last visit', fileordir) |
455 return True |
455 return True |
456 return False |
456 return False |
457 |
457 |
458 def load_file(self, filepath, modname, force_reload=False): |
458 def load_file(self, filepath, modname): |
459 """load app objects from a python file""" |
459 """load app objects from a python file""" |
460 from logilab.common.modutils import load_module_from_name |
460 from logilab.common.modutils import load_module_from_name |
461 if modname in self._loadedmods: |
461 if modname in self._loadedmods: |
462 return |
462 return |
463 self._loadedmods[modname] = {} |
463 self._loadedmods[modname] = {} |
470 # set update time before module loading, else we get some reloading |
470 # set update time before module loading, else we get some reloading |
471 # weirdness in case of syntax error or other error while importing the |
471 # weirdness in case of syntax error or other error while importing the |
472 # module |
472 # module |
473 self._lastmodifs[filepath] = mdate |
473 self._lastmodifs[filepath] = mdate |
474 # load the module |
474 # load the module |
475 module = load_module_from_name(modname, use_sys=not force_reload) |
475 module = load_module_from_name(modname) |
476 self.load_module(module) |
476 self.load_module(module) |
477 |
477 |
478 def load_module(self, module): |
478 def load_module(self, module): |
479 self.info('loading %s', module) |
479 self.info('loading %s', module) |
480 if hasattr(module, 'registration_callback'): |
480 if hasattr(module, 'registration_callback'): |