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