294 lines
9.0 KiB
Bash
294 lines
9.0 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# This program collects all upstream translations defined in
|
||
|
# configuration and merges them together.
|
||
|
|
||
|
# If you want to use po files for completing of translations, you can remove --no-fuzzy-matching.
|
||
|
# It will run much slower, but you could start with fuzzy matches.
|
||
|
|
||
|
WORK_DIR=$PWD
|
||
|
DEBUG=false
|
||
|
|
||
|
set -o errexit
|
||
|
shopt -s nullglob
|
||
|
|
||
|
source ${0%.sh}.conf
|
||
|
|
||
|
function rpmprep {
|
||
|
RPMDIR=$HOME/.var.rpmpatch$$
|
||
|
rm -rf BUILD $HOME/.var.rpmpatch$$
|
||
|
trap "rm -rf $RPMDIR" 0
|
||
|
mkdir -p BUILD $RPMDIR
|
||
|
cat >$RPMDIR/macros <<EOF
|
||
|
%_sourcedir $PWD
|
||
|
%_builddir $PWD/BUILD
|
||
|
EOF
|
||
|
|
||
|
cat >$RPMDIR/rpmrc <<EOF
|
||
|
$(grep macrofiles /usr/lib/rpm/rpmrc):$RPMDIR/macros
|
||
|
EOF
|
||
|
|
||
|
eval rpmbuild --nodeps --rcfile /usr/lib/rpm/rpmrc:$RPMDIR/rpmrc -bp ${*:-*.spec}
|
||
|
rm -rf $RPMDIR
|
||
|
trap - 0
|
||
|
}
|
||
|
|
||
|
ONLY_PACKAGE=
|
||
|
FULL_PROCESS=true
|
||
|
SNAPSHOT=$(LC_ALL=C LANG=C date +%Y%m%d)
|
||
|
case $1 in
|
||
|
--help )
|
||
|
# "only_new" is tricky: Processing new is the default. "only_new" has no match => only_new.
|
||
|
echo "Usage: $0 [ package | only_new ]"
|
||
|
exit
|
||
|
;;
|
||
|
# no arguments: process everything
|
||
|
"" )
|
||
|
;;
|
||
|
* )
|
||
|
ONLY_PACKAGE="$1"
|
||
|
FULL_PROCESS=false
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
rm -rf UPSTREAM
|
||
|
mkdir UPSTREAM
|
||
|
if ! test -d STAMPS ; then
|
||
|
mkdir PACKAGES UPDATE STAMPS
|
||
|
fi
|
||
|
|
||
|
if ! $FULL_PROCESS ; then
|
||
|
# more tarballs are available => use the latest one
|
||
|
# FIXME: Fix 20090213.10 < 20090213.9
|
||
|
# (but it should not happen for people who update and submit)
|
||
|
for ARCHIVE_ in translation-update-upstream-*.tar.bz2 ; do
|
||
|
ARCHIVE=$ARCHIVE_
|
||
|
done
|
||
|
if ! test -d UPDATE_OLD ; then
|
||
|
mkdir UPDATE_OLD
|
||
|
cd UPDATE_OLD
|
||
|
tar -jxf ../$ARCHIVE
|
||
|
# If it is not a full process, increment only release
|
||
|
# SNAPSHOT 20090213 -> 20090213.1, 20090213.1 -> 20090213.2
|
||
|
fi
|
||
|
SNAPSHOT=${ARCHIVE#translation-update-upstream-}
|
||
|
SNAPSHOT=${SNAPSHOT%.tar.bz2}
|
||
|
SNAPSHOT_PART1=${SNAPSHOT%.*}
|
||
|
SNAPSHOT_PART2=${SNAPSHOT#*.}
|
||
|
if test "$SNAPSHOT_PART1" = "$SNAPSHOT" ; then
|
||
|
SNAPSHOT_PART2=1
|
||
|
else
|
||
|
let SNAPSHOT_PART2++
|
||
|
fi
|
||
|
SNAPSHOT=$SNAPSHOT_PART1.$SNAPSHOT_PART2
|
||
|
cd ..
|
||
|
fi
|
||
|
|
||
|
for TLST in *.tlst ; do
|
||
|
exec <$WORK_DIR/$TLST
|
||
|
|
||
|
SERIAL=0
|
||
|
while read PACKAGE DOMAIN METHOD REPO DIR BRANCH ; do
|
||
|
|
||
|
# Continue for empty lines and comments
|
||
|
if test "${PACKAGE###}" != "$PACKAGE" ; then
|
||
|
continue
|
||
|
fi
|
||
|
if test -z "$PACKAGE" ; then
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
echo
|
||
|
echo "$(tput setf 3)Processing: package=$PACKAGE gettext-package=$DOMAIN method=$METHOD repository=$REPO directory=$DIR branch=${BRANCH:-HEAD}$(tput init)"
|
||
|
|
||
|
# NOTE: Force a limitation: tlst rules for one package must be placed on contiguous line sequence
|
||
|
if ! $DEBUG ; then
|
||
|
if test "$OLD_PACKAGE" != "$PACKAGE" ; then
|
||
|
if test -n "$RPMPKGDIR" ; then
|
||
|
rm -rf $RPMPKGDIR
|
||
|
fi
|
||
|
fi
|
||
|
OLD_PACKAGE=$PACKAGE
|
||
|
fi
|
||
|
|
||
|
if test -d $WORK_DIR/STAMPS/$PACKAGE/$DOMAIN/$METHOD/${REPO//[\/:.]/_}/$DIR/${BRANCH:-HEAD} ; then
|
||
|
echo " Already successfully processed. Skipping..."
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
if test -n "$ONLY_PACKAGE" ; then
|
||
|
if test "$ONLY_PACKAGE" != "$PACKAGE" ; then
|
||
|
if test -d $WORK_DIR/UPDATE_OLD/po/$DOMAIN ; then
|
||
|
if test -d $WORK_DIR/UPDATE/po/$DOMAIN ; then
|
||
|
echo "Should not happen. Internal error."
|
||
|
exit 255
|
||
|
else
|
||
|
echo " Not scheduled to process. Recycling old update..."
|
||
|
mkdir -p $WORK_DIR/UPDATE/po
|
||
|
mv $WORK_DIR/UPDATE_OLD/po/$DOMAIN $WORK_DIR/UPDATE/po/
|
||
|
fi
|
||
|
else
|
||
|
if test -d $WORK_DIR/UPDATE/po/$DOMAIN ; then
|
||
|
echo " Already recycled old update..."
|
||
|
else
|
||
|
echo " Not scheduled to process. No update available..."
|
||
|
fi
|
||
|
fi
|
||
|
mkdir -p $WORK_DIR/STAMPS/$PACKAGE/$DOMAIN/$METHOD/${REPO//[\/:.]/_}/$DIR/${BRANCH:-HEAD}
|
||
|
touch $WORK_DIR/STAMPS/$PACKAGE/.builddir_ok
|
||
|
continue
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
cd $WORK_DIR/PACKAGES
|
||
|
|
||
|
RPMPKGDIR=$(echo $WORK_DIR/PACKAGES/$OSC_REPOSITORY/$PACKAGE)
|
||
|
|
||
|
if ! test -f $WORK_DIR/STAMPS/$PACKAGE/.builddir_ok ; then
|
||
|
if ! test -d "$RPMPKGDIR" ; then
|
||
|
osc ${OSC_APIURL:+--apisrv=$OSC_APIURL} checkout --expand-link $OSC_REPOSITORY $PACKAGE
|
||
|
else
|
||
|
rm -rf "$RPMPKGDIR" $WORK_DIR/STAMPS/$PACKAGE
|
||
|
echo "Removed possibly incorrect temporary files from previous runs. Please re-run $0 now."
|
||
|
exit 1
|
||
|
fi
|
||
|
RPMPKGDIR=$(echo $WORK_DIR/PACKAGES/$OSC_REPOSITORY/$PACKAGE)
|
||
|
cd $RPMPKGDIR
|
||
|
rpmprep $PACKAGE.spec
|
||
|
else
|
||
|
# During processing, builddir may contain incomplete po files:
|
||
|
rm $WORK_DIR/STAMPS/$PACKAGE/.builddir_ok
|
||
|
fi
|
||
|
REPODIR=$DIR
|
||
|
RPMPODIR=$(echo $RPMPKGDIR/BUILD/*/${DIR#*/})
|
||
|
|
||
|
if test -f ${TLST%.tlst}.hook ; then
|
||
|
source ${TLST%.tlst}.hook
|
||
|
fi
|
||
|
|
||
|
cd $RPMPODIR
|
||
|
if ! intltool-update --gettext-package=$DOMAIN --pot ; then
|
||
|
if test -f $DOMAIN.pot ; then
|
||
|
echo >>$WORK_DIR/upstream-collect.log "package=$PACKAGE gettext-package=$DOMAIN method=$METHOD repository=$REPO directory=$DIR branch=${BRANCH:-HEAD}: intltool-update error, continuing with original $DOMAIN.pot"
|
||
|
else
|
||
|
echo >>$WORK_DIR/upstream-collect.log "package=$PACKAGE gettext-package=$DOMAIN method=$METHOD repository=$REPO directory=$DIR branch=${BRANCH:-HEAD}: intltool-update error, no way to update"
|
||
|
mkdir -p $WORK_DIR/STAMPS/$PACKAGE/$DOMAIN/$METHOD/${REPO//[\/:.]/_}/$REPODIR/${BRANCH:-HEAD}
|
||
|
continue
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
cd $WORK_DIR/UPSTREAM
|
||
|
let SERIAL++ || :
|
||
|
mkdir $SERIAL
|
||
|
cd $SERIAL
|
||
|
|
||
|
case "$METHOD" in
|
||
|
cvs )
|
||
|
cvs -z3 -d:pserver:anoncvs@$REPO co $REPODIR $BRANCH
|
||
|
cd $REPODIR
|
||
|
;;
|
||
|
svn )
|
||
|
if test -z "$BRANCH" ; then
|
||
|
svn co $REPO/${REPODIR%%/*}/trunk/${REPODIR#*/}
|
||
|
else
|
||
|
svn co $REPO/${REPODIR%%/*}/branches/$BRANCH/${REPODIR#*/}
|
||
|
fi
|
||
|
cd ${REPODIR##*/}
|
||
|
;;
|
||
|
tbz )
|
||
|
wget -N $REPO
|
||
|
tar -jxf ${REPO##*/}
|
||
|
cd $REPODIR
|
||
|
;;
|
||
|
tgz )
|
||
|
wget -N $REPO
|
||
|
tar -zxf ${REPO##*/}
|
||
|
cd $REPODIR
|
||
|
;;
|
||
|
* )
|
||
|
echo "$PACKAGE: Unknown update method $METHOD"
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
for PO in *.po ; do
|
||
|
# step 0: Merge new po file into old project. Removes unused (too new) translations.
|
||
|
if ! msgmerge --no-fuzzy-matching $PO $RPMPODIR/$DOMAIN.pot -o ${PO%.po}-backport.po ; then
|
||
|
echo >>$WORK_DIR/upstream-collect.log "package=$PACKAGE gettext-package=$DOMAIN method=$METHOD repository=$REPO directory=$DIR branch=${BRANCH:-HEAD} po=$PO: msgmerge error"
|
||
|
continue
|
||
|
fi
|
||
|
if test -f $RPMPODIR/$PO ; then
|
||
|
# step 1: Clean the po file to be safe.
|
||
|
if ! msgmerge --no-fuzzy-matching $RPMPODIR/$PO $RPMPODIR/$DOMAIN.pot -o $RPMPODIR/${PO%.po}-clean.po ; then
|
||
|
echo >>$WORK_DIR/upstream-collect.log "package=$PACKAGE gettext-package=$DOMAIN directory=$RPMPODIR po=$PO: package msgmerge error"
|
||
|
# Failed initial msgmerge is fatal. There is no way to update. Build may fail.
|
||
|
continue
|
||
|
fi
|
||
|
# Do the magic:
|
||
|
# step 2: Merge new po and previous updates (if any).
|
||
|
if test -f ${PO%.po}-updates.po ; then
|
||
|
msgcat --force-po --use-first ${PO%.po}-backport.po $RPMPODIR/${PO%.po}-updates.po -o ${PO%.po}-join.po
|
||
|
else
|
||
|
cp -a ${PO%.po}-backport.po ${PO%.po}-join.po
|
||
|
fi
|
||
|
# step 3: Join both translations, without --use-first string changes will disappear as fuzzy.
|
||
|
msgcat --force-po ${PO%.po}-join.po $RPMPODIR/${PO%.po}-clean.po -o ${PO%.po}-allfz.po
|
||
|
msgcat --use-first --force-po ${PO%.po}-join.po $RPMPODIR/${PO%.po}-clean.po -o ${PO%.po}-all.po
|
||
|
# step 4: Find string fixes (existed before, now different).
|
||
|
msgcat --force-po --unique ${PO%.po}-all.po ${PO%.po}-allfz.po -o ${PO%.po}-fixes.po
|
||
|
# step 5: Find newly translated strings (translation removal is not supported).
|
||
|
msgcat --force-po --unique $RPMPODIR/${PO%.po}-clean.po ${PO%.po}-all.po -o ${PO%.po}-additions.po
|
||
|
# step 6: Join both to collect all known fixes.
|
||
|
msgcat ${PO%.po}-fixes.po ${PO%.po}-additions.po -o $RPMPODIR/${PO%.po}-updatesraw.po
|
||
|
# Are there any updated? If no, game over.
|
||
|
if test -f $RPMPODIR/${PO%.po}-updatesraw.po ; then
|
||
|
# step 7: Ugly game to get the latest po file header.
|
||
|
sed -n '1,/^$/p' <${PO%.po}-backport.po >${PO%.po}-header.po
|
||
|
# step 8: And yet another ugly game to get rid commented out dust.
|
||
|
sed '/#~/d' <$RPMPODIR/${PO%.po}-updatesraw.po >$RPMPODIR/${PO%.po}-updates.po~
|
||
|
# step 9: Merge correct header to the updates file.
|
||
|
msgcat --no-location --use-first ${PO%.po}-header.po $RPMPODIR/${PO%.po}-updates.po~ -o $RPMPODIR/${PO%.po}-updates.po
|
||
|
fi
|
||
|
else
|
||
|
# step 1: Merge new po and previous updates (if any).
|
||
|
if test -f ${PO%.po}-updates.po ; then
|
||
|
msgcat --force-po --use-first ${PO%.po}-backport.po $RPMPODIR/${PO%.po}-updates.po -o ${PO%.po}-updates.po~
|
||
|
mv ${PO%.po}-updates.po~ ${PO%.po}-updates.po
|
||
|
else
|
||
|
cp -a ${PO%.po}-backport.po ${PO%.po}-updates.po
|
||
|
fi
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
cd $RPMPODIR
|
||
|
for POX in *-updates.po ; do
|
||
|
PO=${POX/-updates/}
|
||
|
mkdir -p $WORK_DIR/UPDATE/po/$DOMAIN
|
||
|
cp -a $POX $WORK_DIR/UPDATE/po/$DOMAIN/$PO
|
||
|
done
|
||
|
|
||
|
mkdir -p $WORK_DIR/STAMPS/$PACKAGE/$DOMAIN/$METHOD/${REPO//[\/:.]/_}/$DIR/${BRANCH:-HEAD}
|
||
|
touch $WORK_DIR/STAMPS/$PACKAGE/.builddir_ok
|
||
|
|
||
|
if ! $DEBUG ; then
|
||
|
rm -rf $WORK_DIR/UPSTREAM/$SERIAL
|
||
|
fi
|
||
|
|
||
|
done
|
||
|
|
||
|
done
|
||
|
|
||
|
if ! $DEBUG ; then
|
||
|
if test -n "$RPMPKGDIR" ; then
|
||
|
rm -rf $RPMPKGDIR
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
cd $WORK_DIR/UPDATE
|
||
|
tar -j -c -f $WORK_DIR/translation-update-upstream-$SNAPSHOT.tar.bz2 po
|
||
|
|
||
|
cd $WORK_DIR
|
||
|
if ! $DEBUG ; then
|
||
|
rm -rf UPSTREAM PACKAGES UPDATE UPDATE_OLD STAMPS
|
||
|
fi
|