]> mj.ucw.cz Git - moe.git/blob - t/moe/batch.py
2a0ef1e88e4d048aed6f1658e7bd3836edfe58e7
[moe.git] / t / moe / batch.py
1 #!/usr/bin/env python
2
3 import os.path
4 import moe
5 import moe.box
6 import moe.eval
7 import moe.util
8 import shutil
9
10 def normalize_ext(e, ext):
11     alias = e.cfgs["ALIAS_EXT_" + ext]
12     return alias if alias != "" else ext
13
14 def try_ext(e, ext):
15     for e in e.cfgs["EXTENSIONS"].split():
16         if e == ext:
17             return
18     raise moe.MoeErr, "Unknown extension: " + ext
19
20 def locate(e, filename=None):
21     e.log.progress("Locating source... ")
22     task = e.cfgs["TASK"]
23     if filename is None:
24         dir = ""
25         file = task
26     else:
27         dir, file = os.path.split(filename)
28     if dir == "":
29         dir = e.cfgs["SOL_DIR"]
30
31     base, ext = os.path.splitext(file)
32     if ext != "":
33         if not os.path.exists(os.path.join(dir, file)):
34             raise moe.SolutionErr, "No solution of %s called %s found" % (task,file)
35         ext = ext[1:]
36         try_ext(e, ext)
37     else:
38         found = []
39         for ext in e.cfgs["EXTENSIONS"].split():
40             if os.path.exists(os.path.join(dir, base + "." + ext)):
41                 found.append(ext)
42         if len(found) == 0:
43             raise moe.SolutionErr, "No solution of %s found" % task
44         if len(found) > 1:
45             raise moe.SolutionErr, "Multiple solutions of %s found" % task
46         ext = found[0]
47         file = base + "." + ext
48
49     orig_path = os.path.join(dir, file)
50     norm_ext = normalize_ext(e, ext)
51     e.log.verbose("Found solution %s\n" % orig_path)
52
53     copy = e.cfgs["TASK"] + "." + norm_ext
54     copy_path = os.path.join(e.cfgs["TEST_DIR"], copy)
55     if file != copy:
56         e.log.verbose("Renaming to %s\n" % copy)
57     moe.util.link_or_copy(orig_path, copy_path)
58
59     e.builtins.set("SRC", copy)
60     e.builtins.set("EXT", norm_ext)
61     e.cfgs.apply_overrides("EXT_" + norm_ext)
62
63     e.stat["source"] = file
64     e.log.progress(file + "\n")
65
66 def compile_init(e):
67     e.log.progress("Compiling: ")
68     boxdir = moe.box.setup(e)
69     pdir = e.cfgs["TASK_DIR"]
70     tdir = e.cfgs["TEST_DIR"]
71     shutil.copyfile(os.path.join(tdir, e.cfgs["SRC"]), os.path.join(boxdir, e.cfgs["SRC"]))
72     for x in e.cfgs["EXTRAS"].split() + e.cfgs["COMP_EXTRAS"].split()
73         xx = os.path.join(tdir, x)
74         if not os.path.isfile(xx):
75             xx = os.path.join(pdir, x)
76         e.log.verbose("Copying extra file %s\n" % xx)
77         shutil.copyfile(xx, os.path.join(boxdir, x))
78
79 def compile_run(e):
80     moe.box.show(e, "compiler input")
81     cc = e.cfgs["COMP"]
82     e.log.verbose("Compilation command: %s\n" % cc)
83     rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], cc)
84     if rc > 0:
85         e.log.progress("FAILED\n")
86         ## FIXME: fill in the status file and abort the pipeline?
87     moe.box.show(e, "compiler output")
88
89 def compile_done(e):
90     e.log.progress("OK\n")
91
92 def tests(e):
93     pass
94
95 def prepare_pipe(e):
96     e.main_pipe.insert(100, "compile-init", compile_init)
97     e.main_pipe.insert(150, "compile-run", compile_run)
98     e.main_pipe.insert(190, "compile-done", compile_done)
99     e.main_pipe.insert(200, "batch-tests", tests)