[sword-svn] r131 - trunk/modules/calvinscommentaries

lukeplant at www.crosswire.org lukeplant at www.crosswire.org
Tue Jan 8 11:01:16 MST 2008


Author: lukeplant
Date: 2008-01-08 11:01:16 -0700 (Tue, 08 Jan 2008)
New Revision: 131

Modified:
   trunk/modules/calvinscommentaries/bundle_and_install.sh
Log:
Refactored build script


Modified: trunk/modules/calvinscommentaries/bundle_and_install.sh
===================================================================
--- trunk/modules/calvinscommentaries/bundle_and_install.sh	2008-01-08 18:00:56 UTC (rev 130)
+++ trunk/modules/calvinscommentaries/bundle_and_install.sh	2008-01-08 18:01:16 UTC (rev 131)
@@ -1,8 +1,6 @@
 #!/bin/bash
 
 
-echo "Please edit this file first."
-exit 1
 ## Must modify these:
 SWORDTOOLS="$HOME/devel/sword-tools"
 CALCOMSOURCES="$HOME/christian/books/John Calvin/Commentaries/calcom_sources"
@@ -16,117 +14,142 @@
 
 ##############################################
 
+function check_requirements {
+	which csplit > /dev/null || { echo "Cannot find required tool 'csplit'.  Exiting."; exit 1;}
+	which replace > /dev/null || { echo "Cannot find required tool 'replace'.  Exiting."; exit 1;}
+}
 
-which csplit > /dev/null || { echo "Cannot find required tool 'csplit'.  Exiting."; exit 1;}
-which replace > /dev/null || { echo "Cannot find required tool 'replace'.  Exiting."; exit 1;}
+function setup_dirs {
+	mkdir -p $BUILDDIR
+	mkdir -p $OSIS2MODOUTPUT
+	mkdir -p $CONFDIR
+}
 
+function combine {
+	echo "Running combine_calcom.py..."
+	./combine_calcom.py "$CALCOMSOURCES"/calcom??.xml > "$BUILDDIR/calvinscommentaries.thml" || exit 1
+}
 
-mkdir -p $BUILDDIR
-mkdir -p $OSIS2MODOUTPUT
-mkdir -p $CONFDIR
+function convert_to_osis {
+	echo "Converting to OSIS..."
+	xsltproc --novalid  "$SWORDTOOLS/thml2osis/xslt/thml2osis.xslt" "$BUILDDIR/calvinscommentaries.thml" > "$BUILDDIR/calvinscommentaries.osis" || exit 1
+}
 
+function reversify {
+	cd "$BUILDDIR"
 
-echo "Running combine_calcom.py..."
-./combine_calcom.py "$CALCOMSOURCES"/calcom??.xml > "$BUILDDIR/calvinscommentaries.thml" || exit 1
+	##############################################################################
+	# Splitting
+	# We currently have to use genbookOsis2Commentary (since
+	# osis2mod doesn't accept format unless it is marked up like a Bible),
+	# genbookOsis2Commentary is a quick hack, and doesn't work well
+	# with big files, since it is DOM based.  So we split the file
+	# into lots of small ones, using markers inserted before.
+	# Then recombine again.  This is hacky, should go away once
+	# osis2mod is fixed.
 
-echo "Converting to OSIS..."
-xsltproc --novalid  "$SWORDTOOLS/thml2osis/xslt/thml2osis.xslt" "$BUILDDIR/calvinscommentaries.thml" > "$BUILDDIR/calvinscommentaries.osis" || exit 1
+	# Split
+	echo "Splitting..."
 
+	rm part*
 
-cd "$BUILDDIR"
+	COUNT=$(csplit -f 'part' -b '%03d' calvinscommentaries.osis "/combine_calcom.py START/" '{*}' | nl | tail -n 1 | cut -c 1-7 )
 
+	# $COUNT now contains the number of parts we split into
 
-##############################################################################
-# Splitting
-# We currently have to use genbookOsis2Commentary (since
-# osis2mod doesn't accept format unless it is marked up like a Bible),
-# genbookOsis2Commentary is a quick hack, and doesn't work well
-# with big files, since it is DOM based.  So we split the file
-# into lots of small ones, using markers inserted before.
-# Then recombine again.  This is hacky, should go away once
-# osis2mod is fixed.
+	FIRSTFILE="part000"
+	FIRSTFILEALT="firstpart"
+	LASTFILE="part`printf '%03d' $((COUNT-1))`"
+	mv $FIRSTFILE $FIRSTFILEALT
 
-# Split
-echo "Splitting..."
+	# $LASTFILE is special -- it will have trailing stuff
+	TMP=`mktemp`
+	replace '</osis>' '' '</osisText>' '' < $LASTFILE > $TMP || exit 1
+	mv $TMP $LASTFILE
 
-rm part*
 
-COUNT=$(csplit -f 'part' -b '%03d' calvinscommentaries.osis "/combine_calcom.py START/" '{*}' | nl | tail -n 1 | cut -c 1-7 )
+	# Fix individual files
+	for F in part*;
+	do
+	    # prepend and append some stuff
+	    TMP=`mktemp`
+	    echo '<?xml version="1.0" encoding="UTF-8"?>' > $TMP
+	    echo '<osis>' >> $TMP
+	    echo '<osisText>' >> $TMP
+	    cat $F >> $TMP
+	    echo '</osisText>' >> $TMP
+	    echo '</osis>' >> $TMP
+	    mv $TMP $F
 
-# $COUNT now contains the number of parts we split into
+	    echo "re-versifying $F ..."
+	    "$SWORDTOOLS/python/swordutils/osis/genbookOsis2Commentary.py" $F > "$F.versified" || exit 1
 
-FIRSTFILE="part000"
-FIRSTFILEALT="firstpart"
-LASTFILE="part`printf '%03d' $((COUNT-1))`"
-mv $FIRSTFILE $FIRSTFILEALT
+	    # Now strip stuff we added 
+	    TMP2=`mktemp`
+	    cat "$F.versified" | egrep -v 'xml version' | replace '<osis>' '' '<osisText>' '' '</osis>' '' '</osisText>' '' > $TMP2
+	    mv $TMP2 "$F.versified"
 
-# $LASTFILE is special -- it will have trailing stuff
-TMP=`mktemp`
-replace '</osis>' '' '</osisText>' '' < $LASTFILE > $TMP || exit 1
-mv $TMP $LASTFILE
+	done
 
+	# Now combine again
+	COMBINED="calvinscommentaries.versified.osis"
+	# Use this cleared up XML instead of the uncleaned stuff in $FIRSTFILEALT
+	echo '<?xml version="1.0" encoding="UTF-8"?>' > $COMBINED
+	echo '<osis xmlns="http://www.bibletechnologies.net/2003/OSIS/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd">' >> $COMBINED
+	echo '<osisText osisRefWork="bible" canonical="true" osisIDWork="calvincommentaries" xml:lang="en">' >> $COMBINED
 
-# Fix individual files
-for F in part*;
-do
-    # prepend and append some stuff
-    TMP=`mktemp`
-    echo '<?xml version="1.0" encoding="UTF-8"?>' > $TMP
-    echo '<osis>' >> $TMP
-    echo '<osisText>' >> $TMP
-    cat $F >> $TMP
-    echo '</osisText>' >> $TMP
-    echo '</osis>' >> $TMP
-    mv $TMP $F
+	for F in part*.versified;
+	do
+	    cat $F >> $COMBINED
+	done
 
-    echo "re-versifying $F ..."
-    "$SWORDTOOLS/python/swordutils/osis/genbookOsis2Commentary.py" $F > "$F.versified" || exit 1
+	echo '</osisText>' >> $COMBINED
+	echo '</osis>' >> $COMBINED
 
-    # Now strip stuff we added 
-    TMP2=`mktemp`
-    cat "$F.versified" | egrep -v 'xml version' | replace '<osis>' '' '<osisText>' '' '</osis>' '' '</osisText>' '' > $TMP2
-    mv $TMP2 "$F.versified"
+}
 
-done
+function convert_to_mod {
 
-# Now combine again
-COMBINED="calvinscommentaries.versified.osis"
-# Use this cleared up XML instead of the uncleaned stuff in $FIRSTFILEALT
-echo '<?xml version="1.0" encoding="UTF-8"?>' > $COMBINED
-echo '<osis xmlns="http://www.bibletechnologies.net/2003/OSIS/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd">' >> $COMBINED
-echo '<osisText osisRefWork="bible" canonical="true" osisIDWork="calvincommentaries" xml:lang="en">' >> $COMBINED
+	#######################################################################
 
-for F in part*.versified;
-do
-    cat $F >> $COMBINED
-done
+	# clean out old stuff
+	rm "$OSIS2MODOUTPUT/*"
 
-echo '</osisText>' >> $COMBINED
-echo '</osis>' >> $COMBINED
+	# Bug in osis2mod currently -- it removes all whitespace either side
+	# of a newline, so if a sentence has a newline in it, words end
+	# up merged together.  Fix that below:
 
-#######################################################################
+	tr '\n' ' ' < "$COMBINED" > "$COMBINED.2"
+	mv "$COMBINED.2" "$COMBINED"
 
-# clean out old stuff
-rm "$OSIS2MODOUTPUT/*"
+	# osis2mod
+	echo "Running osis2mod..."
+	osis2mod "$OSIS2MODOUTPUT" "$BUILDDIR/$COMBINED" 0 2 3 || exit 1
+}
 
-# xml2gbs 
-#xml2gbs -fO calvinscommentaries.osis CalvinsCommentaries
-#mv CalvinsCommentaries.{bdt,dat,idx} modules/comments/zcom/calvinscommentaries/
+function do_zip {
 
-# osis2mod
-echo "Running osis2mod..."
-osis2mod "$OSIS2MODOUTPUT" "$BUILDDIR/$COMBINED" 0 2 3 || exit 1
+    echo "Zipping..."
+    cp "$THISDIR/calvinscommentaries.conf" "$CONFDIR"
 
 
-echo "Zipping..."
-cp "$THISDIR/calvinscommentaries.conf" "$CONFDIR"
+    cd "$BUILDDIR"
 
+    zip -r CalvinsCommentaries.zip mods.d/ modules/
+}
 
-cd "$BUILDDIR"
+function do_install {
+    echo "Installing..."
 
-zip -r CalvinsCommentaries.zip mods.d/ modules/
+    unzip -o -d $HOME/.sword CalvinsCommentaries.zip
 
-echo "Installing..."
-## Install
-unzip -o -d $HOME/.sword CalvinsCommentaries.zip
+}
 
+check_requirements
+setup_dirs
+combine
+convert_to_osis
+reversify
+convert_to_mod
+do_zip
+do_install




More information about the sword-cvs mailing list