annotate TOOLS/mphelp_check.py @ 37174:6c941fe7fc3e

Align backslashes followed by a newline (line continuation). Do so when the statement spans over multiple lines.
author ib
date Sun, 07 Sep 2014 22:22:50 +0000
parents a39a9aa7dc70
children
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
36688
a39a9aa7dc70 Update program documentation.
ib
parents: 36686
diff changeset
4 # conflicting definitions, mismatching arguments, extra definitions
a39a9aa7dc70 Update program documentation.
ib
parents: 36686
diff changeset
5 # not present in the base file and (optionally) missing definitions.
18522
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('"')
36686
8715803f09e8 Enhance the tool for checking translated messages header files.
ib
parents: 19177
diff changeset
28 if name in r:
8715803f09e8 Enhance the tool for checking translated messages header files.
ib
parents: 19177
diff changeset
29 print 'Conflict: ', name
8715803f09e8 Enhance the tool for checking translated messages header files.
ib
parents: 19177
diff changeset
30 print r[name]
8715803f09e8 Enhance the tool for checking translated messages header files.
ib
parents: 19177
diff changeset
31 print value
8715803f09e8 Enhance the tool for checking translated messages header files.
ib
parents: 19177
diff changeset
32 print
18522
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
33 r[name] = value
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
34 f.close()
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
35 return r
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
36
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
37 def compare(base, other, show_missing=False):
19177
9065db6f98d9 Regular expression for conversions had 'P' instead of 'p', fixed
uau
parents: 18532
diff changeset
38 r = re.compile('%[^diouxXeEfFgGaAcspn%]*[diouxXeEfFgGaAcspn%]')
18522
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
39 missing = []
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
40 for key in base:
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
41 if key not in other:
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
42 missing.append(key)
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
43 continue
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
44 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
45 print 'Mismatch: ', key
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
46 print base[key]
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
47 print other[key]
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
48 print
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
49 del other[key]
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
50 if other:
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
51 extra = other.keys()
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
52 extra.sort()
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
53 print 'Extra: ', ' '.join(extra)
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
54 if show_missing and missing:
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
55 missing.sort()
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
56 print 'Missing: ', ' '.join(missing)
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
57
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
58 if len(sys.argv) < 3:
18530
585837bbe7c3 Accept --missing as well as -missing, print less newlines.
diego
parents: 18522
diff changeset
59 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
60 '[otherfile2 ...]'
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
61 sys.exit(1)
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
62 i = 1
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
63 show_missing = False
18532
fe17e7634db1 10l: Really accept both one and two dashes.
diego
parents: 18530
diff changeset
64 if sys.argv[i] in ( '--missing', '-missing' ):
18522
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
65 show_missing = True
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
66 i = 2
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
67 base = parse(sys.argv[i])
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
68 for filename in sys.argv[i+1:]:
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
69 print '*****', filename
e151ef8cf21b Add tool to check MPlayer translation files for conflicting arguments
uau
parents:
diff changeset
70 compare(base, parse(filename), show_missing)
18530
585837bbe7c3 Accept --missing as well as -missing, print less newlines.
diego
parents: 18522
diff changeset
71 print '\n'