From 53926b8bbec10cb229fb229e4ff4d6a129102d70 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 25 Apr 2022 15:00:52 +0200 Subject: [PATCH] i18n: make language-updater more resilient --- CMakeLists.txt | 1 + ci/txstats.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5133415d..3ecdb0b66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,7 @@ set( _tx_ok ar ast bg bn el en_GB es_MX et eu gl hu id is mr nb oc pl ro sl sr sr@latin th ) set( _tx_incomplete eo es_PR gu ie ja-Hira kk kn lo lv mk ne_NP ta_IN te ur zh zh_HK ) +# Total 74 languages ### Required versions # diff --git a/ci/txstats.py b/ci/txstats.py index 69a34f89e..696a4b828 100755 --- a/ci/txstats.py +++ b/ci/txstats.py @@ -97,10 +97,12 @@ class EditingOutputter(object): lines = f.readlines() mark = None + mark_text = None for l in lines: # Note that we didn't strip the lines, so need the \n here if l.startswith("# Total ") and l.endswith(" languages\n"): mark = lines.index(l) + mark_text = l break if mark is None: raise TXError("No CMakeLists.txt lines for TX stats found") @@ -108,18 +110,17 @@ class EditingOutputter(object): nextmark = mark + 1 for l in lines[mark+1:]: - if l.startswith("set( _tx_"): - nextmark += 1 - continue - if l.startswith(" "): - nextmark += 1 - continue - break - if nextmark > mark + 12 or nextmark > len(lines) - 4: + nextmark += 1 + if l.startswith(mark_text): + break + if nextmark > mark + 100 or nextmark > len(lines) - 4: # Try to catch runaway nextmarks: we know there should # be four set-lines, which are unlikely to be 3 lines each; # similarly the CMakeLists.txt is supposed to end with # some boilerplate. + # + # However, gersemi will reformat to one-language-per-line, + # so we can get really long sections, that's why we use 100 as a limit. raise TXError("Could not find end of TX settings in CMakeLists.txt") self.post_lines = lines[nextmark:] @@ -185,7 +186,8 @@ def get_tx_stats(languages, outputter, verbose): ) all_langs = [] - outputter.print("# Total %d languages" % len(languages)) + mark_text = "# Total %d languages" % len(languages) + outputter.print(mark_text) for lang_name in languages: stats = languages[lang_name]["translated"]["percentage"] # Make the by-definition-incomplete languages have a percentage @@ -202,6 +204,7 @@ def get_tx_stats(languages, outputter, verbose): output_langs(all_langs, outputter, "good", lambda s : 1.0 > s >= 0.75) output_langs(all_langs, outputter, "ok", lambda s : 0.75 > s >= 0.05) output_langs(all_langs, outputter, "incomplete", lambda s : 0.05 > s) + outputter.print(mark_text) # Audit the languages that are in TX, mapped to git for lang_name in languages: