Retrieving debconf translations from the bts

Downloading debconf translations from the bts and committing them to my packaging repository was always a task which pretty much annoyed me. Today I spent some time on writing a script which does this job for me. There is still much to improve - it is more like a prove of concept - but it works for me. With some love and probably a rewrite in Perl or Python it is a good candidate for devscripts probably.


#!/bin/bash

set -e
[ -d debian/po ] || exit 255
[ -r debian/control ] || exit 255

function get_ci_message() {
	echo "Updating debconf translation: ${2}"
	echo ""
	echo "Thanks: $(echo ${3} | sed 's, <[^<]*@[^>]*>.*,,')"
	echo "Closes: #${1}"
}

pkg_source=$(grep '^Source:' debian/control| awk '{print$2}')
for bug in $(bts select source:${pkg_source} tag:l10n tag:patch status:open); do
	#sanety check - stop if there is somethign left to commit.
	git status | grep -qE '^nothing.*to commit' || exit 255

	#cache bug files
	bts cache ${bug}

	# po files are gzip or bz2 compressed sometimes
	find ~/.devscripts_cache/bts/${bug} -type f -name '*.po.gz' -exec gunzip {} \;
	find ~/.devscripts_cache/bts/${bug} -type f -name '*.po.bz2' -exec bunzip2 {} \;

	#find the last .po file from the attachments
	pofile=$(find ~/.devscripts_cache/bts/${bug} -type f -name '*.po' |\
			sort | tail -1)
	if [ -z ${pofile} ]; then
		echo "Ignoring bug #${bug} - no po file found"
		continue
	fi

	# find the basename of the .po file, some translators use
	# packagename.xy.po, we try to work around that
	basename=$(basename ${pofile} | sed 's,.*\.\([a-z][a-z].po\),\1,')

	# sanety check if we have a filename like xy.po now
	if ! echo ${basename} | grep -qE '^[a-z][a-z].po$'; then
		echo "Ignoring bug #${bug} - ${basename} not a useful name"
		continue
	fi

	cp ${pofile} debian/po/${basename}

	#git add and commit it.
	git add debian/po/${basename}

	author=$(bts status ${bug} |\
		grep '^originator' |\
		awk -F '\t' '{print $2}')

	get_ci_message ${bug} ${basename} ${author} | git commit -F - --author="${author}"
	bts cleancache ${bug}
done

The git commit messages are prepared for usage with git-dch, which is my favourite way to write the Debian changelog.

Update: The script is using the originator information from the bug as author information for the commit now. Thanks to Santi for the comment! I could not test the changes yet, but I assume it will work well :)