Mercurial > kallithea
annotate scripts/logformat.py @ 7983:b075693b3214
pygrack: address webob AcceptValidHeader DeprecationWarning
Got warnings like:
kallithea/tests/other/test_vcs_operations.py::TestVCSOperations::test_yada_yada
.../site-packages/webob/acceptparse.py:649: DeprecationWarning: The behavior of AcceptValidHeader.__contains__ is currently being maintained for backward compatibility, but it will change in the future to better conform to the RFC.
DeprecationWarning,
There *must* be a better alternative to pygrack ... for now, let's keep it alive.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 24 Nov 2019 21:40:05 +0100 |
parents | a8e6bb9ee9ea |
children | aa6f17a53b49 |
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 |
7844
a8e6bb9ee9ea
future: use Python print function
Mads Kiilerich <mads@kiilerich.com>
parents:
7820
diff
changeset
|
3 from __future__ import print_function |
a8e6bb9ee9ea
future: use Python print function
Mads Kiilerich <mads@kiilerich.com>
parents:
7820
diff
changeset
|
4 |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
5 import re |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
6 import sys |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
7 |
7811
0a277465fddf
scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents:
7666
diff
changeset
|
8 |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
9 logre = r''' |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
10 (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
|
11 [(][ \n]* |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
12 ) |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
13 %s |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
14 ( |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
15 [ \n]*[)] |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
16 ) |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
17 ''' |
7666
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
18 |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
19 |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
20 res = [ |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
21 # handle % () - keeping spaces around the old % |
7820
63b548dd5ef3
flake8: fix E227 missing whitespace around bitwise or shift operator
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
22 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'), |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
23 # handle % without () - keeping spaces around the old % |
7820
63b548dd5ef3
flake8: fix E227 missing whitespace around bitwise or shift operator
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
24 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'), |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
25 # remove extra space if it is on next line |
7820
63b548dd5ef3
flake8: fix E227 missing whitespace around bitwise or shift operator
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
26 (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'), |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
27 # remove extra space if it is on same line |
7820
63b548dd5ef3
flake8: fix E227 missing whitespace around bitwise or shift operator
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
28 (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+ () ( [\n ]+) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'), |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
29 # remove trailing , and space |
7820
63b548dd5ef3
flake8: fix E227 missing whitespace around bitwise or shift operator
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
30 (re.compile(logre % r'''("[^"]*"|'[^']*') , () ( [\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'), |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
31 ] |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
32 |
7666
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
33 |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
34 def rewrite(f): |
6860
665dfa112f2c
py3: replace "file" with "open"
Lars Kruse <devel@sumpfralle.de>
parents:
5599
diff
changeset
|
35 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
|
36 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
|
37 s = r.sub(t, s) |
6860
665dfa112f2c
py3: replace "file" with "open"
Lars Kruse <devel@sumpfralle.de>
parents:
5599
diff
changeset
|
38 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
|
39 |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
40 |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
41 if __name__ == '__main__': |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
42 if len(sys.argv) < 2: |
7844
a8e6bb9ee9ea
future: use Python print function
Mads Kiilerich <mads@kiilerich.com>
parents:
7820
diff
changeset
|
43 print('Cleanup of superfluous % formatting of log statements.') |
a8e6bb9ee9ea
future: use Python print function
Mads Kiilerich <mads@kiilerich.com>
parents:
7820
diff
changeset
|
44 print('Usage:') |
a8e6bb9ee9ea
future: use Python print function
Mads Kiilerich <mads@kiilerich.com>
parents:
7820
diff
changeset
|
45 print(''' hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff''') |
7666
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
46 raise SystemExit(1) |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
47 |
4473f1094d3d
scripts: clean up and run the old scripts/logformat.py script
Mads Kiilerich <mads@kiilerich.com>
parents:
6860
diff
changeset
|
48 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
|
49 rewrite(f) |