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