##// END OF EJS Templates
tests: push with force in test_vcs_operations.py _add_files_and_push...
tests: push with force in test_vcs_operations.py _add_files_and_push Some tests push a fixed branch name. If such tests are run twice, it will fail second time when the other branch head already exists. Work around that by using force and thus replace the old head.

File last commit:

r7572:4473f109 default
r7660:76e2072b default
Show More
logformat.py
46 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
import re
import sys
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 %
(re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
# handle % without () - keeping spaces around the old %
(re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
# remove extra space if it is on next line
(re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
# remove extra space if it is on same line
(re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+ () ( [\n ]+) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
# remove trailing , and space
(re.compile(logre % r'''("[^"]*"|'[^']*') , () ( [\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
]
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:
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'''
raise SystemExit(1)
for f in sys.argv[1:]:
rewrite(f)