##// END OF EJS Templates
scripts: use explicit relative imports of contributor_data...
scripts: use explicit relative imports of contributor_data Avoid any ambiguity ... and avoid pytype failing to find scripts/contributor_data.py when scripts isn't in sys.path.

File last commit:

r7750:a8e6bb9e default
r8041:2786730e default
Show More
logformat.py
49 lines | 1.8 KiB | text/x-python | PythonLexer
Mads Kiilerich
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements...
r5586 #!/usr/bin/env python2
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)