File: txpull.sh

package info (click to toggle)
calamares 3.3.14-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,444 kB
  • sloc: cpp: 71,554; python: 4,328; xml: 1,379; sh: 866; ansic: 105; makefile: 7
file content (167 lines) | stat: -rwxr-xr-x 5,818 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/sh

### LICENSE
# === This file is part of Calamares - <https://calamares.io> ===
#
#   SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
#   SPDX-FileCopyrightText: 2017-2020 Adriaan de Groot <groot@kde.org>
#   SPDX-License-Identifier: BSD-2-Clause
#
#   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
# into the source tree, adding commits of the different files.
#
# Run this (occasionally) at the top-level directory to get
# new translations. See also CMakeLists.txt and ci/txstats.py
# for update instructions.
#
### END USAGE

### SANITY CHECKING
#
# The script needs a .tx/config to talk to the Transifex server;
# it also checks that it is run from the top-level of a Calamares
# checkout. In order to use the system overall, you'll also need:
#  - ~/.gitconfig (For the git commits this does)
#  - ~/.transifexrc (Password token for Transifex)
#  - ~/.ssh (For git commits)
#
test -f "CMakeLists.txt" || { echo "! Not at Calamares top-level" ; exit 1 ; }
test -f ".tx/config" || { echo "! Not at Calamares top-level" ; exit 1 ; }
test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ; }


### FIND EXECUTABLES
#
#
XMLLINT=""
for _xmllint in xmllint
do
	$_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint
	test -n "$XMLLINT" && break
done
# XMLLINT is optional


### FETCH TRANSLATIONS
#
# Use Transifex client to get translations; this depends on the
# .tx/config file to locate files, and overwrites them in the
# filesystem with new (merged) translations.
export QT_SELECT=5
transifex-client pull --force --all || exit 1


### CLEANUP TRANSLATIONS
#
# Some languages have been deprecated. They may still exist in Transifex,
# so clean them up after pulling.
#
drop_language() {
	rm -rf lang/python/"$1" lang/calamares_"$1".ts
	grep -v "\\[$1]" calamares.desktop > calamares.desktop.new
	mv calamares.desktop.new calamares.desktop
}

# Also fix the .desktop file, which has some fields removed by Transifex.
#
{ cat calamares.desktop.in ; grep "\\[[a-zA-Z_@]*]=" calamares.desktop ; } > calamares.desktop.new
mv calamares.desktop.new calamares.desktop

# And fixup the XML files like in txpush.sh
if test -n "$XMLLINT" ; then
	for TS_FILE in lang/calamares_*.ts
	do
		$XMLLINT --c14n11 "$TS_FILE" | { echo "<!DOCTYPE TS>" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE"
	done
fi


### COMMIT TRANSLATIONS
#
# Produce multiple commits (for the various parts of the i18n
# infrastructure used by Calamares) of the updated translations.
# Try to be a little smart about not committing trivial changes.

# Who is credited with these CI commits
AUTHOR="--author='Calamares CI <groot@kde.org>'"
# Message to put after the module name
BOILERPLATE="Automatic merge of Transifex translations"

git add --verbose lang/calamares*.ts
git commit "$AUTHOR" --message="i18n: [calamares] $BOILERPLATE" | true

rm -f lang/desktop*.desktop
awk '
	BEGIN {skip=0;}
	/^# Translations/ {skip=1;}
	{if (!skip || (length($0)>1 && $0 != "# Translations")) {
		skip=0; print $0;
	}}' < calamares.desktop > calamares.desktop.new
mv calamares.desktop.new calamares.desktop
# Now group translated key-names (Name, Icon, Description, ..) by sorted
# language key rather than random-ish language-key order (which shuffles
# entries around).
#
# First, the non-translated lines
grep -v '\[.*\]=' calamares.desktop  > calamares.desktop.new
# The translated lines:
# - replace (the first) [] by | so we have a consistent field separator
# - sort based on field 2, then 1 (language code, then reversed key-name)
# - replace the first | by [, the first (remaining) | by ]
# Effectively this puts the fields in this order: Name, Icon, Generic Name,
# Comment -- within each language key. This keeps churn down since the
# language codes and key-names are constant.
grep '\[.*\]=' calamares.desktop | sed -e 's/\[/|/' -e 's/\]/|/' | sort -t '|' -k 2,2 -k 1,1r | sed -e 's/|/\[/' | sed -e 's/|/\]/' >> calamares.desktop.new
mv calamares.desktop.new calamares.desktop
git add --verbose calamares.desktop
git commit "$AUTHOR" --message="i18n: [desktop] $BOILERPLATE" | true

# Transifex updates the PO-Created timestamp also when nothing interesting
# has happened, so drop the files which have just 1 line changed (the
# PO-Created line). This applies only to modules which use po-files.
git diff --numstat src/modules | awk '($1==1 && $2==1){print $3}' | xargs git checkout --

# sed either wants -i'' (GNU sed) or -i '' (BSD sed) to
# replace in a file, with no backup extension. Define
# a `reinplace` command to deal with the difference.
if test FreeBSD = `uname` ; then
	reinplace() { 
		sed -i '' "$@"
	}
else
	reinplace() { 
		sed -i'' "$@"
	}
fi

# Go through the Python modules; those with a lang/ subdir have their
# own complete gettext-based setup.
for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do
	FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f)
	if test -n "$FILES" ; then
		MODULE_NAME=$(basename ${MODULE_DIR})
		if [ -d ${MODULE_DIR}/lang ]; then
			# Convert PO files to MO files
			for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do
				reinplace '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
				# msgfmt -o ${POFILE%.po}.mo $POFILE
			done
			git add --verbose ${MODULE_DIR}/lang/*
			git commit "$AUTHOR" --message="i18n: [${MODULE_NAME}] $BOILERPLATE" | true
		fi
	fi
done

for POFILE in $(find lang -name "python.po") ; do
	reinplace '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
	# msgfmt -o ${POFILE%.po}.mo $POFILE
done
git add --verbose lang/python*
git commit "$AUTHOR" --message="i18n: [python] $BOILERPLATE" | true