Merge remote-tracking branch 'gci-binaryking/master'
[trojita.git] / l10n-fetch-po-files.py
blobbcf2dfacd2227af5edb550f5e80d9d5324966266
1 import os
2 import re
3 import subprocess
5 """Fetch the .po files from KDE's SVN for Trojita
7 Run me from Trojita's top-level directory.
8 """
11 SVN_PATH = "svn://anonsvn.kde.org/home/kde/trunk/l10n-kde4/"
12 SOURCE_PO_PATH = "/messages/extragear-pim/trojita_common.po"
13 OUTPUT_PO_PATH = "./po/"
14 OUTPUT_PO_PATTERN = "trojita_common_%s.po"
16 fixer = re.compile(r'^#~\| ', re.MULTILINE)
17 re_empty_msgid = re.compile('^msgid ""$', re.MULTILINE)
18 re_empty_line = re.compile('^$', re.MULTILINE)
19 re_has_qt_contexts = re.compile('X-Qt-Contexts: true\\n')
21 if not os.path.exists(OUTPUT_PO_PATH):
22 os.mkdir(OUTPUT_PO_PATH)
24 all_languages = subprocess.check_output(['svn', 'cat', SVN_PATH + 'subdirs'],
25 stderr=subprocess.STDOUT)
27 all_languages = [x.strip() for x in all_languages.split("\n") if len(x)]
28 for lang in all_languages:
29 try:
30 raw_data = subprocess.check_output(['svn', 'cat', SVN_PATH + lang + SOURCE_PO_PATH],
31 stderr=subprocess.PIPE)
32 (transformed, subs) = fixer.subn('# ~| ', raw_data)
33 pos1 = re_empty_msgid.search(transformed).start()
34 pos2 = re_empty_line.search(transformed).start()
35 if re_has_qt_contexts.search(transformed, pos1, pos2) is None:
36 transformed = transformed[:pos2] + \
37 '"X-Qt-Contexts: true\\n"\n' + \
38 transformed[pos2:]
39 subs = subs + 1
40 if (subs > 0):
41 print "Fetched %s (and performed %d cleanups)" % (lang, subs)
42 else:
43 print "Fetched %s" % lang
44 file(OUTPUT_PO_PATH + OUTPUT_PO_PATTERN % lang, "wb").write(transformed)
45 except subprocess.CalledProcessError:
46 print "No data for %s" % lang