Mercurial > mplayer.hg
annotate TOOLS/mphelp_check.py @ 18771:a1807995e2ab
Move #ifdefs around complete files into the build system.
author | diego |
---|---|
date | Wed, 21 Jun 2006 14:49:09 +0000 |
parents | fe17e7634db1 |
children | 9065db6f98d9 |
rev | line source |
---|---|
18522
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
1 #!/usr/bin/python |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
2 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
3 # Tool to compare MPlayer translation files against a base file. Reports |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
4 # conflicting arguments, extra strings not present in the base file and |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
5 # (optionally) missing strings. |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
6 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
7 # Written by Uoti Urpala |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
8 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
9 import sys |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
10 import re |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
11 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
12 def parse(filename): |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
13 r = {} |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
14 f = open(filename) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
15 it = iter(f) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
16 cur = '' |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
17 for line in it: |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
18 line = line.strip() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
19 if not line.startswith('#define'): |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
20 while line and line[-1] == '\\': |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
21 line = it.next().strip() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
22 continue |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
23 _, name, value = line.split(None, 2) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
24 value = value.strip('"') |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
25 while line[-1] == '\\': |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
26 line = it.next().strip() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
27 value += line.rstrip('\\').strip('"') |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
28 r[name] = value |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
29 f.close() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
30 return r |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
31 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
32 def compare(base, other, show_missing=False): |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
33 r = re.compile('%[^diouxXeEfFgGaAcsPn%]*[diouxXeEfFgGaAcsPn%]') |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
34 missing = [] |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
35 for key in base: |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
36 if key not in other: |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
37 missing.append(key) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
38 continue |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
39 if re.findall(r, base[key]) != re.findall(r, other[key]): |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
40 print 'Mismatch: ', key |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
41 print base[key] |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
42 print other[key] |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
43 print |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
44 del other[key] |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
45 if other: |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
46 extra = other.keys() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
47 extra.sort() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
48 print 'Extra: ', ' '.join(extra) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
49 if show_missing and missing: |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
50 missing.sort() |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
51 print 'Missing: ', ' '.join(missing) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
52 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
53 if len(sys.argv) < 3: |
18530
585837bbe7c3
Accept --missing as well as -missing, print less newlines.
diego
parents:
18522
diff
changeset
|
54 print 'Usage:\n'+sys.argv[0]+' [--missing] base_helpfile otherfile1 '\ |
18522
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
55 '[otherfile2 ...]' |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
56 sys.exit(1) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
57 i = 1 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
58 show_missing = False |
18532 | 59 if sys.argv[i] in ( '--missing', '-missing' ): |
18522
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
60 show_missing = True |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
61 i = 2 |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
62 base = parse(sys.argv[i]) |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
63 for filename in sys.argv[i+1:]: |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
64 print '*****', filename |
e151ef8cf21b
Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff
changeset
|
65 compare(base, parse(filename), show_missing) |
18530
585837bbe7c3
Accept --missing as well as -missing, print less newlines.
diego
parents:
18522
diff
changeset
|
66 print '\n' |