annotate scripts/logformat.py @ 6474:2ff913970025

journal: make "username:" filtering condition work as expected As described in previous revision, using TEXT in JOURNAL_SCHEMA causes unexpected results for "username:", too. - tokenization by non-alphanumeric characters - removing "stop words" To make "username:" filtering condition work as expected, this revision uses ID instead of TEST for "username" of JOURNAL_COLUMN.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 23 Jan 2017 02:17:38 +0900
parents 8bc8366a6874
children 665dfa112f2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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:]:
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
36 s = file(f).read()
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)
8bc8366a6874 cleanup: introduce scripts/logformat.py for cleanup of string formatting of logging statements
Mads Kiilerich <madski@unity3d.com>
parents:
diff changeset
39 file(f, 'w').write(s)