Mercurial > kallithea
view scripts/logformat.py @ 6226:590d5b7a2b26
db: do case-insensitive explicit sorting of RepoGroup names
This does not change the implicit sorting enabled via __mapper_args__,
which is a bad idea anyway (and now deprecated), and will have to be
dealt with in a later changeset.
The use of __mapper_args__ implicitly adds sorting to every query of
RepoGroup objects throughout the code (including implicit queries via
relationships). For the relationships, __mapper_args can be replaced
with "order_by" on each individual relationship, and it's reasonably
straight-forward to identify every RepoGroup query throughout the code,
and add explicit sorting. But we don't really need that sorting most
of the time, so a better way forward may be to identify all the places
that actually needs the sorting, make it explicit there, and then kill
the __mapper_args__. (Anyway, future work.)
author | Søren Løvborg <sorenl@unity3d.com> |
---|---|
date | Thu, 15 Sep 2016 15:13:27 +0200 |
parents | 8bc8366a6874 |
children | 665dfa112f2c |
line wrap: on
line source
#!/usr/bin/env python2 import re import sys 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) logre = r''' (log\.(?:error|info|warning|debug) [(][ \n]* ) %s ( [ \n]*[)] ) ''' 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'), ] for f in sys.argv[1:]: s = file(f).read() for r, t in res: s = r.sub(t, s) file(f, 'w').write(s)