[MPlayer-cvslog] CVS: main/TOOLS mphelp_check.py,NONE,1.1

Uoti Urpala CVS syncmail at mplayerhq.hu
Tue May 16 20:09:17 CEST 2006

CVS change done by Uoti Urpala CVS

Update of /cvsroot/mplayer/main/TOOLS
In directory mail:/var2/tmp/cvs-serv13386

Added Files:
Log Message:
Add tool to check MPlayer translation files for conflicting arguments
and extra/missing translation strings.

--- NEW FILE ---

# Tool to compare MPlayer translation files against a base file. Reports
# conflicting arguments, extra strings not present in the base file and
# (optionally) missing strings.

# Written by Uoti Urpala

import sys
import re

def parse(filename):
    r = {}
    f = open(filename)
    it = iter(f)
    cur = ''
    for line in it:
        line = line.strip()
        if not line.startswith('#define'):
            while line and line[-1] == '\\':
                line = it.next().strip()
        _, name, value = line.split(None, 2)
        value = value.strip('"')
        while line[-1] == '\\':
            line = it.next().strip()
            value += line.rstrip('\\').strip('"')
        r[name] = value
    return r

def compare(base, other, show_missing=False):
    r = re.compile('%[^diouxXeEfFgGaAcsPn%]*[diouxXeEfFgGaAcsPn%]')
    missing = []
    for key in base:
        if key not in other:
        if re.findall(r, base[key]) != re.findall(r, other[key]):
            print 'Mismatch: ', key
            print base[key]
            print other[key]
        del other[key]
    if other:
        extra = other.keys()
        print 'Extra: ', ' '.join(extra)
    if show_missing and missing:
        print 'Missing: ', ' '.join(missing)

if len(sys.argv) < 3:
    print 'Usage:\n'+sys.argv[0]+' [-missing] base_helpfile otherfile1 '\
          '[otherfile2 ...]'
i = 1
show_missing = False
if sys.argv[i] == '-missing':
    show_missing = True
    i = 2
base = parse(sys.argv[i])
for filename in sys.argv[i+1:]:
    print '*****', filename
    compare(base, parse(filename), show_missing)
    print '\n\n\n'

More information about the MPlayer-cvslog mailing list