]> mj.ucw.cz Git - moe.git/blob - t/moe/batch.py
Locating batch tasks
[moe.git] / t / moe / batch.py
1 #!/usr/bin/env python
2
3 import os.path
4 import moe.log
5 import moe.eval
6 import moe.util
7
8 def normalize_ext(e, ext):
9     alias = e.cfgs["ALIAS_EXT_" + ext]
10     return alias if alias != "" else ext
11
12 def try_ext(e, ext):
13     for e in e.cfgs["EXTENSIONS"].split():
14         if e == ext:
15             return
16     raise moe.eval.MoeEvalErr, "Unknown extension: " + ext
17
18 def locate(e, filename=None):
19     task = e.cfgs["TASK"]
20     if filename is None:
21         dir = ""
22         file = task
23     else:
24         dir, file = os.path.split(filename)
25     if dir == "":
26         dir = e.cfgs["SOL_DIR"]
27
28     base, ext = os.path.splitext(file)
29     if ext != "":
30         if not os.path.exists(os.path.join(dir, file)):
31             raise moe.eval.MoeEvalErr, "No solution of %s called %s found" % (task,file)
32         ext = ext[1:]
33         try_ext(e, ext)
34     else:
35         found = []
36         for ext in e.cfgs["EXTENSIONS"].split():
37             if os.path.exists(os.path.join(dir, base + "." + ext)):
38                 found.append(ext)
39         if len(found) == 0:
40             raise moe.eval.MoeEvalErr, "No solution of %s found" % task
41         if len(found) > 1:
42             raise moe.eval.MoeEvalErr, "Multiple solutions of %s found" % task
43         ext = found[0]
44         file = base + "." + ext
45
46     orig_path = os.path.join(dir, file)
47     norm_ext = normalize_ext(e, ext)
48     moe.log.verbose("Found solution %s\n" % orig_path)
49
50     copy = e.cfgs["TASK"] + "." + norm_ext
51     copy_path = os.path.join(e.cfgs["TEST_DIR"], copy)
52     if file != copy:
53         moe.log.verbose("Renaming to %s\n" % copy)
54     moe.util.link_or_copy(orig_path, copy_path)
55
56     e.builtins.set("SRC", copy)
57     e.builtins.set("EXT", norm_ext)
58     e.cfgs.apply_overrides("EXT_" + norm_ext)
59
60     e.meta["source"] = copy
61
62 def compile(e):
63     pass
64
65 def tests(e):
66     pass
67
68 def prepare_pipe(e):
69     e.main_pipe.insert(100, "compile", compile)
70     e.main_pipe.insert(200, "batch-tests", tests)