]> mj.ucw.cz Git - moe.git/blob - t/moe/batch.py
Parts of compilation
[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     boxdir = moe.box.setup(e)
68     pdir = e.cfgs["TASK_DIR"]
69     tdir = e.cfgs["TEST_DIR"]
70     shutil.copyfile(os.path.join(tdir, e.cfgs["SRC"]), os.path.join(boxdir, e.cfgs["SRC"]))
71     for x in e.cfgs["EXTRAS"].split() + e.cfgs["COMP_EXTRAS"].split()
72         xx = os.path.join(tdir, x)
73         if not os.path.isfile(xx):
74             xx = os.path.join(pdir, x)
75         e.log.verbose("Copying extra file %s\n" % xx)
76         shutil.copyfile(xx, os.path.join(boxdir, x))
77     pass
78
79 def compile_run(e):
80     moe.box.show(e, "compiler input")
81     rc = moe.box.run(e, e.cfgs["COMP_SANDBOX_OPTS"], e.cfgs["COMP"])
82     moe.box.show(e, "compiler output")
83     pass
84
85 def compile_done(e):
86     pass
87
88 def tests(e):
89     pass
90
91 def prepare_pipe(e):
92     e.main_pipe.insert(100, "compile-init", compile_init)
93     e.main_pipe.insert(150, "compile-run", compile_run)
94     e.main_pipe.insert(190, "compile-done", compile_done)
95     e.main_pipe.insert(200, "batch-tests", tests)