##// END OF EJS Templates
deps: also report unseen known violations
deps: also report unseen known violations

File last commit:

r8548:0a84ef07 default
r8600:c7663810 default
Show More
logformat.py
47 lines | 1.8 KiB | text/x-python | PythonLexer
Mads Kiilerich
py3: switch to use Python 3 interpreter, temporarily leaving many things very broken until they have been migrated/fixed in a reviewable way...
r8053 #!/usr/bin/env python3
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586
import re
import sys
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 logre = r'''
(log\.(?:error|info|warning|debug)
[(][ \n]*
)
%s
(
[ \n]*[)]
)
'''
Mads Kiilerich
scripts: clean up and run the old scripts/logformat.py script
r7572
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 res = [
# handle % () - keeping spaces around the old %
Mads Kiilerich
flake8: fix E227 missing whitespace around bitwise or shift operator
r7727 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'),
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 # handle % without () - keeping spaces around the old %
Mads Kiilerich
flake8: fix E227 missing whitespace around bitwise or shift operator
r7727 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'),
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 # remove extra space if it is on next line
Mads Kiilerich
flake8: fix E227 missing whitespace around bitwise or shift operator
r7727 (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'),
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 # remove extra space if it is on same line
Mads Kiilerich
flake8: fix E227 missing whitespace around bitwise or shift operator
r7727 (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+ () ( [\n ]+) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'),
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 # remove trailing , and space
Mads Kiilerich
flake8: fix E227 missing whitespace around bitwise or shift operator
r7727 (re.compile(logre % r'''("[^"]*"|'[^']*') , () ( [\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE | re.VERBOSE), r'\1\2,\3\4\5\6'),
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 ]
Mads Kiilerich
scripts: clean up and run the old scripts/logformat.py script
r7572
def rewrite(f):
Lars Kruse
py3: replace "file" with "open"
r6785 s = open(f).read()
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 for r, t in res:
s = r.sub(t, s)
Lars Kruse
py3: replace "file" with "open"
r6785 open(f, 'w').write(s)
Mads Kiilerich
scripts: clean up and run the old scripts/logformat.py script
r7572
if __name__ == '__main__':
if len(sys.argv) < 2:
Mads Kiilerich
future: use Python print function
r7750 print('Cleanup of superfluous % formatting of log statements.')
print('Usage:')
Mads Kiilerich
scripts: handle running with pending deleted files...
r8548 print(''' hg revert `hg files 'set:**.py'|grep -v logformat.py` && scripts/logformat.py `hg files 'set:**.py'` && hg diff''')
Mads Kiilerich
scripts: clean up and run the old scripts/logformat.py script
r7572 raise SystemExit(1)
for f in sys.argv[1:]:
rewrite(f)