Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Klass <kissaki@posteo.de>2021-03-03 02:09:31 +0300
committerJan Klass <kissaki@posteo.de>2021-03-03 21:09:15 +0300
commitdf79c632e0649e1ac04276b087978dca2afed6c5 (patch)
tree6a4da6a0e95f3a4e6f9328cd6fd308657377a096
parent310212c516d550b9bc63b1bd7c2be8fe8aba2f3d (diff)
MAINT: Replace updatetranslations.sh with updatetranslations.py script
The bash script is not platform independent. The python script is. I invested way too much time trying to run the sh script on WSL (Windows Subsystem for Linux), installing Qt packages, but in the end still failing. I also implemented a bat script calling lupdate with the same parameters as the sh script, but having one platform independent script is preferable to having two separate scripts for the same activity. The python script will call lupdate to update the ts files like the sh script did, and commit the changes if any were made. Furthermore it checks that the ts files have no local changes before running, and after updating reset the git index, add commit the files. The reset operation is added so only the ts files are being committed. Contrary to the previous script this one disables all heuristics so those can be applied as separate changes, so they will be visible.
-rwxr-xr-x.ci/azure-pipelines/assertNoTranslationChanges.sh4
-rwxr-xr-x.ci/azure-pipelines/install-environment_linux_translations.bash2
-rwxr-xr-xscripts/updatetranslations.py136
-rwxr-xr-xscripts/updatetranslations.sh90
4 files changed, 139 insertions, 93 deletions
diff --git a/.ci/azure-pipelines/assertNoTranslationChanges.sh b/.ci/azure-pipelines/assertNoTranslationChanges.sh
index 171da997a..0a11bcb32 100755
--- a/.ci/azure-pipelines/assertNoTranslationChanges.sh
+++ b/.ci/azure-pipelines/assertNoTranslationChanges.sh
@@ -8,7 +8,7 @@
set -e
# Get path to the updatetranslations script
-updateScript="$BUILD_SOURCESDIRECTORY/scripts/updatetranslations.sh"
+updateScript="$BUILD_SOURCESDIRECTORY/scripts/updatetranslations.py"
# Get current commit hash
oldHash=`git rev-parse HEAD`
@@ -18,7 +18,7 @@ git config user.name "CI"
git config user.email "ci@mumble.info"
# Execute updatetranslations that'll commit any translation changes
-$updateScript > /dev/null
+python $updateScript
echo
# Ger new commit hash
diff --git a/.ci/azure-pipelines/install-environment_linux_translations.bash b/.ci/azure-pipelines/install-environment_linux_translations.bash
index 1e20cd7a7..3b038af9d 100755
--- a/.ci/azure-pipelines/install-environment_linux_translations.bash
+++ b/.ci/azure-pipelines/install-environment_linux_translations.bash
@@ -10,4 +10,4 @@ set -x
sudo apt-get update
-sudo apt-get -y install qttools5-dev-tools qt5-qmake
+sudo apt-get -y install qttools5-dev-tools
diff --git a/scripts/updatetranslations.py b/scripts/updatetranslations.py
new file mode 100755
index 000000000..38a88605e
--- /dev/null
+++ b/scripts/updatetranslations.py
@@ -0,0 +1,136 @@
+#!/usr/bin/env python3
+#
+# Copyright 2021 The Mumble Developers. All rights reserved.
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file at the root of the
+# Mumble source tree or at <https://www.mumble.info/LICENSE>.
+#
+# Updates the translation files src/mumble/mumble_*.ts from source and commits the changes.
+#
+# The main actions this script performs:
+# * lupdate to update translation strings
+# * Commit the resulting translation file
+#
+# Requires qt5 ; sudo apt-get install libqt5-dev
+
+import os, glob, logging, sys, subprocess, re
+import argparse
+from shutil import which
+from typing import Optional
+
+def FindLupdate(vcpkg_triplet: Optional[str] = None) -> Optional[str]:
+ logging.debug('Looking for lupdate…')
+ if which('lupdate') is not None:
+ return 'lupdate'
+ if vcpkg_triplet is not None:
+ vcpkgbin = os.path.join(os.path.expanduser('~'), 'vcpkg', 'installed', vcpkg_triplet, 'tools', 'qt5', 'bin')
+ logging.debug('Looking for lupdate in %s…', vcpkgbin)
+ return which('lupdate', path=vcpkgbin)
+ return None
+
+def CheckForGitHasTsFileChanges(tsfiles: list) -> bool:
+ res = subprocess.run(["git", "status", '--porcelain', '--'] + tsfiles, capture_output=True)
+ return res.returncode == 0 and len(res.stdout) > 0
+
+def Commit(tsfiles: list) -> None:
+ res = subprocess.run(["git", "reset", '--mixed'], capture_output=True)
+ if res.returncode != 0:
+ logging.error('The git reset call returned an error status code ' + res.returncode)
+ logging.debug('stdout: ' + res.stdout)
+ exit(1)
+ res = subprocess.run(["git", "add"] + tsfiles, capture_output=True)
+ if res.returncode != 0:
+ logging.error('The git add call returned an error status code ' + res.returncode)
+ logging.debug('stdout: ' + res.stdout)
+ exit(1)
+ res = subprocess.run(["git", "commit", '-m', 'TRANSLATION: Update translation files'], capture_output=True)
+ if res.returncode != 0:
+ logging.error('The git commit call returned an error status code ' + res.returncode)
+ logging.debug('stdout: ' + res.stdout)
+ exit(1)
+
+def Update(lupdatebin, tsfile: str, debuglupdate: bool) -> (int, int, int):
+ res = subprocess.run([
+ lupdatebin
+ # Do not explain what is being done.
+ , '-no-ui-lines'
+ # {sametext|similartext|number}
+ , '-disable-heuristic', 'sametext'
+ , '-disable-heuristic', 'similartext'
+ , '-disable-heuristic', 'number'
+ # {absolute|relative|none}
+ , '-locations', 'none'
+ , '-no-obsolete'
+ , '-no-recursive'
+ , '-extensions', 'ui,c,cpp,h,mm'
+ # sources
+ , './src', './src/mumble'
+ # target
+ , '-ts', tsfile
+ ], capture_output=True)
+ if debuglupdate:
+ logging.debug(res.stdout)
+ if res.returncode != 0:
+ logging.error('lupdate failed with error code %d', res.returncode)
+ logging.debug('stdout: ' + res.stdout)
+ exit(1)
+ p = re.compile('Found (?P<nsrc>[0-9]+) source text\(s\) \((?P<nnew>[0-9]+) new and (?P<nsame>[0-9]+) already existing\)')
+ m = p.search(res.stdout.decode("ascii"))
+ logging.debug('Found %s texts where %s new and %s same', m.group('nsrc'), m.group('nnew'), m.group('nsame'))
+ return (m.group('nsrc'), m.group('nnew'), m.group('nsame'))
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--vcpkg-triplet', type=str, required=False, help='the vcpkg triplet to use the lupdate tool from, e.g. "x64-windows-static-md"')
+ parser.add_argument('--debug', dest='debug', action='store_true')
+ parser.add_argument('--debug-lupdate', dest='debuglupdate', action='store_true')
+ parser.set_defaults(debug=False, debuglupdate=False)
+ args = parser.parse_args()
+
+ loglevel = logging.DEBUG if args.debug else logging.INFO
+ logging.basicConfig(stream=sys.stdout, level=loglevel, format='%(levelname)s: %(message)s')
+
+ lupdatebin = FindLupdate(args.vcpkg_triplet)
+ if lupdatebin is None:
+ logging.error('Could not find `lupdate` executable')
+ exit(1)
+
+ # cd into repository root directory
+ os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..")
+ logging.info('Working in directory %s', os.getcwd())
+
+ tsfiles = glob.glob(os.path.join('src', 'mumble', 'mumble_*.ts'))
+ logging.debug('Identified these ts files: %s', tsfiles)
+
+ logging.info('Ensuring ts files have no local changes…')
+ if CheckForGitHasTsFileChanges(tsfiles):
+ logging.error('There are ts files with local changes. Cancelling execution.')
+ exit(1)
+
+ logging.info('Updating ts files…')
+ nsrc: Optional[int] = None
+ nnew: Optional[int] = None
+ nsame: Optional[int] = None
+ mismatch = False
+ for tsfile in tsfiles:
+ logging.debug('Updating ts file ' + tsfile + '…')
+ (resnsrc, resnnew, resnsame) = Update(lupdatebin, tsfile, args.debuglupdate)
+ if nsrc is None:
+ nsrc = resnsrc
+ nnew = resnnew
+ nsame = resnsame
+ else:
+ if nsrc != resnsrc or nnew != resnnew or nsame != resnsame:
+ logging.warn('Mismatching counts of updating changes between ts files: %s %s %s vs %s %s %s', nsrc, nnew, nsame, resnsrc, resnnew, resnsame)
+ mismatch = True
+
+ if nsrc is not None:
+ logging.info('Found %s texts where %s new and %s same', nsrc, nnew, nsame)
+
+ if CheckForGitHasTsFileChanges(tsfiles):
+ logging.info('Committing changes…')
+ Commit(tsfiles)
+ else:
+ logging.info('No changes to commit.')
+
+ logging.info('The updating of the translation files successfully completed.')
diff --git a/scripts/updatetranslations.sh b/scripts/updatetranslations.sh
deleted file mode 100755
index 15efabb00..000000000
--- a/scripts/updatetranslations.sh
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright 2014-2021 The Mumble Developers. All rights reserved.
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file at the root of the
-# Mumble source tree or at <https://www.mumble.info/LICENSE>.
-
-# Updates mumble_en.ts from source and adds a commit.
-#
-# The main actions this script performs:
-# * lupdate to update translation strings
-# * Commit the resulting translation file
-#
-# Requires qt5 ; sudo apt-get install libqt5-dev
-# As the QT project files are parsed, additional qt dependencies apply;
-# sudo apt-get install libqt5svg5-dev
-
-set -u
-set -e
-set -o pipefail
-
-rootDir="$(dirname $(realpath $0))/.."
-
-cd "$rootDir"
-
-# Make sure we are using Qt5
-export QT_SELECT=5
-tmpfile="commitmessage.tmp"
-
-function requireCommand
-{
- local c=$1
- command -v $c >/dev/null 2>&1 || { printError "The required command $c is not available." >&2; exit 1; }
-}
-
-function checkRequirements
-{
- requireCommand lupdate
- requireCommand qmake
- requireCommand git
-}
-
-function printError
-{
- echo -e "\e[1;31mERROR\e[0m: $1"
-}
-
-function fatal
-{
- local msg="${1:-"Exiting because a command returned the error code $code"}"
-
- printError "$msg"
- exit 1
-}
-
-function main
-{
- checkRequirements
-
- echo "TRANSLATION: Update translation files" > $tmpfile
- echo "" >> $tmpfile
-
- for filePath in src/mumble/*.ts; do
- if [[ -n $(git status --porcelain "$filePath") ]] ; then
- printError "The file $filePath has local changes."
- exit 1
- fi
-
- lupdate -no-ui-lines -disable-heuristic similartext -locations none -no-obsolete -no-recursive -extensions "ui,c,cpp,h,mm" "./src" "./src/mumble" -ts "$filePath" \
- | tee -a $tmpfile || fatal "lupdate failed"
- echo ""
- done
-
- if ! [[ -n $(git status --porcelain src/mumble/mumble_*.ts) ]] ; then
- echo "No translation changes. Nothing to commit."
- rm $tmpfile
- exit 0
- fi
-
- echo "Committing changes ..."
- git commit -F $tmpfile $filePath || (rm $tmpfile ; fatal "Failed to commit the changes")
- rm $tmpfile || printError "Failed to remove temporary file '$tmpfile'"
-
- echo "Probably done."
- echo
- echo "Before pushing, _manually_ check the output above as well as the commits changes."
- echo "An lupdate warning about overriding TRANSLATIONS is expected, as well as \"removal of plural forms\". Any project errors (missing qt modules) however are not, and the resulting changes must not be pushed."
-}
-
-main