def load_modules(self):
"""
Load all existing modules
"""
mod_dir = os.path.join(self.__code_dir, MODULE_DIR)
if os.path.exists(os.path.join(self.__code_dir, VERSION_FILE)):
fd = open(os.path.join(self.__code_dir, VERSION_FILE), "r")
self.__current_version = int(fd.read())
fd.close()
pkg_resources.working_set = pkg_resources.WorkingSet._build_master()
for py in glob.glob(os.path.join(mod_dir, "*.py")):
if mod_dir in py:
mod_name = py[len(mod_dir) + 1:-3]
else:
mod_name = py[:-3]
source_code = ""
with open(py, "r") as fd:
source_code = fd.read().encode("utf-8")
sha1sum = hashlib.new("sha1")
sha1sum.update(source_code)
hv = sha1sum.hexdigest()
self._load_module(mod_name, py, hv)
评论列表
文章目录