~knitzsche/+junk/scripts-kylen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python

import os
import sys

if sys.argv[1] == "-h" or sys.argv[1] == "--help":
    print "Purpose:"
    print "Compares two msgid message set files produced with get_msgids to see if the set of translations has changed."
    print "If msgids have changed the return value is $1. If they have not, it is $0. If help was displayed, it is $2\n"
    print "Usage: diff_msgids <msgids1> <msgids2>\n"
    sys.exit(2)

if len(sys.argv) < 3: 
    print "Missing args, quitting. Use 'diff_msgids --help'"
    sys.exit(2)

arg1 = sys.argv[1]
arg2 = sys.argv[2]

f_1 = open(arg1, "r")
msgids_1 = f_1.readlines()
f_1.close()
f_2 = open(arg2, "r")
msgids_2 = f_2.readlines()
f_2.close()

msgs = []
msg = ""
if len(msgids_1) != len(msgids_2):
    msg += arg1 + " has " + str(len(msgids_1)) + "msgids\n"
    msg += arg2 + " has " + str(len(msgids_2)) + "msgids\n"
    msgs.append(msg)

for msgid in msgids_1:
    msg = ""
    if msgid not in msgids_2:
        msg += msgid + " not in " + arg2
        msgs.append(msg)
for msgid in msgids_2:
    msg = ""
    if msgid not in msgids_1:
        msg += msgid + " not in " + arg2
        msgs.append(msg)

if len(msgs) > 0:
    print "TRANSLATIONS HAVE CHANGED. Translators need to update po files."
    print "Details:"
    for msg in msgs:
        print msg

    sys.exit(1)

sys.exit(0)