forked from philchristensen/svn-color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvn-color.py
executable file
·64 lines (56 loc) · 1.47 KB
/
svn-color.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
Author: Saophalkun Ponlu (http://phalkunz.com)
Contact: [email protected]
Date: May 23, 2009
Modified: June 15, 2009
Additional modifications:
Author: Phil Christensen (http://bubblehouse.org)
Contact: [email protected]
Date: February 22, 2010
"""
import sys, subprocess
colorizedSubcommands = (
'status',
'stat',
'st',
'add',
'remove',
'diff',
'di',
)
statusColors = {
'M' : "31", # red
'?' : "37", # grey
'A' : "32", # green
'X' : "33", # yellow
'C' : "30;41", # black on red
'-' : "31", # red
'D' : "31;1", # bold red
'+' : "32", # green
}
def colorize(line):
for status in statusColors:
if line.startswith(status):
return ''.join(("\033[", statusColors[status], "m", line, "\033[m"))
else:
return line
if __name__ == '__main__':
command = sys.argv
command[0] = '/usr/bin/svn'
if len(command) > 1:
subcommand = (command[1], '')[len(command) < 2]
else:
subcommand = ''
if subcommand in colorizedSubcommands and sys.stdout.isatty():
task = subprocess.Popen(command, stdout=subprocess.PIPE)
while True:
line = task.stdout.readline()
if not line:
break
sys.stdout.write(colorize(line))
sys.stdout.flush()
else:
task = subprocess.Popen(command)
task.communicate()
sys.exit(task.returncode)