CI: tidy up scripts

- Add SPDX headers
 - Indent consistently (tabs, not a mix of 2-space, 4-space, and tabs)

The scripts were originally added without a license header.
Since they are simple, and re-usable, and not particularly
interesting, I've made the license explicitly 2-clause BSD.
This is unlike the rest of Calamares, which is GPLv3+; the
build system and support scripts are not the software itself.
This commit is contained in:
Adriaan de Groot 2020-02-06 13:11:23 +01:00
parent 0d2425ca78
commit dec30d70fd
3 changed files with 116 additions and 80 deletions

View File

@ -37,18 +37,18 @@ TX_FILE_LIST="lang/calamares_en.ts lang/python.pot src/modules/dummypythonqt/lan
# normally used much later in the script. # normally used much later in the script.
tx_cleanup() tx_cleanup()
{ {
# Cleanup artifacs of checking # Cleanup artifacs of checking
git worktree remove --force build-txcheck-head git worktree remove --force build-txcheck-head
git worktree remove --force build-txcheck-prev git worktree remove --force build-txcheck-prev
git branch -D build-txcheck-head > /dev/null 2>&1 git branch -D build-txcheck-head > /dev/null 2>&1
} }
if test "x$1" = "x--cleanup" ; then if test "x$1" = "x--cleanup" ; then
tx_cleanup tx_cleanup
exit 0 exit 0
fi fi
if test "x$1" = "x--help" ; then if test "x$1" = "x--help" ; then
sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0" sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0"
fi fi
test -z "$1" || { echo "! Usage: txcheck.sh [--cleanup]" ; exit 1 ; } test -z "$1" || { echo "! Usage: txcheck.sh [--cleanup]" ; exit 1 ; }
@ -59,22 +59,22 @@ test -z "$1" || { echo "! Usage: txcheck.sh [--cleanup]" ; exit 1 ; }
XMLLINT="" XMLLINT=""
for _xmllint in xmllint for _xmllint in xmllint
do do
$_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint
test -n "$XMLLINT" && break test -n "$XMLLINT" && break
done done
# Distinguish GNU date from BSD date # Distinguish GNU date from BSD date
if date +%s -d "1 week ago" > /dev/null 2>&1 ; then if date +%s -d "1 week ago" > /dev/null 2>&1 ; then
last_week() { date +%s -d "1 week ago" ; } last_week() { date +%s -d "1 week ago" ; }
else else
last_week() { date -v1w +%s; } last_week() { date -v1w +%s; }
fi fi
# Distinguish GNU SHA executables from BSD ones # Distinguish GNU SHA executables from BSD ones
if which sha256sum > /dev/null 2>&1 ; then if which sha256sum > /dev/null 2>&1 ; then
SHA256=sha256sum SHA256=sha256sum
else else
SHA256=sha256 SHA256=sha256
fi fi
### CHECK WORKING DIRECTORY ### CHECK WORKING DIRECTORY

View File

@ -1,4 +1,18 @@
#!/bin/sh #!/bin/sh
### LICENSE
# === This file is part of Calamares - <https://github.com/calamares> ===
#
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: 2017-2020 Adriaan de Groot <groot@kde.org>
# SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
#
# This file is Free Software: you can redistribute it and/or modify
# it under the terms of the 2-clause BSD License.
#
### END LICENSE
### USAGE
# #
# Fetch the Transifex translations for Calamares and incorporate them # Fetch the Transifex translations for Calamares and incorporate them
# into the source tree, adding commits of the different files. # into the source tree, adding commits of the different files.
@ -6,6 +20,8 @@
# Run this (occasionally) at the top-level directory to get # Run this (occasionally) at the top-level directory to get
# new translations. See also CMakeLists.txt and ci/txstats.py # new translations. See also CMakeLists.txt and ci/txstats.py
# for update instructions. # for update instructions.
#
### END USAGE
### INITIAL SETUP ### INITIAL SETUP
# #
@ -32,8 +48,8 @@ test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ;
XMLLINT="" XMLLINT=""
for _xmllint in xmllint for _xmllint in xmllint
do do
$_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint
test -n "$XMLLINT" && break test -n "$XMLLINT" && break
done done
# XMLLINT is optional # XMLLINT is optional
@ -53,9 +69,9 @@ tx pull --force --source --all
# so clean them up after pulling. # so clean them up after pulling.
# #
drop_language() { drop_language() {
rm -rf lang/python/"$1" src/modules/dummypythonqt/lang/"$1" lang/calamares_"$1".ts rm -rf lang/python/"$1" src/modules/dummypythonqt/lang/"$1" lang/calamares_"$1".ts
grep -v "\\[$1]" calamares.desktop > calamares.desktop.new grep -v "\\[$1]" calamares.desktop > calamares.desktop.new
mv calamares.desktop.new calamares.desktop mv calamares.desktop.new calamares.desktop
} }
drop_language es_ES drop_language es_ES
@ -68,10 +84,10 @@ mv calamares.desktop.new calamares.desktop
# And fixup the XML files like in txpush.sh # And fixup the XML files like in txpush.sh
if test -n "$XMLLINT" ; then if test -n "$XMLLINT" ; then
for TS_FILE in lang/calamares_*.ts for TS_FILE in lang/calamares_*.ts
do do
$XMLLINT --c14n11 "$TS_FILE" | { echo "<!DOCTYPE TS>" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE" $XMLLINT --c14n11 "$TS_FILE" | { echo "<!DOCTYPE TS>" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE"
done done
fi fi
@ -108,24 +124,24 @@ git diff --numstat src/modules | awk '($1==1 && $2==1){print $3}' | xargs git ch
# Go through the Python modules; those with a lang/ subdir have their # Go through the Python modules; those with a lang/ subdir have their
# own complete gettext-based setup. # own complete gettext-based setup.
for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do
FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f) FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f)
if test -n "$FILES" ; then if test -n "$FILES" ; then
MODULE_NAME=$(basename ${MODULE_DIR}) MODULE_NAME=$(basename ${MODULE_DIR})
if [ -d ${MODULE_DIR}/lang ]; then if [ -d ${MODULE_DIR}/lang ]; then
# Convert PO files to MO files # Convert PO files to MO files
for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do
sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
msgfmt -o ${POFILE%.po}.mo $POFILE msgfmt -o ${POFILE%.po}.mo $POFILE
done done
git add --verbose ${MODULE_DIR}/lang/* git add --verbose ${MODULE_DIR}/lang/*
git commit "$AUTHOR" --message="i18n: [${MODULE_NAME}] $BOILERPLATE" | true git commit "$AUTHOR" --message="i18n: [${MODULE_NAME}] $BOILERPLATE" | true
fi fi
fi fi
done done
for POFILE in $(find lang -name "python.po") ; do for POFILE in $(find lang -name "python.po") ; do
sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
msgfmt -o ${POFILE%.po}.mo $POFILE msgfmt -o ${POFILE%.po}.mo $POFILE
done done
git add --verbose lang/python* git add --verbose lang/python*
git commit "$AUTHOR" --message="i18n: [python] $BOILERPLATE" | true git commit "$AUTHOR" --message="i18n: [python] $BOILERPLATE" | true

View File

@ -1,13 +1,33 @@
#!/bin/sh #!/bin/sh
### LICENSE
# === This file is part of Calamares - <https://github.com/calamares> ===
#
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: 2017-2020 Adriaan de Groot <groot@kde.org>
# SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
#
# This file is Free Software: you can redistribute it and/or modify
# it under the terms of the 2-clause BSD License.
#
### END LICENSE
### USAGE
# #
# Extract translations from Calamares source and send them # Extract translations from Calamares source and send them
# to Transifex. # to Transifex. Also (forcibly) updates the git "translation"
# tag to document that source texts were updated and sent;
# this is used by txcheck.sh to ensure that there's enough
# time between updates and releases, and that strings don't
# change between updates and releases.
# #
# Run this at the top-level. # Run this at the top-level.
# #
# Use the --no-tx option to do the extraction, but not the # Use the --no-tx option to do the extraction, but not the
# pushing-to-Transifex part. This can be useful to check for # pushing-to-Transifex part. This can be useful to check for
# new strings or when testing the tools themselves. # new strings or when testing the tools themselves.
#
### END USAGE
### INITIAL SETUP ### INITIAL SETUP
# #
@ -28,21 +48,21 @@ test -f ".tx/config" || { echo "! Not at Calamares top-level" ; exit 1 ; }
test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ; } test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ; }
if test "x$1" = "x--no-tx" ; then if test "x$1" = "x--no-tx" ; then
# tx is the transifex command -- eat its arguments and do nothing # tx is the transifex command -- eat its arguments and do nothing
tx() { tx() {
echo "Skipped tx $*" echo "Skipped tx $*"
} }
# txtag is used to tag in git to measure changes -- skip it too # txtag is used to tag in git to measure changes -- skip it too
txtag() { txtag() {
echo "Skipped tx tagging." echo "Skipped tx tagging."
} }
else else
# tx is the regular transifex command # tx is the regular transifex command
# txtag is used to tag in git to measure changes # txtag is used to tag in git to measure changes
txtag() { txtag() {
git tag -f translation git tag -f translation
git push --force origin translation git push --force origin translation
} }
fi fi
@ -52,18 +72,18 @@ fi
LUPDATE="" LUPDATE=""
for _lupdate in lupdate-qt5 lupdate for _lupdate in lupdate-qt5 lupdate
do do
export QT_SELECT=5 export QT_SELECT=5
$_lupdate -version > /dev/null 2>&1 || export QT_SELECT=qt5 $_lupdate -version > /dev/null 2>&1 || export QT_SELECT=qt5
$_lupdate -version > /dev/null 2>&1 && LUPDATE=$_lupdate $_lupdate -version > /dev/null 2>&1 && LUPDATE=$_lupdate
test -n "$LUPDATE" && break test -n "$LUPDATE" && break
done done
test -n "$LUPDATE" || { echo "! No working lupdate" ; lupdate -version ; exit 1 ; } test -n "$LUPDATE" || { echo "! No working lupdate" ; lupdate -version ; exit 1 ; }
XMLLINT="" XMLLINT=""
for _xmllint in xmllint for _xmllint in xmllint
do do
$_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint
test -n "$XMLLINT" && break test -n "$XMLLINT" && break
done done
# XMLLINT is optional # XMLLINT is optional
@ -82,8 +102,8 @@ $LUPDATE -no-obsolete $_srcdirs -ts lang/calamares_en.ts
# $LUPDATE -no-obsolete -extensions cxxtr src/libcalamares/locale -ts lang/tz_en.ts # $LUPDATE -no-obsolete -extensions cxxtr src/libcalamares/locale -ts lang/tz_en.ts
if test -n "$XMLLINT" ; then if test -n "$XMLLINT" ; then
TS_FILE="lang/calamares_en.ts" TS_FILE="lang/calamares_en.ts"
$XMLLINT --c14n11 "$TS_FILE" | { echo "<!DOCTYPE TS>" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE" $XMLLINT --c14n11 "$TS_FILE" | { echo "<!DOCTYPE TS>" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE"
fi fi
tx push --source --no-interactive -r calamares.calamares-master tx push --source --no-interactive -r calamares.calamares-master
@ -103,29 +123,29 @@ PYGETTEXT="xgettext --keyword=_n:1,2 -L python"
SHARED_PYTHON="" SHARED_PYTHON=""
for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do
FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f) FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f)
if test -n "$FILES" ; then if test -n "$FILES" ; then
MODULE_NAME=$(basename ${MODULE_DIR}) MODULE_NAME=$(basename ${MODULE_DIR})
if [ -d ${MODULE_DIR}/lang ]; then if [ -d ${MODULE_DIR}/lang ]; then
${PYGETTEXT} -p ${MODULE_DIR}/lang -d ${MODULE_NAME} -o ${MODULE_NAME}.pot ${MODULE_DIR}/*.py ${PYGETTEXT} -p ${MODULE_DIR}/lang -d ${MODULE_NAME} -o ${MODULE_NAME}.pot ${MODULE_DIR}/*.py
POTFILE="${MODULE_DIR}/lang/${MODULE_NAME}.pot" POTFILE="${MODULE_DIR}/lang/${MODULE_NAME}.pot"
if [ -f "$POTFILE" ]; then if [ -f "$POTFILE" ]; then
sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE" sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE"
tx set -r calamares.${MODULE_NAME} --source -l en "$POTFILE" tx set -r calamares.${MODULE_NAME} --source -l en "$POTFILE"
tx push --source --no-interactive -r calamares.${MODULE_NAME} tx push --source --no-interactive -r calamares.${MODULE_NAME}
fi fi
else else
SHARED_PYTHON="$SHARED_PYTHON $FILES" SHARED_PYTHON="$SHARED_PYTHON $FILES"
fi fi
fi fi
done done
if test -n "$SHARED_PYTHON" ; then if test -n "$SHARED_PYTHON" ; then
${PYGETTEXT} -p lang -d python -o python.pot $SHARED_PYTHON ${PYGETTEXT} -p lang -d python -o python.pot $SHARED_PYTHON
POTFILE="lang/python.pot" POTFILE="lang/python.pot"
sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE" sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE"
tx set -r calamares.python --source -l en "$POTFILE" tx set -r calamares.python --source -l en "$POTFILE"
tx push --source --no-interactive -r calamares.python tx push --source --no-interactive -r calamares.python
fi fi
txtag txtag