annotate scripts/logformat.py @ 7802:a545d2274120

helpers: rename internal names of authentication_token to clarify that secure_form is about session CSRF secrets - not authentication
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 22 Jul 2019 03:29:45 +0200
parents 4473f1094d3d
children 0a277465fddf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5599
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
1 #!/usr/bin/env python2
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
2
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
3 import re
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
4 import sys
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
5
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
6 logre = r'''
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
7 (log\.(?:error|info|warning|debug)
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
8 [(][ \n]*
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
9 )
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
10 %s
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
11 (
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
12 [ \n]*[)]
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
13 )
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
14 '''
7666
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
15
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
16
5599
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
17 res = [
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
18 # handle % () - keeping spaces around the old %
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
19 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
20 # handle % without () - keeping spaces around the old %
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
21 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
22 # remove extra space if it is on next line
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
23 (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
24 # remove extra space if it is on same line
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
25 (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+ () ( [\n ]+) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
26 # remove trailing , and space
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
27 (re.compile(logre % r'''("[^"]*"|'[^']*') , () ( [\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
28 ]
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
29
7666
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
30
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
31 def rewrite(f):
6860
665dfa112f2c py3: replace "file" with "open"
Lars Kruse <devel@sumpfralle.de>
parents: 5599
diff changeset
32 s = open(f).read()
5599
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
33 for r, t in res:
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
34 s = r.sub(t, s)
6860
665dfa112f2c py3: replace "file" with "open"
Lars Kruse <devel@sumpfralle.de>
parents: 5599
diff changeset
35 open(f, 'w').write(s)
7666
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
36
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
37
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
38 if __name__ == '__main__':
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
39 if len(sys.argv) < 2:
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
40 print 'Cleanup of superfluous % formatting of log statements.'
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
41 print 'Usage:'
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
42 print ''' hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff'''
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
43 raise SystemExit(1)
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
44
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
45 for f in sys.argv[1:]:
4473f1094d3d scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents: 6860
diff changeset
46 rewrite(f)