emin

Wed, 24 Apr 2013 10:37:45 +0200

author
Andy Buckley <andy@insectnation.org>
date
Wed, 24 Apr 2013 10:37:45 +0200
changeset 24
02f21810d43d
parent 23
4e1d30c61d0e
child 25
fb778c6b6d4b
permissions
-rwxr-xr-x

Adding -1/--one-pageand --exclude options, and various tweaks

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

mercurial