def _load_module(self, dirpath, filename):
mod_name = filename.split('.')[0]
mod_dispname = '/'.join(re.split('/modules/', dirpath)[-1].split('/') + [mod_name])
mod_loadname = mod_dispname.replace('/', '_')
mod_loadpath = os.path.join(dirpath, filename)
mod_file = open(mod_loadpath)
try:
# import the module into memory
mod = imp.load_source(mod_loadname, mod_loadpath, mod_file)
__import__(mod_loadname)
# add the module to the framework's loaded modules
self._loaded_modules[mod_dispname] = sys.modules[mod_loadname].Module(mod_dispname)
return True
except ImportError as e:
# notify the user of missing dependencies
self.error('Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_dispname, e.message[16:]))
except:
# notify the user of errors
self.print_exception()
self.error('Module \'%s\' disabled.' % (mod_dispname))
# remove the module from the framework's loaded modules
self._loaded_modules.pop(mod_dispname, None)
return False
评论列表
文章目录