emin

Wed, 24 Apr 2013 10:49:39 +0200

author
Andy Buckley <andy@insectnation.org>
date
Wed, 24 Apr 2013 10:49:39 +0200
changeset 26
79167c58c3a5
parent 25
fb778c6b6d4b
child 28
1088bb11189f
permissions
-rwxr-xr-x

More tweaks. Tagging as 0.3.4

andy@1 1 #! /usr/bin/env python
andy@1 2 # -*- python -*-
andy@1 3
andy@14 4 """%prog [opts] dir [outdir]
andy@3 5
andy@14 6 emin - a static web gallery builder
andy@3 7
andy@24 8 emin makes static Web pages for presenting lots of imagey things: photos, PDFs,
andy@24 9 graphs with thumbnails as well as links to the image/doc file proper.
andy@3 10
andy@24 11 It's primarily intended for making Web photo galleries for the sorts of people
andy@24 12 who don't want to install some PHP monstrosity just to put their photos
andy@24 13 online. On the assumption that most people will want to tweak their gallery's
andy@24 14 appearance, the output is fully customisable using the Cheetah templating
andy@24 15 engine.
andy@3 16
andy@24 17 Supported image formats are JPEG, PNG, GIF, TIFF, PDF and EPS, with the latter
andy@24 18 two being converted to PNG for Web display. Image resizing, renaming and
andy@24 19 thumbnailing is supported, as is building a zip file to download the whole
andy@24 20 set. Large image sets can be split over several pages.
andy@24 21
andy@24 22 As for the name, this is a program to make pretty simple galleries, so it's
andy@14 23 named after a pretty crappy artist. And, thankfully, e-m-i-n is not many
andy@24 24 characters to type.
andy@3 25
andy@3 26 TODO:
andy@24 27 * Make Cheetah templating optional, or use Genshi/Jinja/Mako?
andy@26 28 * Clean up image filenames to avoid/minimise duplicate extensions
andy@24 29 * Try to validate the HTML output
andy@14 30 * Add all on one page option
andy@11 31 * Resize option
andy@11 32 * Rename option
andy@13 33 * Crop-to-thumb option
andy@16 34 * Auto-rotate by EXIF orientation
andy@13 35 * Copy Lightbox stuff into place
andy@6 36 * Allow complete rollback if any failure (or on demand?)
andy@24 37
andy@24 38 Author: Andy Buckley, http://www.insectnation.org\
andy@3 39 """
andy@2 40
andy@24 41 __author__ = "Andy Buckley <andy@insectnation.org>"
andy@24 42 __version__ = "0.3.4"
andy@14 43
andy@3 44
andy@5 45 import logging
andy@2 46 from optparse import OptionParser, OptionGroup
andy@24 47 parser = OptionParser(usage=__doc__, version=__version__)
andy@26 48 parser.add_option("-t", "--title", dest="TITLE", default=None,
andy@5 49 help="title of this gallery")
andy@14 50 parser.add_option("--template", dest="TEMPLATE", default=None,
andy@5 51 help="specify the template file to be used for the index pages")
andy@14 52 parser.add_option("--zipfile", dest="ZIPFILE", default=None,
andy@5 53 help="name of zip archive file. Default is based on the title.")
andy@6 54 parser.add_option("--no-zipfile", action="store_false",
andy@14 55 dest="WRITE_ZIPFILE", default=True,
andy@5 56 help="disable writing out of a zipped archive of photos from this gallery")
andy@24 57 parser.add_option("-1", "--one-page", dest="ONE_PAGE", action="store_true", default=False,
andy@24 58 help="put all thumbnails on one page (default: %default)")
andy@24 59 parser.add_option("-c", "--num-cols", "--cols", dest="NUM_COLS", default=5, type=int,
andy@24 60 help="max number of thumbnail columns on one page (default: %default)")
andy@24 61 parser.add_option("-r", "--num-rows", "--rows", dest="NUM_ROWS", default=6, type=int,
andy@24 62 help="max number of thumbnail rows on one page (default: %default). Set < 1 for unlimited (i.e. all on one page)")
andy@5 63 parser.add_option("--thumb-height", dest="THUMB_HEIGHT", default=150, type=int,
andy@24 64 help="thumbnail height, in pixels (default: %default)")
andy@5 65 parser.add_option("--max-imgsize", dest="MAX_IMGSIZE", default=800, type=int,
andy@24 66 help="max large image dimension in pixels (default: %default)")
andy@24 67 parser.add_option("--exclude", dest="EXCLUDE", default=None,
andy@24 68 help="a regex pattern specifying image files to be excludes (default: %default)")
andy@14 69 parser.add_option("--no-js", dest="USE_JS", action="store_false", default=True,
andy@5 70 help="disable use of funky JavaScript display stuff")
andy@14 71 parser.add_option("--force", dest="FORCE", action="store_true", default=False,
andy@5 72 help="force creation of gallery: regen thumbnails etc.")
andy@14 73 parser.add_option("--no-table", dest="USE_TABLE", action="store_false", default=True,
andy@5 74 help="don't use an HTML table for thumbnail presentation: just let the thumbs flow into the browser window")
andy@5 75 verbgroup = OptionGroup(parser, "Verbosity control")
andy@16 76 verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL",
andy@5 77 default=logging.INFO, help="print debug (very verbose) messages")
andy@16 78 verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL",
andy@5 79 default=logging.INFO, help="be very quiet")
andy@5 80 parser.add_option_group(verbgroup)
andy@3 81 opts, args = parser.parse_args()
andy@5 82 logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s")
andy@1 83
andy@1 84
andy@24 85 ## More imports
andy@24 86 import sys, os, glob, re, math, shutil, fnmatch
andy@24 87 try:
andy@24 88 from Cheetah.Template import Template
andy@24 89 except Exception, e:
andy@24 90 logging.error("Couldn't import required Cheetah package")
andy@24 91 exit(1)
andy@24 92 try:
andy@24 93 import PIL.Image as PILI
andy@24 94 except Exception, e:
andy@24 95 logging.error("Couldn't import required Python Imaging Library package")
andy@24 96 exit(1)
andy@5 97
andy@5 98
andy@5 99 ## Set processing/output dir
andy@9 100 if len(args) < 1 or len(args) > 2:
andy@24 101 parser.print_usage()
andy@9 102 exit(1)
andy@9 103 if len(args) >= 1:
andy@9 104 opts.SRCDIR = os.path.normpath(args[0])
andy@9 105 opts.OUTDIR = os.path.normpath(args[0])
andy@9 106 if len(args) == 2:
andy@9 107 opts.OUTDIR = os.path.normpath(args[1])
andy@5 108
andy@5 109
andy@24 110 ## Deal with consequences of interacting optional settings
andy@24 111 if opts.ONE_PAGE:
andy@24 112 opts.NUM_ROWS = -1
andy@24 113 # TODO: These should be options...
andy@24 114 opts.RENAME = False
andy@24 115 opts.CONVERT = False
andy@2 116
andy@2 117
andy@3 118 def safeencode(s):
andy@2 119 """Encode a string for use as a filename."""
andy@3 120 newstr = s.replace(" ", "-").replace(",", "").replace("/", "").replace(".", "")
andy@3 121 return newstr
andy@1 122
andy@26 123 ## Better title autodetection
andy@26 124 if not opts.TITLE:
andy@26 125 opts.TITLE = os.path.basename(os.path.abspath(opts.SRCDIR))
andy@24 126
andy@5 127 logging.debug("Title: %s" % opts.TITLE)
andy@5 128 logging.debug("Thumb height: %d" % opts.THUMB_HEIGHT)
andy@5 129
andy@1 130
andy@9 131 class ImageInfo(object):
andy@6 132 def __init__(self):
andy@9 133 self.name = None
andy@6 134 self.path = None
andy@9 135 self.thumbname = None
andy@9 136 self.thumbpath = None
andy@9 137 self.thumbx = None
andy@9 138 self.thumby = None
andy@9 139
andy@9 140 def setsize(self, sizetuple):
andy@9 141 self.thumbx = sizetuple[0]
andy@9 142 self.thumby = sizetuple[1]
andy@9 143
andy@7 144 def _getsize(self):
andy@9 145 return self.thumbx, self.thumby
andy@9 146
andy@9 147 thumbsize = property(_getsize, setsize)
andy@6 148
andy@6 149
andy@2 150 ## Go to the gallery directory and test if it's writeable
andy@2 151 if not os.access(opts.OUTDIR, os.W_OK):
andy@9 152 try:
andy@9 153 logging.info("Making output dir in %s" % opts.OUTDIR)
andy@9 154 os.makedirs(opts.OUTDIR)
andy@9 155 except Exception, e:
andy@9 156 logging.error("Problem when making output dir %s... exiting" % opts.OUTDIR)
andy@9 157 exit(1)
andy@1 158
andy@14 159
andy@9 160 ## Make thumbnail directory if needed
andy@9 161 opts.THUMBDIR = "thumbs"
andy@9 162 THUMBDIR = os.path.join(opts.OUTDIR, opts.THUMBDIR)
andy@5 163 try:
andy@9 164 if not os.path.isdir(THUMBDIR):
andy@9 165 logging.info("Making thumbs dir in %s" % THUMBDIR)
andy@9 166 os.makedirs(THUMBDIR)
andy@5 167 except Exception, e:
andy@5 168 logging.error("Problem when making thumbnails dir... exiting")
andy@9 169 exit(1)
andy@5 170
andy@2 171
andy@9 172 ## Build the list of pictures to display
andy@24 173 # TODO: types: PNG/GIF, JPEG, PDF
andy@24 174 # TODO: match formats & store thumb filenames
andy@9 175 EXTENSIONS = \
andy@9 176 ["*.jpg", "*.jpeg"] + \
andy@9 177 ["*.png", "*.gif"] + \
andy@9 178 ["*.tif", "*.tiff"] + \
andy@9 179 ["*.eps", "*.pdf"]
andy@9 180 imgs = []
andy@9 181 for img in os.listdir(opts.SRCDIR):
andy@9 182 for e in EXTENSIONS:
andy@24 183 if not fnmatch.fnmatch(img.lower(), e):
andy@24 184 continue
andy@24 185 if opts.EXCLUDE and re.search(opts.EXCLUDE, img):
andy@24 186 continue
andy@24 187 imgpath = os.path.join(opts.SRCDIR, img)
andy@24 188 imgs.append(imgpath)
andy@24 189 break
andy@9 190
andy@3 191 ## Count the pictures
andy@9 192 logging.debug("Number of pictures = %d" % len(imgs))
andy@9 193 if len(imgs) == 0:
andy@2 194 logging.debug("No pictures from which to build a gallery...")
andy@9 195 exit(2)
andy@9 196 logging.debug("Images: " + str(sorted(imgs)))
andy@2 197
andy@5 198
andy@9 199 ## Rename/move if needed
andy@9 200 outimgs = []
andy@9 201 for n, imgpath in enumerate(imgs):
andy@9 202 imgname = os.path.basename(imgpath)
andy@9 203 imgnameparts = os.path.splitext(imgname)
andy@9 204 targetname = imgname
andy@9 205 if opts.RENAME:
andy@9 206 targetname = "%s-%03d%s" % (safename(opts.OUTDIR), n, imgnameparts[1])
andy@9 207 targetpath = os.path.join(opts.OUTDIR, targetname)
andy@9 208 outimgs.append(targetpath)
andy@9 209 if imgpath != targetpath:
andy@9 210 logging.debug("Copying %s -> %s" % (imgpath, targetpath))
andy@9 211 import shutil
andy@9 212 shutil.copy(imgpath, targetpath)
andy@9 213
andy@9 214
andy@9 215 ## Store some image info
andy@9 216 imgsinfo = {}
andy@9 217 for picpath in outimgs:
andy@9 218 picname = os.path.basename(picpath)
andy@9 219 picbase = os.path.splitext(picname)[0]
andy@9 220
andy@9 221 ## Convert EPS, PDF, TIFF to Web-viewable formats
andy@9 222 picversions = {}
andy@9 223 picpathparts = os.path.splitext(picpath)
andy@9 224 picnameparts = os.path.splitext(picname)
andy@9 225 extn = picnameparts[1].lower()
andy@9 226 convcmd = None
andy@9 227 if extn in [".tif", ".tiff"]:
andy@9 228 picversions["TIFF"] = picname
andy@9 229 newpicname = picname + ".jpg"
andy@9 230 newpicpath = picpath + ".jpg"
andy@9 231 picversions["JPG"] = newpicname
andy@9 232 convcmd = ["convert", picpath, newpicpath]
andy@9 233 picname = newpicname
andy@9 234 picpath = newpicpath
andy@9 235 elif extn in [".eps", ".pdf"]:
andy@9 236 picversions[extn[1:].upper()] = picname
andy@9 237 newpicname = picname + ".png"
andy@9 238 newpicpath = picpath + ".png"
andy@9 239 picversions["PNG"] = newpicname
andy@10 240 convcmd = ["convert", "-density", "200", "-resize", "800x700", picpath, newpicpath]
andy@9 241 picname = newpicname
andy@9 242 picpath = newpicpath
andy@9 243 else:
andy@9 244 picversions[extn[1:].upper()] = picname
andy@9 245
andy@9 246 ## Do the conversion
andy@9 247 if convcmd:
andy@9 248 try:
andy@24 249 # TODO: threading / multiprocessing for speed-up?
andy@9 250 import subprocess
andy@9 251 subprocess.check_call(convcmd)
andy@9 252 except:
andy@9 253 raise
andy@9 254
andy@9 255 ## Main pic info
andy@9 256 info = ImageInfo()
andy@9 257 info.name = picname
andy@9 258 info.path = picpath
andy@9 259 info.versions = picversions
andy@9 260
andy@9 261 ## Thumb info
andy@9 262 ## TODO: Un-hard-code PNG thumb format
andy@9 263 thumbname = picname + ".png"
andy@9 264 thumbpath = os.path.join(THUMBDIR, thumbname)
andy@9 265 info.thumbname = thumbname
andy@9 266 info.thumbpath = thumbpath
andy@9 267
andy@9 268 ## Make thumbnail
andy@9 269 ## TODO: Be lazy!
andy@9 270 #if opts.FORCE or not os.access(thumbpath, os.R_OK) or os.stat(thumbpath).st_mtime > os.stat(pic).st_mtime:
andy@9 271 try:
andy@9 272 logging.debug("Making new thumbnail %s for %s (max height %d)" % \
andy@9 273 (thumbpath, picname, opts.THUMB_HEIGHT))
andy@9 274 thumbimg = PILI.open(picpath, "r")
andy@9 275 thumbimg.thumbnail((100000000, opts.THUMB_HEIGHT), resample=PILI.ANTIALIAS)
andy@9 276 thumbimg.save(thumbpath)
andy@9 277 info.thumbsize = thumbimg.size
andy@9 278 except Exception, e:
andy@9 279 logging.warning("Problem when making thumbnail from %s... exiting" % picpath)
andy@9 280 exit(1)
andy@9 281
andy@9 282 ## Store info
andy@9 283 imgsinfo[picname] = info
andy@9 284
andy@9 285
andy@9 286 #####################
andy@9 287
andy@5 288
andy@3 289 ## Calculate how many pages will be needed
andy@24 290 if opts.NUM_ROWS >= 1:
andy@24 291 NUM_PER_PAGE = opts.NUM_ROWS * opts.NUM_COLS
andy@24 292 NUM_PAGES = int(math.ceil( len(imgs)/float(NUM_PER_PAGE) ))
andy@24 293 else:
andy@24 294 NUM_PER_PAGE = len(imgs)
andy@24 295 NUM_PAGES = 1
andy@24 296
andy@24 297
andy@24 298 if NUM_PAGES > 1:
andy@25 299 logging.warn("%d gallery pages will be made. If you just want one page, use the -1 or --one-page option" % NUM_PAGES)
andy@1 300
andy@1 301
andy@14 302 ## TODO: Move HTML extension-setting to option parser
andy@6 303 ## (or take from template name, e.g. page.html.template -> html)
andy@6 304 opts.EXTN = "html"
andy@6 305
andy@6 306
andy@3 307 def getPageFilename(pagenum):
andy@9 308 if pagenum == 1:
andy@3 309 pagefile = "index.%s" % opts.EXTN
andy@3 310 else:
andy@3 311 pagefile = "index%02d.%s" % (pagenum, opts.EXTN)
andy@8 312 return pagefile
andy@3 313
andy@3 314
andy@3 315 def mkPageLinkStr(pagenum):
andy@14 316 "Write the linked page list"
andy@3 317 global NUM_PAGES
andy@14 318 out = ''
andy@3 319 if NUM_PAGES > 1:
andy@6 320 out += ""
andy@3 321 ## Previous
andy@3 322 prev = pagenum - 1
andy@3 323 if prev > 0:
andy@14 324 out += '<a href="%s">prev</a>' % getPageFilename(prev)
andy@3 325 else:
andy@14 326 out += 'prev'
andy@14 327 out += '&nbsp;'
andy@3 328 ## Numbers
andy@14 329 for n in range(1, NUM_PAGES+1):
andy@3 330 if n != pagenum:
andy@14 331 out += '<a href="%s">%d</a>' % (getPageFilename(n), n)
andy@14 332 else:
andy@14 333 out += "%d" % n
andy@14 334 out += '&nbsp;'
andy@3 335 ## Next
andy@3 336 next = pagenum + 1
andy@3 337 if next <= NUM_PAGES:
andy@14 338 out += '<a href="%s">next</a>' % getPageFilename(next)
andy@3 339 else:
andy@14 340 out += 'next'
andy@3 341 return out
andy@3 342
andy@3 343
andy@9 344 ## Make a zip archive
andy@9 345 ZIPFILE = "photo-album.zip"
andy@9 346 if True: #opts.WRITE_ZIPFILE:
andy@3 347 logging.debug("Making zipped picture archive")
andy@6 348 if opts.ZIPFILE is not None:
andy@6 349 ZIPFILE = opts.ZIPFILE
andy@6 350 elif opts.TITLE is not None or len(opts.TITLE) > 0:
andy@3 351 ZIPFILE = safeencode(opts.TITLE)
andy@8 352 #ZIPFILE = safename(opts.OUTDIR)
andy@9 353 if not "." in ZIPFILE or os.path.splitextn(ZIPFILE)[1] != ".zip":
andy@6 354 ZIPFILE += ".zip"
andy@9 355 ## Do the zipping
andy@13 356 if ZIPFILE:
andy@13 357 from zipfile import ZipFile
andy@13 358 zf = ZipFile(os.path.join(opts.OUTDIR, ZIPFILE), "w")
andy@13 359 for img in imgs:
andy@13 360 zf.write(img, os.path.basename(img))
andy@13 361 zf.close()
andy@13 362 else:
andy@13 363 logging.warning("No zip file made because zip filename is empty")
andy@3 364
andy@3 365
andy@24 366 ## Copy Lightbox stuff into ZIP
andy@9 367 #if opts.USE_JS:
andy@9 368 # from zipfile import ZipFile
andy@9 369 # zf = ZipFile(os.path.join(opts.OUTDIR, "lightbox.zip"), "r")
andy@9 370 # for img in imgs:
andy@9 371 # zf.write(img, os.path.basename(img))
andy@9 372 # zf.close()
andy@14 373
andy@9 374
andy@9 375 ## Default template
andy@9 376 tmplstr = \
andy@24 377 '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
andy@9 378 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
andy@9 379 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
andy@9 380 <head>
andy@13 381 #set title = $PAGETITLE
andy@13 382 #if $NUM_PAGES > 1
andy@13 383 #set title = $title + " (page %s)" % $PAGENUM
andy@13 384 #end if
andy@9 385 <title>$title</title>
andy@9 386 <style>
andy@13 387 img { border:0; padding:10 10 0 0; }
andy@9 388 body { padding:1em; background:white; font-family:sans-serif; }
andy@9 389 h1 { font-family:sans-serif; }
andy@13 390 a.format { text-decoration:none; font-variant:small-caps; color:grey; font-size:small; }
andy@13 391 a.format:hover { color:deeppink; }
andy@13 392 a.format:active { color:deeppink; }
andy@14 393 .pagelinks { text-decoration:none; font-variant:small-caps; color:grey; margin-top:1em; margin-bottom:1em; }
andy@14 394 .pagelinks a:link { color:#22c; text-decoration:none; }
andy@14 395 .pagelinks a:hover { color:#55c; text-decoration:none; }
andy@14 396 .pagelinks a:active { color:#55c; text-decoration:none; }
andy@9 397 </style>
andy@9 398 #if $OPTS.USE_JS:
andy@14 399 <link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" />
andy@9 400 <script src="lightbox/js/prototype.js" type="text/javascript"></script>
andy@9 401 <script src="lightbox/js/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
andy@9 402 <script src="lightbox/js/lightbox.js" type="text/javascript"></script>
andy@9 403 #end if
andy@9 404 </head>
andy@9 405 <body>
andy@9 406 <h1>$PAGETITLE</h1>
andy@9 407 #if $NUM_PAGES > 1
andy@9 408 <div class="pagelinks">Pages: $LINKSTR</div>
andy@9 409 #end if
andy@9 410
andy@9 411 <table>
andy@9 412 <tr>
andy@9 413 #set jsrel = ''
andy@9 414 #if $OPTS.USE_JS:
andy@9 415 #set jsrel = 'rel="lightbox[emin]"'
andy@9 416 #end if
andy@9 417 #for n, thumb in enumerate($PAGEPICS)
andy@9 418 #if $n % $NUM_COLS == 0 and $n not in (0, len($PAGEPICS)-1)
andy@9 419 <tr/><tr>
andy@9 420 #end if
andy@9 421 #set info = $PICINFO[$thumb]
andy@9 422 <td>
andy@23 423 <a href="$info.relpath" $jsrel><img alt="$thumb" src="$info.relthumbpath" style="border:0;" width="$info.thumbx" height="$info.thumby" /></a><br/>
andy@9 424 #for fmt, name in $info.versions.iteritems()
andy@13 425 <a class="format" href="$name">$fmt.lower()</a>
andy@9 426 #end for
andy@9 427 </td>
andy@9 428 #end for
andy@9 429 </tr>
andy@9 430 </table>
andy@9 431
andy@9 432 #if $NUM_PAGES > 1
andy@9 433 <div class="pagelinks">Pages: $LINKSTR</div>
andy@9 434 #end if
andy@9 435
andy@13 436 #if $OPTS.WRITE_ZIPFILE and $ZIPFILE:
andy@9 437 <p>All zipped up: <a href="$ZIPFILE">$ZIPFILE</a></p>
andy@9 438 #end if
andy@9 439 </body>
andy@9 440 </html>
andy@24 441 '''
andy@9 442
andy@9 443
andy@9 444 ## Override default template with a template file
andy@9 445 if opts.TEMPLATE is not None:
andy@9 446 logging.info("Using index template file %s" % opts.TEMPLATE)
andy@9 447 tf = open(opts.TEMPLATE, "r")
andy@9 448 tmplstr = tf.read()
andy@9 449 tf.close()
andy@8 450
andy@8 451
andy@3 452 ## Make each index page
andy@3 453 for n in range(NUM_PAGES):
andy@6 454 PAGENUM = n + 1
andy@3 455
andy@3 456 ## Choose and open page file
andy@14 457 PAGEFILE = getPageFilename(PAGENUM)
andy@9 458 PAGEPATH = os.path.join(opts.OUTDIR, PAGEFILE)
andy@8 459
andy@3 460 ## Write the title
andy@26 461 PAGETITLE = opts.TITLE
andy@14 462
andy@3 463 ## Write the linked page list
andy@8 464 LINKSTR = mkPageLinkStr(PAGENUM)
andy@14 465
andy@9 466 ## Work out the picture offsets for this page
andy@3 467 pics_start = n * NUM_PER_PAGE
andy@3 468 pics_end = (n+1) * NUM_PER_PAGE - 1
andy@9 469 if pics_end >= len(imgs):
andy@9 470 pics_end = len(imgs) - 1
andy@1 471
andy@16 472 PAGEPICS = sorted(imgsinfo.keys())[pics_start: pics_end+1]
andy@9 473 PAGEPICNUMS = range(len(PAGEPICS))
andy@9 474 relthumbdir = opts.THUMBDIR
andy@9 475 #relthumbdir = os.path.relpath(THUMBDIR, OUTDIR)
andy@9 476 reloutdir = "."
andy@9 477 for k in imgsinfo.keys():
andy@9 478 imgsinfo[k].relthumbpath = os.path.normpath(os.path.join(relthumbdir, imgsinfo[k].thumbname))
andy@9 479 imgsinfo[k].relpath = os.path.normpath(os.path.join(reloutdir, imgsinfo[k].name))
andy@9 480 PICINFO = imgsinfo
andy@9 481 # THUMBNAMES = [t.name for t in thumbsinfo.values()[pics_start : pics_end]]
andy@9 482 # print THUMBNAMES
andy@9 483 # THUMBPATHS = [os.path.join(relthumbdir, name) for name in THUMBNAMES]
andy@9 484 # print THUMBPATHS
andy@9 485 # THUMBDIMS = [t.size for t in thumbsinfo.values()[pics_start : pics_end]]
andy@1 486
andy@9 487 logging.info("Writing to index file %s" % PAGEPATH)
andy@9 488 f = open(PAGEPATH, "w")
andy@16 489 logging.debug("Images on page: %s" % PAGEPICS)
andy@8 490 tdict = {}
andy@8 491 tdict["NUM_PAGES"] = NUM_PAGES
andy@9 492 tdict["NUM_PER_PAGE"] = NUM_PER_PAGE
andy@9 493 tdict["NUM_COLS"] = opts.NUM_COLS
andy@8 494 tdict["PAGEPICS"] = PAGEPICS
andy@8 495 tdict["PAGENUM"] = PAGENUM
andy@8 496 tdict["PAGETITLE"] = PAGETITLE
andy@8 497 tdict["LINKSTR"] = LINKSTR
andy@8 498 tdict["PAGEPICNUMS"] = PAGEPICNUMS
andy@9 499 tdict["PICINFO"] = imgsinfo
andy@9 500 # tdict["THUMBS"] = thumbsinfo
andy@9 501 # tdict["THUMBNAMES"] = THUMBNAMES
andy@9 502 # tdict["THUMBPATHS"] = THUMBPATHS
andy@9 503 # tdict["THUMBDIMS"] = THUMBDIMS
andy@8 504 tdict["ZIPFILE"] = ZIPFILE
andy@8 505 tdict["OPTS"] = opts
andy@8 506 indexstr = Template(tmplstr, searchList=[tdict])
andy@9 507 #print indexstr
andy@8 508 f.write(str(indexstr))
andy@3 509 f.close()
andy@3 510
andy@3 511 ## It's over. Nothing to see here.
andy@3 512 logging.debug("All done!")

mercurial