File indexing completed on 2024-06-16 05:02:01
0001 import os 0002 import re 0003 import subprocess 0004 0005 """Fetch the .po files from KDE's SVN for Trojita 0006 0007 Run me from Trojita's top-level directory. 0008 """ 0009 0010 0011 SVN_PATH = "svn://anonsvn.kde.org/home/kde/trunk/l10n-kf5/" 0012 SOURCE_PO_PATH = "/messages/trojita/trojita_common.po" 0013 OUTPUT_PO_PATH = "./po/" 0014 OUTPUT_PO_PATTERN = "trojita_common_%s.po" 0015 0016 fixer = re.compile(r'^#~\| ', re.MULTILINE) 0017 re_empty_msgid = re.compile('^msgid ""$', re.MULTILINE) 0018 re_empty_line = re.compile('^$', re.MULTILINE) 0019 re_has_qt_contexts = re.compile('X-Qt-Contexts: true\\n') 0020 0021 if not os.path.exists(OUTPUT_PO_PATH): 0022 os.mkdir(OUTPUT_PO_PATH) 0023 0024 all_languages = subprocess.check_output(['svn', 'cat', SVN_PATH + 'subdirs'], 0025 stderr=subprocess.STDOUT) 0026 0027 all_languages = [x.strip() for x in all_languages.split("\n") if len(x)] 0028 for lang in all_languages: 0029 try: 0030 raw_data = subprocess.check_output(['svn', 'cat', SVN_PATH + lang + SOURCE_PO_PATH], 0031 stderr=subprocess.PIPE) 0032 (transformed, subs) = fixer.subn('# ~| ', raw_data) 0033 pos1 = re_empty_msgid.search(transformed).start() 0034 pos2 = re_empty_line.search(transformed).start() 0035 if re_has_qt_contexts.search(transformed, pos1, pos2) is None: 0036 transformed = transformed[:pos2] + \ 0037 '"X-Qt-Contexts: true\\n"\n' + \ 0038 transformed[pos2:] 0039 subs = subs + 1 0040 if (subs > 0): 0041 print "Fetched %s (and performed %d cleanups)" % (lang, subs) 0042 else: 0043 print "Fetched %s" % lang 0044 file(OUTPUT_PO_PATH + OUTPUT_PO_PATTERN % lang, "wb").write(transformed) 0045 except subprocess.CalledProcessError: 0046 print "No data for %s" % lang 0047 0048 # Inform qmake about the updated file list 0049 os.utime("CMakeLists.txt", None)