-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathglossaire.sh
executable file
·350 lines (305 loc) · 10.7 KB
/
glossaire.sh
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#! /usr/bin/env bash
# Syntax:
# - locale code: update only the requested locale
# - 'no-snapshot': avoid creating a data snapshot
function interrupt_code()
# This code runs if user hits control-c
{
echored "\n*** Operation interrupted ***\n"
exit $?
}
# Trap keyboard interrupt (control-c)
trap interrupt_code SIGINT
# Pretty printing functions
standard_color=$(tput sgr0)
green=$(tput setaf 2; tput bold)
red=$(tput setaf 1)
function echored() {
echo -e "$red$*$standard_color"
}
function echogreen() {
echo -e "$green$*$standard_color"
}
function echo_manual() {
echo "Run 'glossaire.sh' without parameters to update all locales."
echo "Run 'glossaire.sh help' to display this manual."
echo "---"
echo "To update only one locale, add the locale code as first parameter"
echo "(e.g. 'glossaire.sh fr' to update only French)."
echo "---"
echo "To update all locales, and avoid creating a data snapshot at the end, add 'no-snapshot'"
echo "(e.g. 'glossaire.sh no-snapshot' to update all locales without creating a data snapshot)."
echo "---"
echo "To update only one locale, and avoid creating a data snapshot at the end, add locale code and 'no-snapshot'"
echo "(e.g. 'glossaire.sh fr no-snapshot' to update only French without creating a data snapshot)."
echo "---"
echo "To avoid pulling changes from repositories, add 'no-update'"
echo "(e.g. 'glossaire.sh fr no-update' to update only French without updating repositories)."
echo "---"
echo "To force TMX creation, add 'force-tmx'"
echo "(e.g. 'glossaire.sh force-tmx' to update all locales and forcing TMX creation)."
echo "(e.g. 'glossaire.sh fr no-snapshot force-tmx' to update only French without creating a data snapshot and forcing TMX creation)."
}
all_locales=true
create_snapshot=true
forceTMX=false
checkrepo=true
while [[ $# -gt 0 ]]
do
case $1 in
force-tmx)
forceTMX=true
;;
help)
echo_manual
exit
;;
no-snapshot)
create_snapshot=false
;;
no-update)
checkrepo=false
;;
*)
all_locales=false
locale_code=$1
;;
esac
shift
done
echo "Request summary:"
echo "* Create data snapshot: ${create_snapshot}"
echo "* Force TMX creation: ${forceTMX}"
echo "* Update repositories: ${checkrepo}"
if [ "$all_locales" = true ]
then
echo "* Elaborate all locales: ${all_locales}"
else
echo "* Elaborate locale: ${locale_code}"
fi
# Get configuration variables from config/config.ini
app_folder=$(dirname $PWD)
export PATH=$PATH:$app_folder/app/inc
export PATH=$PATH:$app_folder/
# Store the relative path to the script
script_path=$(dirname "$0")
# Convert .ini file in bash variables
eval $(cat $script_path/../config/config.ini | $script_path/ini_to_bash.py)
# Check if we have sources
echogreen "Checking if Transvision sources are available..."
if ! $(ls $config/sources/*.txt &> /dev/null)
then
echored "CRITICAL ERROR: no sources available, aborting."
echored "Check the value for l10nwebservice in your config.ini and run setup.sh"
exit
fi
# Create all bash variables
source $script_path/bash_variables.sh
function updateLocale() {
# Update this locale's repository
# $1: Path to l10n repository
# $2: Locale code
# $3: Repository name
# Assign input variables to variables with meaningful names
l10n_path="$1"
locale="$2"
repository_name="$3"
cd $l10n_path/$locale
# Check if there are incoming changesets
hg incoming -r default --bundle incoming.hg 2>&1 >/dev/null
incoming_changesets=$?
if [ $incoming_changesets -eq 0 ]
then
# Update with incoming changesets and remove the bundle
echogreen "Updating $repository_name"
hg pull --update incoming.hg
rm incoming.hg
# Return 1: we need to create the cache for this locale
return 1
else
echogreen "There are no changes to pull for $repository_name"
# Return 0: no need to create the cache
return 0
fi
}
function updateStandardRepo() {
# Update specified repository. Parameters:
# $1: Channel name used in folders and TMX
# $2: Channel name used in variable names
function buildCache() {
# Build the cache
# $1: Locale code
echogreen "Create ${repo_name^^} cache for $repo_name/$1"
if [ "$1" = "en-US" ]
then
nice -20 $install/app/scripts/tmx_products.py ${!repo_source}/COMMUN/ ${!repo_source}/COMMUN/ en-US en-US $repo_name
else
nice -20 $install/app/scripts/tmx_products.py ${!repo_l10n}/$1/ ${!repo_source}/COMMUN/ $1 en-US $repo_name
fi
}
local repo_name="$1" # e.g. release, beta, aurora, central
local comm_repo="comm-$1" # e.g. comm-release, etc.
local mozilla_repo="mozilla-$1" # e.g. mozilla-release, etc.
local repo_source="${2}_source" # e.g. release_source, beta_source, aurora_source, trunk_source
local repo_l10n="${2}_l10n" # e.g. release_l10n, etc.
local locale_list="${2}_locales" # e.g. release_locales, etc.
updated_english=false
# Store md5 of the existing en-US cache before updating the repositories
cache_file="${root}TMX/en-US/cache_en-US_${repo_name}.php"
if [ -f $cache_file ]
then
existing_md5=($(md5sum $cache_file))
else
existing_md5=0
fi
if [ "$checkrepo" = true ]
then
# Update all source repositories
# ${!repo_source}: if repo_source contains 'release_source', this will
# return the value of the variable $release_source.
cd ${!repo_source}
echogreen "Update $comm_repo"
cd $comm_repo
hg pull -r default --update
echogreen "Update $mozilla_repo"
cd ../$mozilla_repo
hg pull -r default --update
fi
# Remove orphaned symbolic links
find -L ${!repo_source}/COMMUN/ -type l | while read -r file; do echored "$file is orphaned"; unlink $file; done
# Create TMX for en-US and check the updated md5
buildCache en-US
updated_md5=($(md5sum $cache_file))
if [ $existing_md5 != $updated_md5 ]
then
echo "English strings have been updated."
updated_english=true
fi
if [ "$all_locales" = true ]
then
for locale in $(cat ${!locale_list})
do
if [ -d ${!repo_l10n}/$locale ]
then
updated_locale=0
if [ "$checkrepo" = true ]
then
updateLocale ${!repo_l10n} $locale $repo_name/$locale
updated_locale=$?
fi
# Check if we have a cache file for this locale. If it's a brand
# new locale, we'll have the folder and no updates, but we
# still need to create the cache.
cache_file="${root}TMX/${locale}/cache_${locale}_${repo_name}.php"
if [ ! -f $cache_file ]
then
echored "Cache doesn't exist for ${repo_name}/${locale}"
updated_locale=1
else
php -l $cache_file 2>&1 1>/dev/null
if [ $? -ne 0 ]
then
# There are PHP errors, force the rebuild
echored "PHP errors in $cache_file. Forcing rebuild."
updated_locale=1
fi
fi
if [ "$forceTMX" = true -o "$updated_english" = true -o "$updated_locale" -eq 1 ]
then
buildCache $locale
fi
else
echored "Folder ${!repo_l10n}/$locale does not exist. Run setup.sh to fix the issue."
fi
done
else
if [ -d ${!repo_l10n}/$locale_code ]
then
updated_locale=0
if [ "$checkrepo" = true ]
then
updateLocale ${!repo_l10n} $locale_code $repo_name/$locale_code
updated_locale=$?
fi
cache_file="${root}TMX/${locale_code}/cache_${locale_code}_${repo_name}.php"
if [ ! -f $cache_file ]
then
echored "Cache doesn't exist for ${repo_name}/${locale_code}"
updated_locale=1
else
php -l $cache_file 2>&1 1>/dev/null
if [ $? -ne 0 ]
then
# There are PHP errors, force the rebuild
echored "PHP errors in $cache_file. Forcing rebuild."
updated_locale=1
fi
fi
if [ "$forceTMX" = true -o "$updated_english" = true -o "$updated_locale" -eq 1 ]
then
buildCache $locale_code
fi
else
echored "Folder ${!repo_l10n}/$locale_code does not exist."
fi
fi
}
function updateNoBranchRepo() {
if $checkrepo
then
# These repos exist only on trunk
cd $trunk_source/$1
echogreen "Update $1"
hg pull -r default --update
fi
}
function updateFromGitHub() {
if [ "$checkrepo" = true ]
then
cd $mozilla_org
echogreen "Update mozilla.org repository"
git pull origin master
fi
echogreen "Extract strings for mozilla.org"
cd $install
nice -20 $install/app/scripts/tmx_mozillaorg
}
function updateFirefoxiOS() {
if [ "$checkrepo" = true ]
then
cd $firefox_ios
echogreen "Update GitHub repository"
git pull
fi
echogreen "Extract strings for Firefox for iOS"
cd $install
nice -20 $install/app/scripts/tmx_xliff firefox_ios
}
# Update repos without branches first (their TMX is created in updateStandardRepo)
updateNoBranchRepo "chatzilla"
updateStandardRepo "release" "release"
updateStandardRepo "beta" "beta"
updateStandardRepo "aurora" "aurora"
updateStandardRepo "central" "trunk"
updateFromGitHub
updateFirefoxiOS
# Generate productization data
cd $install
echogreen "Extracting p12n data"
nice -20 python $install/app/scripts/p12n_extract.py
# Create a file to get the timestamp of the last string extraction for caching
echogreen "Creating extraction timestamp for cache system"
touch cache/lastdataupdate.txt
echogreen "Deleting all the old cached files"
rm -f cache/*.cache
echogreen "Deleting custom TMX files"
rm -f web/download/*.tmx
# Create a snapshot of all extracted data for download
if [ "$create_snapshot" = true ]
then
cd $root
echogreen "Creating a snapshot of extracted strings in web/data.tar.gz"
tar --exclude="*.tmx" -zcf datatemp.tar.gz TMX
echogreen "Snapshot created in the web root for download"
mv datatemp.tar.gz $install/web/data.tar.gz
fi