#! /bin/bash set -e # Split from calc-release-status by Cyril Brulebois, so that this # helper can be called once per package, making it possible to run in # parallel from the main script, instead of sequentially. log() { echo "$*" >&2 } error() { echo "E: $*" >&2 } # Remove comment lines and blank lines real_contents() { grep -Ev "^(#.*|)[[:space:]]*$" $1 } # Use rmadison to get the current version of a package in $SUITE # Check first if an exception has been defined get_version() { local package madison package=$1 if [ -r packages_exceptions ]; then version=$(sed -n -r "/^$package[[:space:]]/ s/^$package[[:space:]]+//p" packages_exceptions) if [ "$version" = "-" ]; then log "- INFO: skipping $package (excluded in packages_exceptions)" echo "$package (skipped)" >>packages.log return 1 elif [ "$version" ]; then log "- INFO: version exception for $package; using version '$version'" echo "$version" return 0 fi fi madison="$(rmadison -u debian -s $SUITE $package -a source)" if [ -z "$madison" ]; then error "error getting madison info for $package for '$SUITE'" exit 1 elif [ $(echo "$madison" | wc -l) -gt 1 ]; then error "got multiple lines from madison for $package" exit 1 fi echo "$madison" | cut -d"|" -f2 | sed "s/[[:space:]]//g;s/+nmu.*//g" } # Output number of translated/fuzzy/untranslated messages in a file po_status() { local pofile stat_info type stats pofile=$1 stat_info=$(msgfmt --stat -c -o /dev/null $pofile 2>&1 | \ grep -E "^[0-9]+ .* messages?") for type in translated fuzzy untranslated; do if $(echo $stat_info | grep -Eq "[0-9]+ $type"); then stats=${stats:+$stats }$(echo $stat_info | \ sed -r "s/(^|.*[^0-9])([0-9]+) $type.*/\2/") else stats=${stats:+$stats }0 fi done echo "$stats" } # Split a PO or POT file into the different sublevels # This function uses the same logic as l10n-sync and should be kept # in sync with that! split_levels() { local pofile lpofile i pofile=$1 [ -f $pofile ] || return 0 for i in $(seq 1 $NUMLEVELS); do lpofile=sublevel$i/$(basename $pofile) mkdir -p sublevel$i if [ $i -eq 1 ]; then # Select strings without a sublevel msggrep -X -E -v -e ":sl[1-$NUMLEVELS]:" $pofile \ >$lpofile.none 2>/dev/null # Select strings with sublevel 1 set msggrep -X -E -e ":sl1:" $pofile \ >$lpofile.sl1 2>/dev/null # Merge them msgcat $lpofile.none $lpofile.sl1 >$lpofile rm $lpofile.none $lpofile.sl1 else # Select strings with sublevel N set, but exclude any # strings that also have a sublevel smaller than N set # to avoid duplicates msggrep -X -E -e ":sl$i:" $pofile 2>/dev/null | \ msggrep -X -E -v -e ":sl[1-$(($i - 1))]:" \ >$lpofile 2>/dev/null fi done } # Real work starts here: p_dir="$1" package=$(basename $p_dir) if [ "$p_status" = "-" ]; then log "- INFO: skipping $package (excluded in packages_list)" echo "$package (skipped)" >>packages.log exit 0 elif ! version=$(get_version $package); then # packages_exceptions says to skip the package exit 0 fi log "- processing $p_dir ($version)" echo "$package ($version)" >>packages.log # Former assumption, no longer true as of 2017-11: tags with an epoch # are committed without it ("bar" instead of "foo:bar"): no_epoch_version=$(echo $version|sed 's/^[0-9]\+://') tweaked_epoch_version=$(echo $version|sed 's/:/%/') if [ ! -d $package/$version/po ]; then mkdir -p $package/$version pushd $package/$version >/dev/null if [ ! -f "../../$package.workaround" ]; then git clone $GITREPO/$package pushd $package >/dev/null # XXX: This is ugly. # First try with the direct version, fallback with no epoch, fallback with a tweaked epoch, then fail: git checkout -b tag $version || git checkout -b tag $no_epoch_version || git checkout -b tag $tweaked_epoch_version || { echo "Unable to find $version in $package; you might try:"; echo " touch $package.workaround"; echo " rm -rf $package/$version/$package"; exit 1; } popd >/dev/null else echo "Using apt-get source since $package.workaround exists" apt-get source $package=$version mv $package-*/ $package fi cp -r $package/debian/po . else pushd $package/$version >/dev/null fi # We need the templates file in case a translation is missing sed -i 's/charset=CHARSET/charset=UTF-8/g' po/templates.pot split_levels po/templates.pot for level in $(seq 1 $NUMLEVELS); do echo "template: $(po_status sublevel$level/templates.pot)" \ >../../stats/$package.$level done for pofile in po/*.po; do lang=$(basename $pofile .po) if ! grep -q "^$lang$" ../../stats/languages; then echo $lang >>../../stats/languages fi split_levels $pofile for level in $(seq 1 $NUMLEVELS); do if stats="$(po_status sublevel$level/$lang.po)"; then echo "$lang: $stats" >>../../stats/$package.$level fi done done popd >/dev/null