]> mj.ucw.cz Git - eval.git/commitdiff
Moved module loading, use __import__() now
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 11 Sep 2010 15:55:09 +0000 (17:55 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 11 Sep 2010 15:55:09 +0000 (17:55 +0200)
General util.load_module returns module by name.
Hook adding in pipeline removed (and distributed to
tasktype module loading and extension module loading, both in Eval)

t/moe/pipeline.py
t/moe/util.py

index f14a0f5f7956be474151c6148474b94bc86f525f..22422e605904428192bc7fb66fd0003ae62fa0ec 100644 (file)
@@ -51,21 +51,6 @@ class MoePipeline:
        self.index = -1
        moe.log.default.verbose(">> Pipeline %s finished\n" % self.name)
 
-    def add_hook(self, name):
-       modname = "moe.hooks." + name
-       moe.log.default.verbose(">> Loading hook %s\n" % name)
-       if not sys.modules.has_key(modname):
-           ## FIXME: Configuration variable for the hook directory?
-           try:
-               fp, path, desc = imp.find_module(name, ["moe/hooks"])
-           except ImportError:
-               raise MoePipeError, "Cannot find hook module " + modname
-           try:
-               imp.load_module(modname, fp, path, desc)
-           finally:
-               fp.close()
-       sys.modules[modname].init(self)
-
     def configure(self, names):
        for name in names.split():
            self.add_hook(name)
index c7bbb5f4eea1dfdf8b68dde99cae8c0a01c02eaa..a2ef34e602b762df66ba5121dba066616b85ba4b 100644 (file)
@@ -33,3 +33,11 @@ def remove_tree_contents(dir):
                shutil.rmtree(os.path.join(dir, f))
            else:
                raise err
+
+def load_module(modname):
+    """Return the module `modname` (full name) if loaded, or try to import it. 
+    Returns the module or raises `ImportError`."""
+    if not sys.modules.has_key(modname):
+       moe.log.debug("Loading module %s" % (path, name))
+       __import__(modname)
+    return sys.modules[modname]