sf2bz.sh
changeset 0 ae7b3fa753dc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sf2bz.sh	Thu Nov 16 08:30:26 2006 +0000
     1.3 @@ -0,0 +1,109 @@
     1.4 +#!/bin/sh
     1.5 +if [ $# -ne 2 ]; then
     1.6 +    echo "Usage: sf2bz <sf-project-export>.xml <bz-import>.xml" >&2
     1.7 +    exit 1
     1.8 +fi
     1.9 +input=$1
    1.10 +output=$2
    1.11 +topdir=/home/ali/wk/slashem/web.scripts
    1.12 +cd $topdir
    1.13 +cache_dir=$topdir/cache
    1.14 +tagsoup=tagsoup/tagsoup-1.0.1.jar
    1.15 +#tmpdir=`mktemp -d /tmp/XXXXXXXX` || exit 1
    1.16 +tmpdir=/tmp/sf2bz; rm -rf $tmpdir; mkdir $tmpdir
    1.17 +mkdir -p $cache_dir/sf/artifacts
    1.18 +# Sourceforge's export is pretty good, but misses a few things.
    1.19 +# Deal with one of these (descriptions for attached files) here.
    1.20 +echo '<?xml version="1.0"?>' > $tmpdir/descriptions.xml
    1.21 +echo '<artifacts xmlns:xi="http://www.w3.org/2001/XInclude">' \
    1.22 +  >> $tmpdir/descriptions.xml
    1.23 +./get_attached_files $input | cut -s "-d " -f 1,2 | sort -n | uniq | \
    1.24 +  while read atid aid; do
    1.25 +    mkdir -p $cache_dir/sf/artifacts/$atid
    1.26 +    if [ ! -r $cache_dir/sf/artifacts/$atid/$aid.html ]; then
    1.27 +	wget -q -O $cache_dir/sf/artifacts/$atid/$aid.html \
    1.28 +	  "http://sourceforge.net/tracker/index.php?func=detail&aid=$aid&group_id=9746&atid=$atid"
    1.29 +    fi
    1.30 +    mkdir -p $cache_dir/artifacts/$atid
    1.31 +    if [ ! -r $cache_dir/artifacts/$atid/$aid.xhtml ]; then
    1.32 +	java -jar $tagsoup $cache_dir/sf/artifacts/$atid/$aid.html \
    1.33 +	  > $cache_dir/artifacts/$atid/$aid.xhtml
    1.34 +    fi
    1.35 +    echo "<xi:include href=\"$cache_dir/artifacts/$atid/$aid.xhtml\"/>" >> $tmpdir/descriptions.xml
    1.36 +done
    1.37 +echo '</artifacts>' >> $tmpdir/descriptions.xml
    1.38 +xsltproc --xinclude attachment_descs.xsl $tmpdir/descriptions.xml \
    1.39 +  > $tmpdir/attachment-descriptions.xml
    1.40 +# Some details of attachments are included in the project export.
    1.41 +xsltproc attachment_details.xsl $input > $tmpdir/attachment-details.xml
    1.42 +# Then convert the attachments to XML (as required by bugzilla)
    1.43 +# pulling in the various bits of information we have gathered.
    1.44 +mkdir -p $cache_dir/sf/attachments $cache_dir/attachments
    1.45 +mkdir -p $tmpdir/jail
    1.46 +./get_attached_files artifacts.xml | while read atid aid file_id; do
    1.47 +    if [ ! -r $cache_dir/sf/attachments/$file_id ]; then
    1.48 +	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"
    1.49 +    fi
    1.50 +    if [ ! -r $cache_dir/attachments/$file_id.xml ]; then
    1.51 +	type=`file -bi $cache_dir/sf/attachments/$file_id | sed 's/;.*//'`
    1.52 +	case "$type" in
    1.53 +	    text/*)
    1.54 +		(cd $tmpdir/jail; patch --dry-run -s -f \
    1.55 +		  < $cache_dir/sf/attachments/$file_id > /dev/null 2>&1)
    1.56 +		if [ $? -lt 2 ]; then
    1.57 +		    pflag="-p"
    1.58 +		else
    1.59 +		    pflag=""
    1.60 +		fi
    1.61 +		;;
    1.62 +	    *)
    1.63 +	        pflag=""
    1.64 +		;;
    1.65 +	esac
    1.66 +	./xml_attached_file $pflag -i $file_id -t $type \
    1.67 +	  $cache_dir/sf/attachments/$file_id > $tmpdir/$file_id.1.xml
    1.68 +	xsltproc attachment_gather.xsl $tmpdir/$file_id.1.xml \
    1.69 +	  > $tmpdir/$file_id.2.xml
    1.70 +	xsltproc --xinclude attachment_post.xsl $tmpdir/$file_id.2.xml \
    1.71 +	  > $cache_dir/attachments/$file_id.xml
    1.72 +    fi
    1.73 +done
    1.74 +# We can't get hold of descriptions of deleted attachments, so we
    1.75 +# keep a copy of the file in case we need it. Ideally, we'd make sure
    1.76 +# that we only add descriptions, but that's for another day.
    1.77 +cp $tmpdir/attachment-descriptions.xml $topdir
    1.78 +xsltproc get_users.xsl $input > $tmpdir/raw_users.xml
    1.79 +echo '<artifacts xmlns:xi="http://www.w3.org/2001/XInclude">' \
    1.80 +  >> $tmpdir/users.1.xml
    1.81 +for file in $cache_dir/artifacts/*/*.xhtml; do
    1.82 +    echo "<xi:include href=\"$file\"/>" >> $tmpdir/users.1.xml
    1.83 +done
    1.84 +echo "<xi:include href=\"raw_users.xml\"/>" >> $tmpdir/users.1.xml
    1.85 +echo '</artifacts>' >> $tmpdir/users.1.xml
    1.86 +xsltproc --xinclude user_names.xsl $tmpdir/users.1.xml > $tmpdir/users.2.xml
    1.87 +mkdir -p $cache_dir/sf/users $cache_dir/users
    1.88 +echo '<sf_users xmlns:xi="http://www.w3.org/2001/XInclude">' \
    1.89 +  >> $tmpdir/users.3.xml
    1.90 +xsltproc unknown_users.xsl $tmpdir/users.2.xml | while read user; do
    1.91 +    case $user in
    1.92 +	*@users.sourceforge.net)
    1.93 +	    user_id=`echo $user | sed 's/@users.sourceforge.net$//'`
    1.94 +	    if [ ! -r $cache_dir/sf/users/$user_id.html ]; then
    1.95 +		wget -N -O $cache_dir/sf/users/$user_id.html \
    1.96 +		  "http://sourceforge.net/users/$user_id/"
    1.97 +	    fi
    1.98 +	    if [ ! -r $cache_dir/users/$user_id.xhtml ]; then
    1.99 +		java -jar $tagsoup $cache_dir/sf/users/$user_id.html \
   1.100 +		  > $cache_dir/users/$user_id.xhtml
   1.101 +	    fi
   1.102 +	    echo "<xi:include href=\"$cache_dir/users/$user_id.xhtml\"/>" \
   1.103 +	      >> $tmpdir/users.3.xml
   1.104 +    esac
   1.105 +done
   1.106 +echo "<xi:include href=\"users.2.xml\"/>" >> $tmpdir/users.3.xml
   1.107 +echo '</sf_users>' >> $tmpdir/users.3.xml
   1.108 +xsltproc --xinclude user_names.xsl $tmpdir/users.3.xml > users.xml
   1.109 +ln -s $cache_dir/attachments $tmpdir
   1.110 +xsltproc bugzilla.xsl $input > artifacts.tmp.xml
   1.111 +xsltproc --xinclude bugzilla_post.xsl artifacts.tmp.xml > $output
   1.112 +#rm -rf $tmpdir artifacts.tmp.xml