diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-03-27 22:33:04 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-03-27 22:33:04 +0100 |
| commit | 0e7af38d06339287d8ffe72bdd7af4d5e7e0001d (patch) | |
| tree | c5b1381d19836ddde725394dd0b9ed4dc7787a15 | |
| parent | ae398d3abace1aea33e7d2704f731be880d1931b (diff) | |
| download | cataract-0e7af38d06339287d8ffe72bdd7af4d5e7e0001d.tar.xz | |
Make 'cgg-dirgen' more flexible in option parsing
| -rwxr-xr-x | src/cgg-dirgen | 83 |
1 files changed, 67 insertions, 16 deletions
diff --git a/src/cgg-dirgen b/src/cgg-dirgen index 44dd256..a56289f 100755 --- a/src/cgg-dirgen +++ b/src/cgg-dirgen @@ -2,27 +2,81 @@ ## Cataract Gallery Generator - a simple static web photo gallery ## cgg-dirgen - Directory index.xml generator ## Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net> -## +## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 2 ## of the License, or any later version. -## +## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. -## +## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Optional arguments (must be in order, for now): -## -d Use preview pictures from the "preview" folder -## -o Do not include original image (removes link to original size) -## -t Generate thumbnails from the "thumbnails" folder +PREVIEW=no +PREVIEW_PATH="preview" +NO_FULLSIZE=no +EXT_THUMB=no +EXT_THUMB_PATH="thumbnails" + +print_help() +{ + echo "Usage: cgg-dirgen [OPTION...] > index.xml" + echo "" + echo "Options:" + echo " -?, --help Show help options" + echo " -d, --preview [dir] Use supplied preview (web page) images" + echo " - takes optional [dir] argument (default=\"preview\")" + echo " -o, --nofullsize Do not copy original (full size) image" + echo " - deprecated, use global <nofullsize /> tag" + echo " -t, --thumbnails [dir] Use supplied thumbnails" + echo " - takes optional [dir] argument (default=\"thumbnails\")" +} + + +# Gather arguments + +while [[ $1 = -* ]]; do + case "$1" in + -d|--preview) + PREVIEW=yes + shift + if [[ ! $1 == -* && ! "x$1" == "x" ]]; then + PREVIEW_PATH="$1" + shift + fi + ;; + -o|--nofullsize) + NO_FULLSIZE=yes + shift + ;; + -t|--thumbnails) + EXT_THUMB=yes + shift + if [[ ! $1 == -* && ! "x$1" == "x" ]]; then + EXT_THUMB_PATH="$1" + shift + fi + ;; + -h|--help|-\?) + print_help + exit + ;; + *) + echo "Error: Unknown option: $1" >&2 + exit 1 + ;; + esac +done + + +# Write index file cat << XML_HEADER_STOP <?xml version="1.0" encoding="utf-8"?> @@ -33,22 +87,19 @@ cat << XML_HEADER_STOP <description><![CDATA[Album description<br/> ]]></description> </general> - + <items> XML_HEADER_STOP for i in `find -L . -maxdepth 1 -type f -iname '*.jpg' -or -iname '*.jpeg' -or -iname '*.gif' -or -iname '*.png' | sort`; do INCL=""; - INCL2=""; - INCL3=""; - if [ "$1" = "-d" ]; then INCL=" preview=\"preview/`echo $i | cut -b 3-`\""; fi - if [ "$2" = "-o" ]; then INCL2=" <nofullsize />\n"; fi - if [ "$3" = "-t" ]; then INCL3=" thumbnail=\"thumbnails/`echo $i | cut -b 3-`\""; fi - echo -e " <item src=\"`echo $i | cut -b 3-`\"${INCL}${INCL3}>\n${INCL2} <title> </title>\n <title_description> </title_description>\n </item>\n"; + if [ ${PREVIEW} == "yes" ]; then INCL=" preview=\"${PREVIEW_PATH}/`echo $i | cut -b 3-`\""; fi + if [ ${EXT_THUMB} == "yes" ]; then INCL+=" thumbnail=\"${EXT_THUMB_PATH}/`echo $i | cut -b 3-`\""; fi + if [ ${NO_FULLSIZE} == "yes" ]; then INCL+=">\n <nofullsize /"; fi + echo -e " <item src=\"`echo $i | cut -b 3-`\"${INCL}>\n <title> </title>\n <title_description> </title_description>\n </item>\n"; done - + cat << XML_FOOTER_STOP </items> </gallery> XML_FOOTER_STOP - |
