Skip to content
Newer
Older
100644 50 lines (37 sloc) 1020 Bytes
e18fa85 @apenwarr The only thing in helpers.py that needed vars.py was the log stuff.
authored
1 import sys, os
2 import vars
3
cb1512b Use named constants for terminal control codes.
Tim Allen authored
4 # By default, no output colouring.
5 RED = ""
6 GREEN = ""
7 YELLOW = ""
8 BOLD = ""
9 PLAIN = ""
10
f6ea1fd @apenwarr log.py, minimal/do: don't use ansi colour codes if $TERM is blank or …
authored
11 if sys.stderr.isatty() and (os.environ.get('TERM') or 'dumb') != 'dumb':
cb1512b Use named constants for terminal control codes.
Tim Allen authored
12 # ...use ANSI formatting codes.
13 RED = "\x1b[31m"
14 GREEN = "\x1b[32m"
15 YELLOW = "\x1b[33m"
16 BOLD = "\x1b[1m"
17 PLAIN = "\x1b[m"
18
19
e18fa85 @apenwarr The only thing in helpers.py that needed vars.py was the log stuff.
authored
20 def log_(s):
21 sys.stdout.flush()
22 if vars.DEBUG_PIDS:
23 sys.stderr.write('%d %s' % (os.getpid(), s))
24 else:
25 sys.stderr.write(s)
26 sys.stderr.flush()
27
28
cb1512b Use named constants for terminal control codes.
Tim Allen authored
29 def log(s):
30 log_(''.join([GREEN, "redo ", vars.DEPTH, BOLD, s, PLAIN]))
e18fa85 @apenwarr The only thing in helpers.py that needed vars.py was the log stuff.
authored
31
cb1512b Use named constants for terminal control codes.
Tim Allen authored
32 def err(s):
33 log_(''.join([RED, "redo ", vars.DEPTH, BOLD, s, PLAIN]))
e18fa85 @apenwarr The only thing in helpers.py that needed vars.py was the log stuff.
authored
34
cb1512b Use named constants for terminal control codes.
Tim Allen authored
35 def warn(s):
36 log_(''.join([YELLOW, "redo ", vars.DEPTH, BOLD, s, PLAIN]))
e18fa85 @apenwarr The only thing in helpers.py that needed vars.py was the log stuff.
authored
37
38
39 def debug(s):
40 if vars.DEBUG >= 1:
41 log_('redo: %s%s' % (vars.DEPTH, s))
42 def debug2(s):
43 if vars.DEBUG >= 2:
44 log_('redo: %s%s' % (vars.DEPTH, s))
45 def debug3(s):
46 if vars.DEBUG >= 3:
47 log_('redo: %s%s' % (vars.DEPTH, s))
48
49
Something went wrong with that request. Please try again.