]> mj.ucw.cz Git - moe.git/blob - t/moe/box.py
Sanitize by adding newlines detween defs
[moe.git] / t / moe / box.py
1 #!/usr/bin/env python
2
3 import moe
4 import moe.util
5 import os.path
6
7 def init(e):
8     user = e["TEST_USER"]
9     if user == "":
10         e.log.verbose("Sandbox running locally\n")
11         e.builtins.parse_line("BOXDIR=${HOME}/box")
12         e.builtins.parse_line("BOXEXE=${HOME}/bin/box")
13     else:
14         e.log.verbose("Sandbox user: %s\n" % user);
15         e.builtins.parse_line("BOXDIR=${HOME}/box")
16         e.builtins.parse_line("BOXEXE=${HOME}/bin/box-" + user)
17     e.builtins.parse_line("BOXCMD=${BOXEXE} -c${BOXDIR}")
18     dir = e["BOXDIR"]
19     cmd = e["BOXCMD"]
20     exe = e["BOXEXE"]
21     e.log.verbose("Sandbox directory: %s\n" % dir)
22     e.log.verbose("Sandbox command: %s\n" % cmd)
23     if dir == "" or not os.path.isdir(dir) or exe == "" or not os.path.isfile(exe):
24         raise moe.MoeError, "Sandbox set up incorrectly"
25
26 def clean(e):
27     moe.util.remove_tree_contents(e["BOXDIR"])
28
29 def setup(e):
30     clean(e)
31     return e["BOXDIR"]
32
33 def show(e, msg):
34     if e.log.verbosity > 1:
35         e.log.verbose("Box contents for %s:\n" % msg)
36         e.log.flush()
37         os.system("ls -Al %s | sed 's/^/\t/'" % e["BOXDIR"])
38
39 def run(e, opts, cmd):
40     c = e["BOXCMD"] + " " + opts + " -- " + cmd
41     e.log.verbose("Sandbox: %s\n" % c)
42     e.log.flush()
43     st = os.system(c)
44     if os.WIFEXITED(st):
45         rc = os.WEXITSTATUS(st)
46         if rc > 1:
47             raise moe.MoeError, "Sandbox failed with rc=%d" % rc
48         return rc
49     else:
50         raise moe.MoeError, "Sandbox failed with exit status 0x%04x" % rc