added new script to list all book info from bookcodes.db
[project-aon.git] / common / scripts / build-svg.sh
1 #!/bin/sh
2 #
3 # Build all the SVG files for Project Aon in a single run
4 #
5 # (c) 2011 Javier Fernandez-Sanguino <jfs@computer.org>
6 #
7 # This script is provided with the same license as that one
8 # used in the Aon Project
9
10 set -e
11
12 CURDIR=`pwd`
13 [ -z "$AONDIR" ] && AONDIR="../../"
14 [ -z "$LANGS" ]  && LANGS="en es"
15 LOGDIR="$CURDIR/logs/"
16 [ ! -e "$LOGDIR" ] && mkdir $LOGDIR
17
18 if [ -n "$1" ] ; then
19     BOOKS="$1"
20 else
21     BOOKS='*'
22 fi
23
24 generate_files() {
25     ls ${AONDIR}/${lang}/xml/$1.xml |
26     while read file ; do
27         if [ -r "$file" ]; then
28             xml=`basename $file | sed -e 's/\.xml//'`
29             # Look for the XML name in the metadata file
30             if grep -q ^$xml $METADATA; then
31                 echo -n "Generating SVG for $xml ('$lang' language)..."
32                 LOGFILE=$LOGDIR/$xml.svg.log
33                 cd $AONDIR 
34                 set +e 
35                 perl common/scripts/gbtosvg.pl --language=$lang $xml >$LOGFILE 2>&1
36                 if [ $? -ne 0 ]; then
37                     echo " ERROR building SVG file (review $LOGFILE)"
38                 fi
39                 echo "...done"
40             else 
41                 echo "WARN: Do not find metadata for $xml in $METADATA"
42             fi
43         else
44             echo "ERROR: Cannot generate SVG file for $xml (not readable)"
45         fi
46     done
47 }
48
49 for lang in $LANGS; do
50     METADATA=${AONDIR}/${lang}/.publisher/rules/simple
51     if [ -e "$METADATA" ] ; then
52         generate_files "$BOOKS"
53     else
54         echo "ERROR: Cannot find the publisher rules at $METADATA for $lang"
55     fi
56 done
57
58 exit 0