annotate TOOLS/mphelp_check.py @ 20863:8488e29241a5

[small fixes] - punctuation - improve markup of <screen> - fix odd '>|' as a shell redirection operator - sentence order - key names
author torinthiel
date Mon, 13 Nov 2006 11:02:30 +0000
parents 9065db6f98d9
children 8715803f09e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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):
19177
9065db6f98d9 Regular expression for conversions had 'P' instead of 'p', fixed
uau
parents: 18532
diff changeset
33 r = re.compile('%[^diouxXeEfFgGaAcspn%]*[diouxXeEfFgGaAcspn%]')
18522
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
fe17e7634db1 10l: Really accept both one and two dashes.
diego
parents: 18530
diff changeset
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'