##// END OF EJS Templates
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
Mads Kiilerich -
r5586:8bc8366a default
parent child Browse files
Show More
@@ -0,0 +1,39 b''
1 #!/usr/bin/env python2
2
3 import re
4 import sys
5
6 if len(sys.argv) < 2:
7 print 'Cleanup of superfluous % formatting of log statements.'
8 print 'Usage:'
9 print ''' hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff'''
10 raise SystemExit(1)
11
12
13 logre = r'''
14 (log\.(?:error|info|warning|debug)
15 [(][ \n]*
16 )
17 %s
18 (
19 [ \n]*[)]
20 )
21 '''
22 res = [
23 # handle % () - keeping spaces around the old %
24 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
25 # handle % without () - keeping spaces around the old %
26 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
27 # remove extra space if it is on next line
28 (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
29 # remove extra space if it is on same line
30 (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+ () ( [\n ]+) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
31 # remove trailing , and space
32 (re.compile(logre % r'''("[^"]*"|'[^']*') , () ( [\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
33 ]
34
35 for f in sys.argv[1:]:
36 s = file(f).read()
37 for r, t in res:
38 s = r.sub(t, s)
39 file(f, 'w').write(s)
General Comments 0
You need to be logged in to leave comments. Login now