Write to temprorary file and rename when done.

This avoids problems with demo server when somebody accesses page while
this file is being generated.
This commit is contained in:
Michal Čihař
2011-05-05 09:17:00 +02:00
parent ece21fbe9a
commit 5c38a10468

View File

@@ -13,20 +13,21 @@ THRESHOLD=50
# #
# Generated output file # Generated output file
# #
TMPOUTPUTFILE=libraries/language_stats.inc.php.tmp
OUTPUTFILE=libraries/language_stats.inc.php OUTPUTFILE=libraries/language_stats.inc.php
if [ ! -z "$1" ] ; then if [ ! -z "$1" ] ; then
THRESHOLD=$1 THRESHOLD=$1
fi fi
echo '<?php' > $OUTPUTFILE echo '<?php' > $TMPOUTPUTFILE
echo '/* Automatically generated file, do not edit! */' >> $OUTPUTFILE echo '/* Automatically generated file, do not edit! */' >> $TMPOUTPUTFILE
echo '/* Generated by scripts/remove-incomplete-mo */' >> $OUTPUTFILE echo '/* Generated by scripts/remove-incomplete-mo */' >> $TMPOUTPUTFILE
echo '' >> $OUTPUTFILE echo '' >> $TMPOUTPUTFILE
echo '$GLOBALS["language_stats"] = array (' >> $OUTPUTFILE echo '$GLOBALS["language_stats"] = array (' >> $TMPOUTPUTFILE
check() { check() {
OUTPUTFILE=$2 TMPOUTPUTFILE=$2
lang=`echo $1 | sed 's@po/\(.*\)\.po@\1@'` lang=`echo $1 | sed 's@po/\(.*\)\.po@\1@'`
STATS=`LC_ALL=C msgfmt --statistics -o /dev/null $1 2>&1` STATS=`LC_ALL=C msgfmt --statistics -o /dev/null $1 2>&1`
if echo $STATS | grep -q ' translated ' ; then if echo $STATS | grep -q ' translated ' ; then
@@ -45,7 +46,7 @@ check() {
UNTRANSLATED=0 UNTRANSLATED=0
fi fi
PERCENT=`expr 100 \* $TRANSLATED / \( $TRANSLATED + $FUZZY + $UNTRANSLATED \) || true` PERCENT=`expr 100 \* $TRANSLATED / \( $TRANSLATED + $FUZZY + $UNTRANSLATED \) || true`
echo " '$lang' => $PERCENT," >> $OUTPUTFILE echo " '$lang' => $PERCENT," >> $TMPOUTPUTFILE
if [ $PERCENT -lt $THRESHOLD ] ; then if [ $PERCENT -lt $THRESHOLD ] ; then
echo "Removing $lang, only $PERCENT%" echo "Removing $lang, only $PERCENT%"
@@ -54,8 +55,10 @@ check() {
} }
for x in po/*.po ; do for x in po/*.po ; do
check $x $OUTPUTFILE check $x $TMPOUTPUTFILE
done done
echo ');' >> $OUTPUTFILE echo ');' >> $TMPOUTPUTFILE
echo '?>' >> $OUTPUTFILE echo '?>' >> $TMPOUTPUTFILE
mv $TMPOUTPUTFILE $OUTPUTFILE