# HOME set automatically
# CONTESTANT set automatically
# TASK set automatically
+## FIXME: Rename?
TASK_DIR="${HOME}/problems/${TASK}"
SOL_DIR="${HOME}/solutions/${CONTESTANT}/${TASK}"
TEST_DIR="${HOME}/testing/${CONTESTANT}/${TASK}"
TASK_TYPE=batch
+
+### Programming language settings
+
+# Known source file extensions
+EXTENSIONS="c cc C cpp p pas"
+
+# Some of the extensions can be aliases for other extensions
+ALIAS_EXT_cc=cpp
+ALIAS_EXT_C=cpp
+ALIAS_EXT_p=pas
+
+# SRC is auto
#!/usr/bin/env python
+import os.path
+import moe.log
+import moe.eval
+import moe.util
+
+def normalize_ext(e, ext):
+ alias = e.cfgs["ALIAS_EXT_" + ext]
+ return alias if alias != "" else ext
+
+def try_ext(e, ext):
+ for e in e.cfgs["EXTENSIONS"].split():
+ if e == ext:
+ return
+ raise moe.eval.MoeEvalErr, "Unknown extension: " + ext
+
+def locate(e, filename=None):
+ task = e.cfgs["TASK"]
+ if filename is None:
+ dir = ""
+ file = task
+ else:
+ dir, file = os.path.split(filename)
+ if dir == "":
+ dir = e.cfgs["SOL_DIR"]
+
+ base, ext = os.path.splitext(file)
+ if ext != "":
+ if not os.path.exists(os.path.join(dir, file)):
+ raise moe.eval.MoeEvalErr, "No solution of %s called %s found" % (task,file)
+ ext = ext[1:]
+ try_ext(e, ext)
+ else:
+ found = []
+ for ext in e.cfgs["EXTENSIONS"].split():
+ if os.path.exists(os.path.join(dir, base + "." + ext)):
+ found.append(ext)
+ if len(found) == 0:
+ raise moe.eval.MoeEvalErr, "No solution of %s found" % task
+ if len(found) > 1:
+ raise moe.eval.MoeEvalErr, "Multiple solutions of %s found" % task
+ ext = found[0]
+ file = base + "." + ext
+
+ orig_path = os.path.join(dir, file)
+ norm_ext = normalize_ext(e, ext)
+ moe.log.verbose("Found solution %s\n" % orig_path)
+
+ copy = e.cfgs["TASK"] + "." + norm_ext
+ copy_path = os.path.join(e.cfgs["TEST_DIR"], copy)
+ if file != copy:
+ moe.log.verbose("Renaming to %s\n" % copy)
+ moe.util.link_or_copy(orig_path, copy_path)
+
+ e.builtins.set("SRC", copy)
+ e.builtins.set("EXT", norm_ext)
+ e.cfgs.apply_overrides("EXT_" + norm_ext)
+
+ e.meta["source"] = copy
+
def compile(e):
pass
def tests(e):
pass
-def locate(e, file=None):
- pass
+def prepare_pipe(e):
+ e.main_pipe.insert(100, "compile", compile)
+ e.main_pipe.insert(200, "batch-tests", tests)
raise MoeEvalErr, "No such task %s" % task
task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config"))
self.cfgs.push(task_cfg)
+ self.meta["task"] = task
type = self.cfgs['TASK_TYPE']
if type == "batch" or type == "interactive":
- self.main_pipe.insert(100, "compile", moe.batch.compile)
- self.main_pipe.insert(200, "batch-tests", moe.batch.tests)
+ moe.batch.prepare_pipe(self)
elif type == "opendata":
raise MoeEvalErr, "Opendata tasks not implemented yet"
else: