]> mj.ucw.cz Git - moe.git/blob - t/moe/log.py
Judges can return single-line verdicts on stderr instead of producing a status file
[moe.git] / t / moe / log.py
1 #!/usr/bin/env python
2
3 import sys
4 import os
5
6 progress_file = os.fdopen(os.dup(1), "w", 0)
7
8 class MoeLog:
9
10     def __init__(self):
11         self.verbosity = 0
12         self.progress_file = progress_file
13         self.log_file = None
14
15     def open(self, name):
16         self.log_file = open(name, "w")
17         os.dup2(self.log_file.fileno(), 1)
18         os.dup2(self.log_file.fileno(), 2)
19
20     def say(self, msg):
21         if self.log_file:
22             self.log_file.write(msg)
23
24     def verbose(self, msg):
25         if self.verbosity and self.log_file:
26             self.log_file.write(msg)
27
28     def progress(self, msg):
29         if self.progress_file:
30             self.progress_file.write(msg)
31
32     def shout(self, msg):
33         self.say(msg)
34         self.progress(msg)
35
36     def flush(self):
37         self.log_file.flush()
38
39 default = MoeLog()