Mercurial > dive4elements > river
comparison flys-artifacts/contrib/check-i18n-properties.py @ 2625:72ce02d1a568
Added consistency checker for i18n properties files.
flys-artifacts/trunk@4213 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 11 Apr 2012 10:54:26 +0000 |
parents | |
children | daf413420cf7 |
comparison
equal
deleted
inserted
replaced
2624:3f24865082da | 2625:72ce02d1a568 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys | |
4 import re | |
5 | |
6 SPLIT_RE = re.compile(r"^\s*([^=]+)=\s*(.*)\s*") | |
7 | |
8 def load_properties_file(filename): | |
9 props = {} | |
10 with open(filename, "r") as f: | |
11 while True: | |
12 line = f.readline() | |
13 if not line: break | |
14 m = SPLIT_RE.match(line) | |
15 if not m: continue | |
16 k = m.group(1).strip() | |
17 v = m.group(2).strip | |
18 if k in props: | |
19 print >> sys.stderr, "'%s' more than once in '%s'." % ( | |
20 k, filename) | |
21 else: | |
22 props[k] = v | |
23 return props | |
24 | |
25 def main(): | |
26 | |
27 props = [(arg, load_properties_file(arg)) for arg in sys.argv[1:]] | |
28 | |
29 l = len(props) | |
30 | |
31 for i in range(0, l): | |
32 a = props[i][1] | |
33 for j in range(i+1, l): | |
34 b = props[j][1] | |
35 for k in a.iterkeys(): | |
36 if k not in b: | |
37 print >> sys.stderr, "'%s' found in '%s' but not in '%s'." % ( | |
38 k, props[i][0], props[j][0]) | |
39 for k in b.iterkeys(): | |
40 if k not in a: | |
41 print >> sys.stderr, "'%s' found in '%s' but not in '%s'." % ( | |
42 k, props[j][0], props[i][0]) | |
43 | |
44 if __name__ == '__main__': | |
45 main() |