Added placeholder script

Fri, 26 Sep 2008 22:02:19 +0000

author
andy
date
Fri, 26 Sep 2008 22:02:19 +0000
changeset 1
57ac3ee72b07
parent 0
2caa767ad76c
child 2
03c561ae154e

Added placeholder script

emin file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emin	Fri Sep 26 22:02:19 2008 +0000
     1.3 @@ -0,0 +1,279 @@
     1.4 +#! /usr/bin/env python
     1.5 +# -*- python -*-
     1.6 +
     1.7 +## 
     1.8 +## emin - a static web gallery builder
     1.9 +## version 0.1
    1.10 +## by Andy Buckley
    1.11 +## http://www.insectnation.org
    1.12 +## 
    1.13 +## TODO
    1.14 +##  * Use thickbox
    1.15 +##  * Specify Lightbox base path
    1.16 +##  * Split into blocks of N
    1.17 +##  * Rename images before starting
    1.18 +
    1.19 +
    1.20 +## Num per page / all on one page
    1.21 +## Zip file
    1.22 +## Num cols (or no cols)
    1.23 +## Title
    1.24 +## Description
    1.25 +## Thumb height (100)
    1.26 +## Image size
    1.27 +## File suffix
    1.28 +## JS
    1.29 +## Generate thumbs (+ force)
    1.30 +## Header & footer files; whole page / snippet; Cheetah format page template
    1.31 +
    1.32 +
    1.33 +
    1.34 +# Image info functions
    1.35 +def getWidth(filename):
    1.36 +    dims=`identify "$1" | cut -d" " -f3 | cut -d"=" -f1`
    1.37 +    xdim=`echo $dims | cut -dx -f1`
    1.38 +    echo $xdim
    1.39 +
    1.40 +def getHeight(filename):
    1.41 +    dims=`identify "$1" | cut -d" " -f3 | cut -d"=" -f1`
    1.42 +    ydim=`echo $dims | cut -dx -f2`
    1.43 +    echo $ydim
    1.44 +
    1.45 +def safeencode(string):
    1.46 +    #ZIPFILE=$( echo $TITLE | sed -e s/"\ "/"-"/g -e s/","//g -e s/"\/"//g -e s/"\."//g -e s/"'"//g )
    1.47 +    return string
    1.48 +
    1.49 +ZIPFILE = "photo-album.zip"
    1.50 +if opts.TITLE is not None or len(opts.TITLE) > 0:
    1.51 +    ZIPFILE = safeencode(opts.TITLE)
    1.52 +
    1.53 +
    1.54 +
    1.55 +
    1.56 +if [[ -n $DEBUG ]]; then 
    1.57 +    echo "Title: $TITLE"
    1.58 +    echo "Write header: $writeHeader $headerFile"
    1.59 +    echo "Write footer: $writeFooter $footerFile"
    1.60 +    echo "Thumb height: $THUMBMAXHEIGHT"
    1.61 +    echo "Non-option args: $nonoptargs"
    1.62 +    echo
    1.63 +fi;
    1.64 +
    1.65 +
    1.66 +if [[ $HELP_MESSAGE == "true" ]]; then
    1.67 +    echo "Andy's static web gallery builder"
    1.68 +    echo "Usage: $0 [-d|-F|-H|-h|-i|-I|-n|-r|-R|-t|-T|-v|-y|-z|-Z]"
    1.69 +    echo " -d DIR       build gallery in given directory" 
    1.70 +    echo " -F | -H FILE specify footer and header includes"
    1.71 +    echo " -h           displays this oh-so-helpful message"
    1.72 +    echo " -i | -I      enable or disable header and footer-writing (default is enabled)"
    1.73 +    echo " -l | -L      enable or disable Lightbox2 effects (default is enabled)"
    1.74 +    echo " -n FILE      specifies the index page filename"
    1.75 +    echo " -r | -R      enable or disable thumbnail re-building"
    1.76 +    echo " -t TITLE     specifies the gallery title"
    1.77 +    echo " -T TAG       specifies the title tag (default is <h1>)"
    1.78 +    echo " -v           enables verbose output while building the gallery"
    1.79 +    echo " -y HEIGHT    specifies the max height of the generated thumbnails"
    1.80 +    echo " -z | -Z      enable or disable the zip archive"
    1.81 +    exit 0
    1.82 +fi
    1.83 +
    1.84 +
    1.85 +# Go to the gallery directory and test if it's writeable
    1.86 +if [[ -d $galleryDir && -w $galleryDir ]]; then
    1.87 +    cd $galleryDir
    1.88 +else
    1.89 +    echo "Directory $galleryDir either doesn't exist or is not writeable" 1>&2
    1.90 +    exit 1
    1.91 +fi
    1.92 +
    1.93 +# Rename images
    1.94 +dirname=$(basename `pwd`)
    1.95 +let n=1
    1.96 +for i in *.jpg *.jpeg *.JPG; do
    1.97 +    num=$n
    1.98 +    if [[ $n -lt 10 ]]; then num="0$num"; fi
    1.99 +    if [[ $n -lt 100 ]]; then num="0$num"; fi
   1.100 +    newname=$( echo "$dirname-$num.jpg" | sed -e s:'/':'-':g -e s:'--*':'-':g )
   1.101 +    if [[ "$i" != "$newname" ]]; then mv $i $newname; fi
   1.102 +    let n++
   1.103 +done
   1.104 +
   1.105 +# Build the list of pictures to display
   1.106 +pics=$( find . -maxdepth 1 -type f -name "*.jpg" | sort );
   1.107 +
   1.108 +
   1.109 +# Make thumbnails if needed
   1.110 +mkdir -p ./thumbs
   1.111 +for pic in $pics; do
   1.112 +    thumbpic="thumbs/${pic}.jpg"
   1.113 +    if [[ $regenThumbs == "true" || ! -e $thumbpic || ( `getHeight $thumbpic` -lt $THUMBMAXHEIGHT && `getHeight $pic` -ge $THUMBMAXHEIGHT ) ]]; then
   1.114 +        if [[ $VERBOSE == "true" ]]; then echo "Making new thumbnail for $pic (max height ${THUMBMAXHEIGHT})"; fi
   1.115 +        convert $pic $thumbpic
   1.116 +        mogrify -resize "x${THUMBMAXHEIGHT}>" $thumbpic
   1.117 +    fi
   1.118 +done
   1.119 +
   1.120 +
   1.121 +# Make a zipped tar archive
   1.122 +rm -f *.zip
   1.123 +if [[ $writeZipfile == "true" ]]; then
   1.124 +    if [[ $VERBOSE == "true" ]]; then echo "Making zipped picture archive"; fi
   1.125 +    zip $ZIPFILE $pics &> /dev/null
   1.126 +fi
   1.127 +
   1.128 +
   1.129 +# Count the pictures
   1.130 +let npics=0;
   1.131 +for pic in $pics; do
   1.132 +    #echo $pic
   1.133 +    let npics++
   1.134 +done;
   1.135 +if [[ $VERBOSE == "true" ]]; then echo "$npics pictures"; fi
   1.136 +if [[ $npics -eq 0 ]]; then
   1.137 +    echo "No pictures from which to build a gallery..."
   1.138 +    exit 2
   1.139 +fi
   1.140 +
   1.141 +# Calculate how many pages
   1.142 +let npages=$npics/$CHUNK_SIZE
   1.143 +let remainder=$npics-$npages*$CHUNK_SIZE
   1.144 +test $remainder -eq 0 || let npages++
   1.145 +
   1.146 +# Make each index page
   1.147 +for page in `seq 1 $npages`; do
   1.148 +    pagefile=$INDEXFILE
   1.149 +    if [[ $page -ne 1 ]]; then pagefile=index${page}.html; fi
   1.150 +    
   1.151 +    # Initialise empty index file
   1.152 +    if [[ $VERBOSE == "true" ]]; then echo "Writing to index file $pagefile"; fi
   1.153 +    > $pagefile
   1.154 +    
   1.155 +    # Write the HTML header
   1.156 +    if [[ $writeHeader == "true" ]]; then
   1.157 +        if [[ -z $headerFile ]]; then
   1.158 +            if [[ $VERBOSE == "true" ]]; then echo "Writing default header"; fi
   1.159 +            echo "<html>" >> $pagefile
   1.160 +            echo "<head>" >> $pagefile
   1.161 +            echo "  <title>${TITLE}</title>" >> $pagefile
   1.162 +            echo "  <style>" >> $pagefile
   1.163 +            echo "    img { border:0; margin:5px; }" >> $pagefile
   1.164 +            echo "    body { padding:1em; background:white; font-family:sans-serif; }" >> $pagefile
   1.165 +            echo "    h1 { font-family:sans-serif; }" >> $pagefile
   1.166 +            echo "  </style>" >> $pagefile
   1.167 +            ## Lightbox2
   1.168 +            if [[ $lightbox == "true" ]]; then
   1.169 +                echo '  <script type="text/javascript" src="/lightbox/js/prototype.js"></script>' >> $pagefile
   1.170 +                echo '  <script type="text/javascript" src="/lightbox/js/scriptaculous.js?load=effects"></script>' >> $pagefile
   1.171 +                echo '  <script type="text/javascript" src="/lightbox/js/lightbox.js"></script>' >> $pagefile
   1.172 +                echo '  <link rel="stylesheet" href="/lightbox/css/lightbox.css" type="text/css" media="screen" />' >> $pagefile
   1.173 +            fi
   1.174 +            echo "</head>" >> $pagefile
   1.175 +            echo "<body>" >> $pagefile
   1.176 +        else
   1.177 +            if [[ $VERBOSE == "true" ]]; then echo "Writing header from $headerFile"; fi
   1.178 +            cat $headerFile >> $pagefile
   1.179 +        fi
   1.180 +    fi
   1.181 +    
   1.182 +    # Write the title
   1.183 +    pagetitle="$TITLE"
   1.184 +    if [[ $page -ne 1 ]]; then pagetitle="$pagetitle (page $page)"; fi
   1.185 +    if [[ $VERBOSE == "true" ]]; then echo "Writing title as <${TITLETAG}>${pagetitle}</${TITLETAG}>"; fi
   1.186 +    echo "<${TITLETAG}>${pagetitle}</${TITLETAG}>" >> $pagefile
   1.187 +        
   1.188 +    # Write the linked page list
   1.189 +    let prevpage=$page-1
   1.190 +    let nextpage=$page+1
   1.191 +    echo "<div class=\"pagelinks\">Pages: " >> $pagefile
   1.192 +    if [[ $prevpage -gt 0 ]]; then 
   1.193 +        echo "[<a href=\"index${prevpage}.html\">prev</a>] " >> $pagefile
   1.194 +    else
   1.195 +        echo "[prev] " >> $pagefile
   1.196 +    fi
   1.197 +    for pagelink in `seq 1 $npages`; do
   1.198 +        if [[ $pagelink -ne $page ]]; then
   1.199 +            pagelinkfile=$INDEXFILE
   1.200 +            if [[ $page -ne 1 ]]; then pagefile=index${page}.html; fi
   1.201 +            echo "[<a href=\"$pagelinkfile\">$pagelink</a>] " >> $pagefile
   1.202 +        else
   1.203 +            echo "[$pagelink]" >> $pagefile
   1.204 +        fi
   1.205 +    done
   1.206 +    if [[ $nextpage -lt $npages ]]; then 
   1.207 +        echo "[<a href=\"index${nextpage}.html\">next</a>] " >> $pagefile
   1.208 +    else
   1.209 +        echo "[next] " >> $pagefile
   1.210 +    fi
   1.211 +    echo "</div>" >> $pagefile
   1.212 +    
   1.213 +    # Make thumbnails if needed and write the image HTML
   1.214 +    echo "<p>" >> $pagefile
   1.215 +    let npic=0
   1.216 +    for pic in $pics; do
   1.217 +        let npic++
   1.218 +        thumbpic="thumbs/${pic}.jpg"
   1.219 +        
   1.220 +        let lowbound=($page-1)*$CHUNK_SIZE
   1.221 +        let highbound=$page*$CHUNK_SIZE
   1.222 +        if [[ $lightbox == "true" ]]; then
   1.223 +            echo -n "<a href=\"$pic\" rel=\"lightbox[set]\">" >> $pagefile
   1.224 +            if [[ $npic -gt $lowbound && $npic -lt $highbound ]]; then 
   1.225 +                echo -n "<img alt=\"$thumbpic\" src=\"$thumbpic\" style=\"border:0;\" width=\"`getWidth $thumbpic`\" height=\"`getHeight $thumbpic`\"/>" >> $pagefile
   1.226 +            fi
   1.227 +            echo "</a>" >> $pagefile
   1.228 +        else
   1.229 +            if [[ $npic -gt $lowbound && $npic -lt $highbound ]]; then 
   1.230 +                echo -n "<a href=\"$pic\">" >> $pagefile
   1.231 +                echo -n "<img alt=\"$thumbpic\" src=\"$thumbpic\" style=\"border:0;\" width=\"`getWidth $thumbpic`\" height=\"`getHeight $thumbpic`\"/>" >> $pagefile
   1.232 +                echo "</a>" >> $pagefile
   1.233 +            fi
   1.234 +        fi
   1.235 +    done
   1.236 +    echo "</p>" >> $pagefile
   1.237 +
   1.238 +    # Write the linked page list
   1.239 +    let prevpage=$page-1
   1.240 +    let nextpage=$page+1
   1.241 +    echo "<div class=\"pagelinks\">Pages: " >> $pagefile
   1.242 +    if [[ $prevpage -gt 0 ]]; then 
   1.243 +        echo "[<a href=\"index${prevpage}.html\">prev</a>] " >> $pagefile
   1.244 +    else
   1.245 +        echo "[prev] " >> $pagefile
   1.246 +    fi
   1.247 +    for pagelink in `seq 1 $npages`; do
   1.248 +        if [[ $pagelink -ne $page ]]; then
   1.249 +            pagelinkfile=$INDEXFILE
   1.250 +            if [[ $page -ne 1 ]]; then pagefile=index${page}.html; fi
   1.251 +            echo "[<a href=\"$pagelinkfile\">$pagelink</a>] " >> $pagefile
   1.252 +        else
   1.253 +            echo "[$pagelink]" >> $pagefile
   1.254 +        fi
   1.255 +    done
   1.256 +    if [[ $nextpage -lt $npages ]]; then 
   1.257 +        echo "[<a href=\"index${nextpage}.html\">next</a>] " >> $pagefile
   1.258 +    else
   1.259 +        echo "[next] " >> $pagefile
   1.260 +    fi
   1.261 +    echo "</div>" >> $pagefile
   1.262 +    
   1.263 +    # Link to zip file
   1.264 +    if [[ $writeZipfile == "true" ]]; then
   1.265 +        echo "<p>All photos zipped up: <a href=\"$ZIPFILE\">$ZIPFILE</a></p>" >> $pagefile
   1.266 +    fi
   1.267 +    
   1.268 +    # Write the HTML footer
   1.269 +    if [[ $writeFooter == "true" ]]; then
   1.270 +        if [[ -z $footerFile ]]; then
   1.271 +            if [[ $VERBOSE == "true" ]]; then echo "Writing default footer"; fi
   1.272 +            echo "</body></html>" >> $pagefile
   1.273 +        else
   1.274 +            if [[ $VERBOSE == "true" ]]; then echo "Writing footer from $footerFile"; fi
   1.275 +            cat $footerFile >> $pagefile
   1.276 +        fi
   1.277 +    fi
   1.278 +done
   1.279 +
   1.280 +if [[ $VERBOSE == "true" ]]; then 
   1.281 +    echo "All done!"
   1.282 +fi

mercurial