##// END OF EJS Templates
py3: some not-entirely-trivial removing of "unicode"
py3: some not-entirely-trivial removing of "unicode"

File last commit:

r8053:aa6f17a5 default
r8080:f9988201 default
Show More
logformat.py
49 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
Mads Kiilerich
future: use Python print function
r7750 from __future__ import print_function
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:')
print(''' hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.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)