17 self.log = moe.log.default
18 self.cfgs = moe.config.MoeConfigStack()
19 self.builtins = moe.config.MoeConfig(type="builtins")
20 self.cfgs.push(self.builtins)
21 self.main_pipe = moe.pipeline.MoePipeline("main")
22 self.test_pipe = moe.pipeline.MoePipeline("test")
23 self.stat = moe.status.MoeStatus()
26 def __getitem__(self, key):
29 def init(self, overrides=None):
30 self.log.progress("Initializing... ")
31 self.init_global(overrides)
36 self.log.progress("OK\n")
38 def init_global(self, overrides):
39 main_cfg = moe.config.MoeConfig(name = os.path.join(self['HOME'], "config"), type="main")
40 self.cfgs.push(main_cfg)
42 self.cfgs.push(overrides)
46 if os.path.isdir(test):
49 moe.util.mkdir_tree(test)
51 raise moe.MoeError, "Cannot create %s: %s" % (test, err.strerror)
54 self.log = moe.log.MoeLog()
56 self.log.verbosity = int(self["V"])
57 self.log.open(os.path.join(self["TDIR"], "log"))
58 self.default_log = self.log
59 moe.log.default = self.log
60 self.log_config(3, "before loading the task")
64 task_dir = self['PDIR']
65 if not os.path.isdir(task_dir):
66 raise moe.MoeError, "No such task %s" % task
68 task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config"), type='task')
69 self.cfgs.push(task_cfg)
70 self.log_config(3, "after loading the task")
72 self.stat["task"] = task
74 type = self['TASK_TYPE']
75 if type == "batch" or type == "interactive":
76 moe.batch.prepare_pipe(self)
77 elif type == "opendata":
78 raise moe.MoeError, "Opendata tasks not implemented yet"
80 raise moe.MoeError, "Unknown task type " + type
83 self.log_config(2, "for the task pipeline")
84 self.main_pipe.configure(self["HOOKS"])
85 if self.log.verbosity >= 2:
86 self.main_pipe.dump(self.log.log_file, prefix="\t")
87 self.main_pipe.run(self)
89 def log_config(self, verb, msg):
90 if self.log.verbosity >= verb:
91 self.log.say("@@@ Configuration stack %s @@@\n" % msg)
92 self.cfgs.dump_defs(self.log.log_file, prefix="\t")
93 if self.log.verbosity >= 99:
94 self.log.say("@@@@@@ Resolved configuration %s @@@@@@\n" % msg)
95 self.cfgs.dump(self.log.log_file, prefix="\t")