diff -r 000000000000 -r ae7b3fa753dc sf2bz.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sf2bz.sh Thu Nov 16 08:30:26 2006 +0000 @@ -0,0 +1,109 @@ +#!/bin/sh +if [ $# -ne 2 ]; then + echo "Usage: sf2bz .xml .xml" >&2 + exit 1 +fi +input=$1 +output=$2 +topdir=/home/ali/wk/slashem/web.scripts +cd $topdir +cache_dir=$topdir/cache +tagsoup=tagsoup/tagsoup-1.0.1.jar +#tmpdir=`mktemp -d /tmp/XXXXXXXX` || exit 1 +tmpdir=/tmp/sf2bz; rm -rf $tmpdir; mkdir $tmpdir +mkdir -p $cache_dir/sf/artifacts +# Sourceforge's export is pretty good, but misses a few things. +# Deal with one of these (descriptions for attached files) here. +echo '' > $tmpdir/descriptions.xml +echo '' \ + >> $tmpdir/descriptions.xml +./get_attached_files $input | cut -s "-d " -f 1,2 | sort -n | uniq | \ + while read atid aid; do + mkdir -p $cache_dir/sf/artifacts/$atid + if [ ! -r $cache_dir/sf/artifacts/$atid/$aid.html ]; then + wget -q -O $cache_dir/sf/artifacts/$atid/$aid.html \ + "http://sourceforge.net/tracker/index.php?func=detail&aid=$aid&group_id=9746&atid=$atid" + fi + mkdir -p $cache_dir/artifacts/$atid + if [ ! -r $cache_dir/artifacts/$atid/$aid.xhtml ]; then + java -jar $tagsoup $cache_dir/sf/artifacts/$atid/$aid.html \ + > $cache_dir/artifacts/$atid/$aid.xhtml + fi + echo "" >> $tmpdir/descriptions.xml +done +echo '' >> $tmpdir/descriptions.xml +xsltproc --xinclude attachment_descs.xsl $tmpdir/descriptions.xml \ + > $tmpdir/attachment-descriptions.xml +# Some details of attachments are included in the project export. +xsltproc attachment_details.xsl $input > $tmpdir/attachment-details.xml +# Then convert the attachments to XML (as required by bugzilla) +# pulling in the various bits of information we have gathered. +mkdir -p $cache_dir/sf/attachments $cache_dir/attachments +mkdir -p $tmpdir/jail +./get_attached_files artifacts.xml | while read atid aid file_id; do + if [ ! -r $cache_dir/sf/attachments/$file_id ]; then + wget -N -O $cache_dir/sf/attachments/$file_id "http://sourceforge.net/tracker/download.php?group_id=9746&atid=$atid&file_id=$file_id&aid=$aid" + fi + if [ ! -r $cache_dir/attachments/$file_id.xml ]; then + type=`file -bi $cache_dir/sf/attachments/$file_id | sed 's/;.*//'` + case "$type" in + text/*) + (cd $tmpdir/jail; patch --dry-run -s -f \ + < $cache_dir/sf/attachments/$file_id > /dev/null 2>&1) + if [ $? -lt 2 ]; then + pflag="-p" + else + pflag="" + fi + ;; + *) + pflag="" + ;; + esac + ./xml_attached_file $pflag -i $file_id -t $type \ + $cache_dir/sf/attachments/$file_id > $tmpdir/$file_id.1.xml + xsltproc attachment_gather.xsl $tmpdir/$file_id.1.xml \ + > $tmpdir/$file_id.2.xml + xsltproc --xinclude attachment_post.xsl $tmpdir/$file_id.2.xml \ + > $cache_dir/attachments/$file_id.xml + fi +done +# We can't get hold of descriptions of deleted attachments, so we +# keep a copy of the file in case we need it. Ideally, we'd make sure +# that we only add descriptions, but that's for another day. +cp $tmpdir/attachment-descriptions.xml $topdir +xsltproc get_users.xsl $input > $tmpdir/raw_users.xml +echo '' \ + >> $tmpdir/users.1.xml +for file in $cache_dir/artifacts/*/*.xhtml; do + echo "" >> $tmpdir/users.1.xml +done +echo "" >> $tmpdir/users.1.xml +echo '' >> $tmpdir/users.1.xml +xsltproc --xinclude user_names.xsl $tmpdir/users.1.xml > $tmpdir/users.2.xml +mkdir -p $cache_dir/sf/users $cache_dir/users +echo '' \ + >> $tmpdir/users.3.xml +xsltproc unknown_users.xsl $tmpdir/users.2.xml | while read user; do + case $user in + *@users.sourceforge.net) + user_id=`echo $user | sed 's/@users.sourceforge.net$//'` + if [ ! -r $cache_dir/sf/users/$user_id.html ]; then + wget -N -O $cache_dir/sf/users/$user_id.html \ + "http://sourceforge.net/users/$user_id/" + fi + if [ ! -r $cache_dir/users/$user_id.xhtml ]; then + java -jar $tagsoup $cache_dir/sf/users/$user_id.html \ + > $cache_dir/users/$user_id.xhtml + fi + echo "" \ + >> $tmpdir/users.3.xml + esac +done +echo "" >> $tmpdir/users.3.xml +echo '' >> $tmpdir/users.3.xml +xsltproc --xinclude user_names.xsl $tmpdir/users.3.xml > users.xml +ln -s $cache_dir/attachments $tmpdir +xsltproc bugzilla.xsl $input > artifacts.tmp.xml +xsltproc --xinclude bugzilla_post.xsl artifacts.tmp.xml > $output +#rm -rf $tmpdir artifacts.tmp.xml