Fixes

Sat, 21 Aug 2010 11:36:42 +0000

author
andy
date
Sat, 21 Aug 2010 11:36:42 +0000
changeset 14
73e0b44f6844
parent 13
32883d89ca7f
child 15
7e3e3eed8ebd

Fixes

emin file | annotate | diff | comparison | revisions
     1.1 --- a/emin	Tue Feb 24 15:35:41 2009 +0000
     1.2 +++ b/emin	Sat Aug 21 11:36:42 2010 +0000
     1.3 @@ -1,27 +1,24 @@
     1.4  #! /usr/bin/env python
     1.5  # -*- python -*-
     1.6  
     1.7 -version = "%prog 0.2"
     1.8 +"""%prog [opts] dir [outdir]
     1.9  
    1.10 -usage="""%prog [opts] dir [outdir]
    1.11 -
    1.12 -%prog - a static web gallery builder
    1.13 +emin - a static web gallery builder
    1.14  
    1.15  by Andy Buckley
    1.16  http://www.insectnation.org
    1.17  
    1.18 -This is a weeny script for making static sets of Web
    1.19 -pages for presenting lots of imagey things: photos, 
    1.20 -PDFs, graphs...
    1.21 +This is a weeny script for making static sets of Web pages for presenting lots
    1.22 +of imagey things: photos, PDFs, graphs...
    1.23  
    1.24 -As for the name, this is a program to make pretty 
    1.25 -crappy galleries, so it's named after a pretty crappy 
    1.26 -artist. And, thankfully, e-m-i-n is not many characters
    1.27 -to type (and they're all close together on the Colemak
    1.28 -keyboard layout) --- trebles all round!
    1.29 +As for the name, this is a program to make pretty crappy galleries, so it's
    1.30 +named after a pretty crappy artist. And, thankfully, e-m-i-n is not many
    1.31 +characters to type (and they're all close together on the Colemak keyboard
    1.32 +layout) --- trebles all round!
    1.33  
    1.34  TODO:
    1.35   * Try to import BeautifulSoup for validating/pretty-printing the output
    1.36 + * Add all on one page option
    1.37   * Resize option
    1.38   * Rename option
    1.39   * Crop-to-thumb option
    1.40 @@ -30,19 +27,22 @@
    1.41   * Allow complete rollback if any failure (or on demand?)
    1.42  """
    1.43  
    1.44 +__version__ = "0.3"
    1.45 +
    1.46  
    1.47  import logging
    1.48  from optparse import OptionParser, OptionGroup
    1.49 -parser = OptionParser(usage=usage, version=version)
    1.50 -parser.add_option("-t", "--title", dest="TITLE", default="", 
    1.51 +parser = OptionParser(usage=__doc__, version="%prog " + __version__)
    1.52 +parser.add_option("-t", "--title", dest="TITLE", default="",
    1.53                    help="title of this gallery")
    1.54 -parser.add_option("--template", dest="TEMPLATE", default=None, 
    1.55 +parser.add_option("--template", dest="TEMPLATE", default=None,
    1.56                    help="specify the template file to be used for the index pages")
    1.57 -parser.add_option("--zipfile", dest="ZIPFILE", default=None, 
    1.58 +parser.add_option("--zipfile", dest="ZIPFILE", default=None,
    1.59                    help="name of zip archive file. Default is based on the title.")
    1.60  parser.add_option("--no-zipfile", action="store_false",
    1.61 -                  dest="WRITE_ZIPFILE", default=True, 
    1.62 +                  dest="WRITE_ZIPFILE", default=True,
    1.63                    help="disable writing out of a zipped archive of photos from this gallery")
    1.64 +## TODO: Add all on one page option
    1.65  parser.add_option("-c", "--num-cols", dest="NUM_COLS", default=5, type=int,
    1.66                    help="max number of thumbnail columns on one page (default: 5)")
    1.67  parser.add_option("-r", "--num-rows", dest="NUM_ROWS", default=6, type=int,
    1.68 @@ -51,11 +51,11 @@
    1.69                    help="thumbnail height, in pixels (default: 100)")
    1.70  parser.add_option("--max-imgsize", dest="MAX_IMGSIZE", default=800, type=int,
    1.71                    help="max large image dimension in pixels (default: 800)")
    1.72 -parser.add_option("--no-js", dest="USE_JS", action="store_false", default=True, 
    1.73 +parser.add_option("--no-js", dest="USE_JS", action="store_false", default=True,
    1.74                    help="disable use of funky JavaScript display stuff")
    1.75 -parser.add_option("--force", dest="FORCE", action="store_true", default=False, 
    1.76 +parser.add_option("--force", dest="FORCE", action="store_true", default=False,
    1.77                    help="force creation of gallery: regen thumbnails etc.")
    1.78 -parser.add_option("--no-table", dest="USE_TABLE", action="store_false", default=True, 
    1.79 +parser.add_option("--no-table", dest="USE_TABLE", action="store_false", default=True,
    1.80                    help="don't use an HTML table for thumbnail presentation: just let the thumbs flow into the browser window")
    1.81  verbgroup = OptionGroup(parser, "Verbosity control")
    1.82  verbgroup.add_option("-V", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL",
    1.83 @@ -141,6 +141,7 @@
    1.84          #traceback.print_exc()
    1.85          exit(1)
    1.86  
    1.87 +
    1.88  ## Make thumbnail directory if needed
    1.89  opts.THUMBDIR = "thumbs"
    1.90  THUMBDIR = os.path.join(opts.OUTDIR, opts.THUMBDIR)
    1.91 @@ -275,7 +276,7 @@
    1.92  NUM_PAGES = int(math.ceil( len(imgs)/float(NUM_PER_PAGE) ))
    1.93  
    1.94  
    1.95 -## TODO: Move HTML extension-setting to option parser 
    1.96 +## TODO: Move HTML extension-setting to option parser
    1.97  ## (or take from template name, e.g. page.html.template -> html)
    1.98  opts.EXTN = "html"
    1.99  
   1.100 @@ -289,29 +290,31 @@
   1.101  
   1.102  
   1.103  def mkPageLinkStr(pagenum):
   1.104 -    "Write the linked page list"  
   1.105 +    "Write the linked page list"
   1.106      global NUM_PAGES
   1.107 -    out = ""
   1.108 +    out = ''
   1.109      if NUM_PAGES > 1:
   1.110          out += ""
   1.111          ## Previous
   1.112          prev = pagenum - 1
   1.113          if prev > 0:
   1.114 -            out += '[<a href="%s">prev</a>] ' % getPageFilename(prev)
   1.115 +            out += '<a href="%s">prev</a>' % getPageFilename(prev)
   1.116          else:
   1.117 -            out += '[prev] '
   1.118 +            out += 'prev'
   1.119 +        out += '&nbsp;'
   1.120          ## Numbers
   1.121 -        for n in range(NUM_PAGES):
   1.122 +        for n in range(1, NUM_PAGES+1):
   1.123              if n != pagenum:
   1.124 -                out += '[<a href="%s">%d</a>] ' % (getPageFilename(n), n)
   1.125 -        else:
   1.126 -            out += "[%d]" % n
   1.127 +                out += '<a href="%s">%d</a>' % (getPageFilename(n), n)
   1.128 +            else:
   1.129 +                out += "%d" % n
   1.130 +            out += '&nbsp;'
   1.131          ## Next
   1.132          next = pagenum + 1
   1.133          if next <= NUM_PAGES:
   1.134 -            out += '[<a href="%s">prev</a>] ' % getPageFilename(next)
   1.135 +            out += '<a href="%s">next</a>' % getPageFilename(next)
   1.136          else:
   1.137 -            out += '[next] '
   1.138 +            out += 'next'
   1.139      return out
   1.140  
   1.141  
   1.142 @@ -344,7 +347,7 @@
   1.143  #    for img in imgs:
   1.144  #        zf.write(img, os.path.basename(img))
   1.145  #    zf.close()
   1.146 -   
   1.147 +
   1.148  
   1.149  ## Default template
   1.150  tmplstr = \
   1.151 @@ -364,9 +367,13 @@
   1.152        a.format { text-decoration:none; font-variant:small-caps; color:grey; font-size:small; }
   1.153        a.format:hover { color:deeppink; }
   1.154        a.format:active { color:deeppink; }
   1.155 +      .pagelinks { text-decoration:none; font-variant:small-caps; color:grey; margin-top:1em; margin-bottom:1em; }
   1.156 +      .pagelinks a:link { color:#22c; text-decoration:none; }
   1.157 +      .pagelinks a:hover { color:#55c; text-decoration:none; }
   1.158 +      .pagelinks a:active { color:#55c; text-decoration:none; }
   1.159      </style>
   1.160      #if $OPTS.USE_JS:
   1.161 -    <link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" />	
   1.162 +    <link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" />
   1.163      <script src="lightbox/js/prototype.js" type="text/javascript"></script>
   1.164      <script src="lightbox/js/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
   1.165      <script src="lightbox/js/lightbox.js" type="text/javascript"></script>
   1.166 @@ -426,15 +433,15 @@
   1.167      PAGENUM = n + 1
   1.168  
   1.169      ## Choose and open page file
   1.170 -    PAGEFILE = getPageFilename(PAGENUM) 
   1.171 +    PAGEFILE = getPageFilename(PAGENUM)
   1.172      PAGEPATH = os.path.join(opts.OUTDIR, PAGEFILE)
   1.173  
   1.174      ## Write the title
   1.175      PAGETITLE = opts.TITLE or os.path.basename(opts.SRCDIR)
   1.176 -    
   1.177 +
   1.178      ## Write the linked page list
   1.179      LINKSTR = mkPageLinkStr(PAGENUM)
   1.180 -    
   1.181 +
   1.182      ## Work out the picture offsets for this page
   1.183      pics_start = n * NUM_PER_PAGE
   1.184      pics_end = (n+1) * NUM_PER_PAGE - 1

mercurial