X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=t%2Fmoe%2Feval.py;h=9a964ffb9a269f98bf101976ef02d9feeab70564;hb=750990d7dbbaf2740f290a26dab527ce4444cbfb;hp=42f5bda6dfe3f1e1b98613f2ffc4a5a9936d5167;hpb=9587bd376c403e16a0f79c9046eecc9b8f543cb8;p=eval.git diff --git a/t/moe/eval.py b/t/moe/eval.py index 42f5bda..9a964ff 100644 --- a/t/moe/eval.py +++ b/t/moe/eval.py @@ -1,65 +1,117 @@ #!/usr/bin/env python +import moe import moe.config +import moe.box import moe.log -import moe.meta +import moe.status import moe.pipeline import moe.batch import moe.util import os.path import shutil -class MoeEvalErr(Exception): - pass - class Eval: + """ + """ def __init__(self): - self.cfgs = moe.config.MoeConfigStack() - self.builtins = moe.config.MoeConfig() - self.cfgs.push(self.builtins) + self.log = moe.log.Logers() + self.config = moe.config.ConfigTree() self.main_pipe = moe.pipeline.MoePipeline("main") - self.meta = moe.meta.MoeMeta() - pass - - def init(self): - self.init_global() - ## FIXME: Configuration overrides - self.init_test() - ## FIXME: Initialize logging early on - self.init_task() - - def init_global(self): - main_cfg = moe.config.MoeConfig(name = os.path.join(self.cfgs['HOME'], "config")) - self.cfgs.push(main_cfg) - - def init_test(self): - test = self.cfgs['TEST_DIR'] + self.test_pipe = moe.pipeline.MoePipeline("test") + self.stat = moe.status.MoeStatus() + + def __getitem__(self, key): + return self.config[key] + + def init(self, overrides=[]): + "Initializes most part of Eval before running the pipeline. See the timeline for details." + self.log.info("Initializing ...") + + # set basic builtins + self.config.parse('HOME=\'%s\'' % os.getcwd(), source="", level=0) + self.config.parse('CONFIG="{HOME}/config"', source="", level=0) + self.config.parse('LOG="{HOME}/log"', source="", level=0) + self.config.parse('DEBUG_LEVEL="0"', source="", level=0) + self.config.parse('VERBOSE=""', source="", level=0) + self.config.parse('TDIR="{HOME}/test"', source="", level=0) # -> config + self.config.parse('USER_LOG="{TDIR}/log"', source="", level=0) # -> config + # apply overrides + for ov in overrides: + self.config.parse(ov, source="", level=100) + + # load config file + self.config.fix('CONFIG') + with open(self['CONFIG'], 'r') as f: + self.config.parse(f, source=self['CONFIG'], level=30) + # fix variables + self.config.fix(['LOG', 'USER_LOG', 'VERBOSE', 'HOME', 'DEBUG_LEVEL', 'TDIR']) + # start logging + self.log.open_eval_log(self['LOG'], self['DEBUG_LEVEL'], redirect_fds = True) + self.log.open_user_log(self['USER_LOG']) + self.debug_dump_config() + + # init and check TDIR + self.debug('Cleaning TDIR: %s'%self['TDIR']) + self.init_TDIR() + + # insert hooks into main pipeline + # TODO + # TODO moe.box.init(self) + + # insert custom hooks + self.conf.fix('HOOKS') + self.main_pipe.configure(self['HOOKS']) + + def run(self): + "Run the main pipeline." + self.debug_dump_pipe(self.main_pipe) + self.debug('Running main pipeline') + self.main_pipe.run(self) + + + def init_TDIR(self): + test = self['TDIR'] if os.path.isdir(test): shutil.rmtree(test) - try: + try: #TODO: Remove moe.util.mkdir_tree(test) - except OSError, e: - raise MoeEvalErr, "Cannot create %s: %s" % (test, e.strerror) + except OSError, err: + raise moe.MoeError, "Cannot create %s: %s" % (test, err.strerror) + + def debug_dump_config(self): + "Dumps config at level DDEBUG (only compiles the dump if main level is low enough)." + if self.log.level <= 5: + self.log.ddebug('****** Config dump: ******') + self.log.ddebug(self.config.dump('**** ')) + self.log.ddebug('**************************') + + def debug_dump_pipe(self, pipe): + "Dumps pipeline `pipe` at level DDEBUG (only compiles the dump if main level low enough)." + if self.log.level <= 5: + self.log.ddebug('****** Pipeline %r dump: ******'%pipe,name) + self.log.ddebug(pipe.dump(prefix='**** ')) + self.log.ddebug('**************************') +#TODO ... def init_task(self): - task = self.cfgs['TASK'] - task_dir = self.cfgs['TASK_DIR'] + task = self['TASK'] + task_dir = self['PDIR'] if not os.path.isdir(task_dir): - raise MoeEvalErr, "No such task %s" % task - task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config")) + raise moe.MoeError, "No such task %s" % task + + task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config"), type='task') self.cfgs.push(task_cfg) - self.meta["task"] = task + self.log_config(3, "after loading the task") + + self.stat["task"] = task - type = self.cfgs['TASK_TYPE'] + type = self['TASK_TYPE'] if type == "batch" or type == "interactive": moe.batch.prepare_pipe(self) elif type == "opendata": - raise MoeEvalErr, "Opendata tasks not implemented yet" + raise moe.MoeError, "Opendata tasks not implemented yet" else: - raise MoeEvalErr, "Unknown task type " + type + raise moe.MoeError, "Unknown task type " + type - def run(self): - self.main_pipe.configure(self.cfgs["HOOKS"]) - self.main_pipe.dump() - self.main_pipe.run(self)