#!/bin/bash # Copyright (c) 2004-2006 by Dennis Stampfer # Copyright (c) 2006 by Frans Pop # Licensed under the GNU General Public License # # Fetches sources for the installer packages and generates # some translation-related statistics. # # As I am not a good bash-programmer, please imagine someone else # to be the author when reading this source! :) # # Files: # o packages-list # Names of the packages to download # o languages # what languages to be checked? # o paths # where are the po-files located in this package? # (sometimes more than one, like shadow) # # o packages (folder) # The packages get downloaded into $TEMPFILE, cleaned up # and moved to packages/. # # SCRIPTNAME="Installation Guide" ROOT="/srv/d-i_manual.daily" WD="$ROOT/bin/po_stats" TEMP_DIR="$WD/temp" TARGET_DIR="$ROOT/build/po_stats" PO_DIR="$ROOT/manual/po" # We want the manual files group writable umask 0002 cd $WD if [ -f manual.lock ]; then echo "A lockfile manual.lock exists. Exiting..."; exit fi touch manual.lock mkdir -p $TARGET_DIR export GETTEXT="/usr/bin" APT_OPT="" export LANG_NAMES="../langlist" TEMPFILE="/tmp/.gen-stats-temp-$RANDOM" LANG=C #some functions: get_stat () { # how many strings are translated/untranslated/fuzzy $GETTEXT/msgfmt --statistics $1 2>&1 | tr "," "\n" | \ sed -nr "/ $2/ {s/ *([0-9]+) $2.*/\1/; p}" } translator () { # who is last-translator? sed -rn "/Last-Translator: / {s/[^:]*: +(.*)\\\n.*/\1/; p}" $1 } print_shit () { # print standard-text echo -n "Files fetched and report generated on: " >> $TARGET_DIR/$lang.txt date -u >> $TARGET_DIR/$lang.txt } ######################################################################### echo -n "$SCRIPTNAME script start (by user $USER, logname $LOGNAME): " date echo "Working directory is $WD" rm -rf $TARGET_DIR/* rm -rf $TEMP_DIR mkdir $TEMP_DIR #check how many strings at all echo "Counting strings..." TOTALU=0 LANG=C POT_LIST=`ls -1 $PO_DIR/pot/` for file in $POT_LIST; do U=`get_stat $PO_DIR/pot/$file untranslated` echo "$file has $U untranslated. ($TOTALU)" TOTALU=`expr $TOTALU + $U || echo 0` if [ "$TOTALU" = "0" -o -z "$TOTALU" ]; then echo "Error while counting untranslated strings in templates." fi done echo "Total strings: $TOTALU=100%" echo #now check: RANK="" #following 3 variables for generating the graph. they include all #strings of all languages of all packages GR_TRANSLATED=0 GR_FUZZY=0 GR_UNTRANSLATED=0 rm -f $TEMP_DIR/rank.txt rm -rf $TEMPFILE for lang in `ls -1 $PO_DIR | grep -v "pot"`; do #run for every language [ -d "$PO_DIR/$lang" ] || continue NAME=$(grep "^$lang[[:space:]]" "$LANG_NAMES" | cut -f 7) if [ "$NAME" ]; then echo "$NAME ($lang)..." else echo "Skipping '$lang': not defined in '$LANG_NAMES'" continue fi cat < $TARGET_DIR/$lang.txt Statistics of Installation Guide translation for $NAME See: http://d-i.alioth.debian.org/manual/ Outdated: EOF MISSING="" #for total strings of a language TU=0 TT=0 TF=0 for f in $POT_LIST; do #for every POT file file=`echo $f | sed "s/t$//g"`; fileprt="$file" file="$PO_DIR/$lang/$file"; echo " $file..." if [ -e $file ]; then #if the file does exist LASTT=`translator $file` #strings of this package: U=`get_stat $file untranslated` F=`get_stat $file fuzzy` T=`get_stat $file translated` test -z "$U" && U=0 test -z "$F" && F=0 test -z "$T" && T=0 #get infos: TU=`expr $TU + $U` TT=`expr $TT + $T` TF=`expr $TF + $F` #for the graph: GR_TRANSLATED=`expr $GR_TRANSLATED + $TT` GR_UNTRANSLATED=`expr $GR_UNTRANSLATED + $TU` GR_FUZZY=`expr $GR_FUZZY + $TF` #don't show completely translated files: if [ "$U" = "0" -a "$F" = "0" ]; then OK=" $fileprt: $T"t" [$LASTT]\n$OK" echo -n else echo " $fileprt: $T"t"$F"f"$U"u" [$LASTT]" >> $TARGET_DIR/$lang.txt fi else #=if not existing MISSING_U=`get_stat $PO_DIR/pot/$f untranslated` test -z $MISSING_U && MISSING_U=0 MISSING="$MISSING $fileprt: "$MISSING_U"u\n" #echo " !!$path/$lang.po" fi done # POT files echo -e "\nTranslated:" >> $TARGET_DIR/$lang.txt echo -e "$OK" >> $TARGET_DIR/$lang.txt OK="" echo -e "Missing files:\n$MISSING\n" >> $TARGET_DIR/$lang.txt P=`echo "$TT * 100 / $TOTALU" | bc` STR=`echo "$TT + $TU + $TF" | bc` echo -e "Global statistics: "$TT"t"$TF"f"$TU"u ($P%) (total strings: $TOTALU=100%)\n(From all $lang.po files)" >> $TARGET_DIR/$lang.txt if [ "$STR" -gt "$TOTALU" ]; then echo -e " You have more strings translated/fuzzy/untranslated than in\n the pot-templates. Please check!" >> $TARGET_DIR/$lang.txt fi echo >> $TARGET_DIR/$lang.txt print_shit LEAD="000"; if [ ${#LEAD} -gt ${#P} ]; then P="${LEAD:0:${#LEAD}-${#P}}$P" else P="$P" fi echo -e "$P%\t $lang" >> $TEMP_DIR/rank.txt echo "$lang done. ($P%)" echo done # languages #generate ranking: $WD/sort-ranktxt < $TEMP_DIR/rank.txt > ../index.podata #move files to their destination cp HEADER.txt $TARGET_DIR/ #cleanup echo "Cleanup..." rm -rf $TEMP_DIR rm -rf $TEMPFILE rm -rf messages messages.mo echo -n "Script end: " date rm $WD/manual.lock