forked from jhershberg/ovsdb_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pplog.py
62 lines (50 loc) · 1.33 KB
/
pplog.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
import string
from sys import stdout,stdin
line_num = 0
def nl():
global line_num
line_num += 1
stdout.write('\n' + i)
for l in stdin:
if '|' not in l: continue
(t, level, component, cat, art, msg) = string.split(l, '|', maxsplit=5)
I = ' '
opener = '[{<'
closer = ']}>'
i = ''
in_ws = 1
is_empty_list = 0
last_char = ''
title = ''
title_stack = []
for c in msg:
if in_ws and c in ' \t': continue
in_ws = 0
if c in closer:
i = i[:-2]
if not is_empty_list and last_char not in closer: nl()
in_ws = 1
is_empty_list = 0
title = ''
elif is_empty_list:
is_empty_list = 0
nl()
if last_char in closer and c != ',': nl()
stdout.write(c)
if not c in opener: title += c
last_char = c
if c in closer:
if len(title_stack):
(t,ln) = title_stack.pop()
if (line_num - ln) > 5: stdout.write(' /* ' + t.strip() + ' */')
if c in opener:
i += I
in_ws = 1
is_empty_list = 1
if title:
title_stack.append((title, line_num))
title = ''
if c == ',':
nl()
in_ws = 1
title = ''