Mercurial > kallithea
annotate scripts/logformat.py @ 7477:006d68c4d7b9
files: use the web browsers built-in js history instead of native.history.js
The history API is available in all web browsers we support.
window.history.pushState is called to register a state that we can go
back/forward to. (But contrary to native.history.js, it doesn't do any
immediate processing of the state and doesn't actually navigate to it.)
When navigation occurs, we get the popstate event and invoke load_state to
actually load the state.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Tue, 25 Dec 2018 20:23:42 +0100 |
parents | 665dfa112f2c |
children | 4473f1094d3d |
rev | line source |
---|---|
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
2 |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
3 import re |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
4 import sys |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
5 |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
6 if len(sys.argv) < 2: |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
7 print 'Cleanup of superfluous % formatting of log statements.' |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
8 print 'Usage:' |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
9 print ''' hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff''' |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
10 raise SystemExit(1) |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
11 |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
12 |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
13 logre = r''' |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
14 (log\.(?:error|info|warning|debug) |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
15 [(][ \n]* |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
16 ) |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
17 %s |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
18 ( |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
19 [ \n]*[)] |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
20 ) |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
21 ''' |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
22 res = [ |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
23 # handle % () - keeping spaces around the old % |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
24 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'), |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
25 # handle % without () - keeping spaces around the old % |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
26 (re.compile(logre % r'''("[^"]*"|'[^']*') ([\n ]*) % ([\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'), |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
27 # remove extra space if it is on next line |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
28 (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'), |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
29 # remove extra space if it is on same line |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
30 (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+ () ( [\n ]+) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'), |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
31 # remove trailing , and space |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
32 (re.compile(logre % r'''("[^"]*"|'[^']*') , () ( [\n ]*) ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'), |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
33 ] |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
34 |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
35 for f in sys.argv[1:]: |
6860
665dfa112f2c
py3: replace "file" with "open"
Lars Kruse <devel@sumpfralle.de>
parents:
5599
diff
changeset
|
36 s = open(f).read() |
5599
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
37 for r, t in res: |
8bc8366a6874
cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
38 s = r.sub(t, s) |
6860
665dfa112f2c
py3: replace "file" with "open"
Lars Kruse <devel@sumpfralle.de>
parents:
5599
diff
changeset
|
39 open(f, 'w').write(s) |