comparison TOOLS/mphelp_check.py @ 18522:e151ef8cf21b

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