-
Notifications
You must be signed in to change notification settings - Fork 2
/
svn-color.py
82 lines (62 loc) · 1.68 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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
Requiere de colorama
"""
from colorama import init, Fore, Back, Style
import sys, re, subprocess
init()
tabsize = 4
colorizedSubcommands = (
'st',
'status',
'add',
'remove',
'diff',
)
statusColors = {
"M" : Fore.RED, # red
"\?" : Fore.BLUE, # grey
"A" : Fore.GREEN, # green
"X" : Fore.YELLOW, # yellow
"C" : Back.BLACK + Fore.RED , # black on red
"-" : Fore.RED, # red
"D" : Style.DIM + Fore.RED, # bold red
"\+" : Fore.GREEN, # green
"!": Fore.CYAN,
}
def colorize(line):
for color in statusColors:
if re.match(color, line):
print statusColors[color] + line + Fore.RESET + Back.RESET + Style.RESET_ALL
return
else:
print line
def escape(s):
s = s.replace('$', r'\$')
s = s.replace('"', r'\"')
s = s.replace('`', r'\`')
return s
passthru = lambda x: x
quoted = lambda x: '"%s"' % escape(x)
if __name__ == "__main__":
cmd = ' '.join(['svn']+[(passthru, quoted)[' ' in arg](arg) for arg in sys.argv[1:]])
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
cancelled = False
lines = output.stdout.readlines()
if sys.argv[1] not in ('diff'):
lines.sort()
for line in lines:
line = line.expandtabs(tabsize)
line = line.rstrip()
if (sys.argv[1] in colorizedSubcommands):
line = colorize(line)
else:
print line