From 8549d6e26f5116b1fcf5e066252cc987a3f2574f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 3 Jan 2023 20:55:54 +0000 Subject: [PATCH] Related: tdf#150687 check autocorr DocumentList.xml at build time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to ensure no noopt entries exist Change-Id: I9fb95e211d6030e1f551558fd5a0a3ca700c8fc2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145030 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- bin/check-autocorr.py | 39 +++++++++++++++++++ bin/find-autocorr-samevalue-beforeafter.py | 45 ---------------------- extras/CustomTarget_autocorr.mk | 6 ++- 3 files changed, 44 insertions(+), 46 deletions(-) create mode 100755 bin/check-autocorr.py delete mode 100755 bin/find-autocorr-samevalue-beforeafter.py diff --git a/bin/check-autocorr.py b/bin/check-autocorr.py new file mode 100755 index 000000000000..ebf1b50b1911 --- /dev/null +++ b/bin/check-autocorr.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Use this script to find the lines in extras/source/autocorr/lang//DocumentList.xml +# which contain the same value for abbreviated-name and name +# Usage sample: ./bin/check-autocorr.py extras/source/autocorr/lang/tr/DocumentList.xml + +import sys +import os +import xml.etree.ElementTree as ET + +complete_file = sys.argv[1] + +bAllFilesOk = True + +# parse the XML file +tree = ET.parse(complete_file) +root = tree.getroot() + +# find all elements X +elements_x = root.findall('.//block-list:block', namespaces={'block-list': "http://openoffice.org/2001/block-list"}) +for element in elements_x: + # get the value of the attribute "abbreviated-name" + value_a = element.get('{http://openoffice.org/2001/block-list}abbreviated-name') + # get the value of the attribute "name" + value_b = element.get('{http://openoffice.org/2001/block-list}name') + # check if the values are equal + if value_a == value_b: + print('In ' + complete_file + ' same value: ' + value_a) + bAllFilesOk = False + +if bAllFilesOk == True: + exit(0) +exit(1) diff --git a/bin/find-autocorr-samevalue-beforeafter.py b/bin/find-autocorr-samevalue-beforeafter.py deleted file mode 100755 index 7116100bdb87..000000000000 --- a/bin/find-autocorr-samevalue-beforeafter.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python3 - -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# Use this script to find the lines in extras/source/autocorr/lang//DocumentList.xml -# which contain the same value for abbreviated-name and name -# Usage sample: ./find-autocorr-samevalue-beforeafter.py - -import os -import xml.etree.ElementTree as ET - -root_dir = '../extras/source/autocorr/lang' - -bAllFilesOk = True - -for root, dirs, files in os.walk(root_dir): - for file in files: - - # just deal with DocumentList.xml, ignore the other files - if (file != "DocumentList.xml"): - continue - complete_file = os.path.join(str(root), file) - # parse the XML file - tree = ET.parse(complete_file) - root = tree.getroot() - - # find all elements X - elements_x = root.findall('.//block-list:block', namespaces={'block-list': "http://openoffice.org/2001/block-list"}) - for element in elements_x: - # get the value of the attribute "abbreviated-name" - value_a = element.get('{http://openoffice.org/2001/block-list}abbreviated-name') - # get the value of the attribute "name" - value_b = element.get('{http://openoffice.org/2001/block-list}name') - # check if the values are equal - if value_a == value_b: - print('In ' + complete_file + ' same value: ' + value_a) - bAllFilesOk = False - -if bAllFilesOk == True: - exit(0) -exit(1) diff --git a/extras/CustomTarget_autocorr.mk b/extras/CustomTarget_autocorr.mk index b602e5bb13ea..f97c8f1d2d71 100644 --- a/extras/CustomTarget_autocorr.mk +++ b/extras/CustomTarget_autocorr.mk @@ -9,6 +9,8 @@ $(eval $(call gb_CustomTarget_CustomTarget,extras/source/autocorr)) +autocorr_PYTHONCOMMAND := $(call gb_ExternalExecutable_get_command,python) + extras_AUTOCORR_LANGS := \ af-ZA:af-ZA \ bg:bg-BG \ @@ -268,11 +270,13 @@ $(call gb_CustomTarget_get_workdir,extras/source/autocorr)/acor_%.dat : \ $$(addprefix \ $(call gb_CustomTarget_get_workdir,extras/source/autocorr)/$$(call extras_AUTOCORR_SHORTLANG,$$*)/,\ mimetype \ - $$(call extras_AUTOCORR_XMLFILES_LANG,$$(call extras_AUTOCORR_SHORTLANG,$$*))) + $$(call extras_AUTOCORR_XMLFILES_LANG,$$(call extras_AUTOCORR_SHORTLANG,$$*))) \ + | $(call gb_ExternalExecutable_get_dependencies,python) $(call gb_Output_announce,autocorr/acor_$*.dat,$(true),ZIP,2) $(call gb_Trace_StartRange,autocorr/acor_$*.dat,ZIP) $(call gb_Helper_abbreviate_dirs,\ cd $(dir $<) && \ + $(autocorr_PYTHONCOMMAND) $(SRCDIR)/bin/check-autocorr.py DocumentList.xml && \ zip -q0X --filesync --must-match $@ mimetype && \ zip -qrX --must-match $@ $(call extras_AUTOCORR_XMLFILES_LANG,$(call extras_AUTOCORR_SHORTLANG,$*)) \ )