From 600bebceef75b28a2e0a4723e09df73c179d66a8 Mon Sep 17 00:00:00 2001 From: Jonathan Blake Date: Thu, 15 Feb 2018 15:45:50 +0000 Subject: [PATCH] added new script to list all book info from bookcodes.db adjusted the copy-* scripts to use the new script git-svn-id: https://projectaon.org/data/trunk@2695 f6f3e2d7-ff33-0410-aaf5-b4bee2cdac11 --- common/scripts/copy-ebooks.sh | 7 +++--- common/scripts/copy-svg.sh | 8 +++---- common/scripts/copy-xhtml.sh | 8 +++---- common/scripts/list-book-info.sh | 41 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 14 deletions(-) create mode 100755 common/scripts/list-book-info.sh diff --git a/common/scripts/copy-ebooks.sh b/common/scripts/copy-ebooks.sh index 1e76fc5..651c0c5 100755 --- a/common/scripts/copy-ebooks.sh +++ b/common/scripts/copy-ebooks.sh @@ -21,14 +21,13 @@ if [ "$AONDIR" -ef "$CURR_DIR" ]; then fi BASE_DIR="$AONDIR/common/epub" -book_db="$AONDIR/common/sqlite/bookcodes.db" for book in $@ do - row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';")) + row=( $($AONDIR/common/scripts/list-book-info.sh $book) ) - lang=${row[0]} - series=${row[1]} + lang=${row[1]} + series=${row[2]} source_dir="$BASE_DIR/$book" diff --git a/common/scripts/copy-svg.sh b/common/scripts/copy-svg.sh index a057dc4..532af7c 100755 --- a/common/scripts/copy-svg.sh +++ b/common/scripts/copy-svg.sh @@ -20,14 +20,12 @@ if [ "$AONDIR" -ef "$CURR_DIR" ]; then exit 1 fi -book_db="$AONDIR/common/sqlite/bookcodes.db" - for book in $@ do - row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';")) + row=( $($AONDIR/common/scripts/list-book-info.sh $book) ) - lang=${row[0]} - series=${row[1]} + lang=${row[1]} + series=${row[2]} source_dir="$AONDIR/$lang/svg/$series" output_dir="$CURR_DIR/$lang/svg/$series" diff --git a/common/scripts/copy-xhtml.sh b/common/scripts/copy-xhtml.sh index 0dde264..49ec516 100755 --- a/common/scripts/copy-xhtml.sh +++ b/common/scripts/copy-xhtml.sh @@ -20,14 +20,12 @@ if [ "$AONDIR" -ef "$CURR_DIR" ]; then exit 1 fi -book_db="$AONDIR/common/sqlite/bookcodes.db" - for book in $@ do - row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';")) + row=( $($AONDIR/common/scripts/list-book-info.sh $book) ) - lang=${row[0]} - series=${row[1]} + lang=${row[1]} + series=${row[2]} for format in xhtml xhtml-less-simple do diff --git a/common/scripts/list-book-info.sh b/common/scripts/list-book-info.sh new file mode 100755 index 0000000..4d9473c --- /dev/null +++ b/common/scripts/list-book-info.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# List all book into that match given bookcode(s). If the bookcode is omitted, +# outputs data for all books. +# +# Examples: +# list-book-info.sh lw gs +# +# list-book-info.sh + +if [ ! -d "$AONDIR" ]; then + >&2 echo "Please set the AONDIR environment variable" + exit 1 +fi + +book_db="$AONDIR/common/sqlite/bookcodes.db" + +if [ -z "$1" ]; then + sqlite3 -column -noheader "$book_db" <&2 echo "invalid book code" + exit + fi + + sqlite3 -column -noheader "$book_db" <