9 class MoePipeError(moe.MoeError):
10 """Failure of the MoePipeline."""
12 class MoeAbortPipeline(Exception):
14 def __init__(self, skip_to=999):
15 self.skip_to = skip_to
20 def __init__(self, name):
25 def insert(self, pri, name, fun):
26 triple = (pri,name,fun)
27 pos = bisect.bisect(self.pipe, triple)
29 raise MoePipeError, "Pipeline insert cannot alter the past"
30 self.pipe.insert(pos, triple)
32 def dump(self, file=sys.stdout, prefix=""):
33 file.write(">>> Pipeline %s\n" % self.name)
34 for pri,name,fun in self.pipe:
35 file.write("%s%03d %s\n" % (prefix,pri,name))
40 while self.index < len(self.pipe):
41 (pri,name,fun) = self.pipe[self.index]
43 moe.log.default.verbose(">> Running %s:%s\n" % (self.name,name))
46 except MoeAbortPipeline, err:
49 moe.log.default.verbose(">> Skipping %s:%s\n" % (self.name,name))
52 moe.log.default.verbose(">> Pipeline %s finished\n" % self.name)
54 def add_hook(self, name):
55 modname = "moe.hooks." + name
56 moe.log.default.verbose(">> Loading hook %s\n" % name)
57 if not sys.modules.has_key(modname):
58 ## FIXME: Configuration variable for the hook directory?
60 fp, path, desc = imp.find_module(name, ["moe/hooks"])
62 raise MoePipeError, "Cannot find hook module " + modname
64 imp.load_module(modname, fp, path, desc)
67 sys.modules[modname].init(self)
69 def configure(self, names):
70 for name in names.split():