9 class MoePipeError(moe.MoeErr):
10 """Failure of the MoePipeline."""
15 def __init__(self, name):
20 def insert(self, pri, name, fun):
21 triple = (pri,name,fun)
22 pos = bisect.bisect(self.pipe, triple)
24 raise MoePipeError, "Pipeline insert cannot alter the past"
25 self.pipe.insert(pos, triple)
27 def dump(self, file=sys.stdout, prefix=""):
28 file.write(">>> Pipeline %s\n" % self.name)
29 for pri,name,fun in self.pipe:
30 file.write("%s%03d %s\n" % (prefix,pri,name))
34 while self.index < len(self.pipe):
35 (pri,name,fun) = self.pipe[self.index]
36 moe.log.default.verbose(">> Running %s:%s\n" % (self.name,name))
41 def add_hook(self, name):
42 modname = "moe.hooks." + name
43 moe.log.default.verbose(">> Loading hook %s\n" % name)
44 if not sys.modules.has_key(modname):
45 ## FIXME: Configuration variable for the hook directory?
47 fp, path, desc = imp.find_module(name, ["moe/hooks"])
49 raise MoePipeError, "Cannot find hook module " + modname
51 imp.load_module(modname, fp, path, desc)
54 sys.modules[modname].init(self)
56 def configure(self, names):
57 for name in names.split():