terom@8: #!/usr/bin/env python2.4 terom@12: # terom@12: # DeGAL - A pretty simple web image gallery terom@12: # Copyright (C) 2007 Tero Marttila terom@12: # http://marttila.de/~terom/degal/ terom@12: # terom@12: # This program is free software; you can redistribute it and/or modify terom@12: # it under the terms of the GNU General Public License as published by terom@12: # the Free Software Foundation; either version 2 of the License, or terom@12: # (at your option) any later version. terom@12: # terom@12: # This program is distributed in the hope that it will be useful, terom@12: # but WITHOUT ANY WARRANTY; without even the implied warranty of terom@12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terom@12: # GNU General Public License for more details. terom@12: # terom@12: # You should have received a copy of the GNU General Public License terom@12: # along with this program; if not, write to the terom@12: # Free Software Foundation, Inc., terom@12: # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. terom@12: # terom@12: terom@8: terom@8: import cgi terom@8: import shelve terom@8: import os, os.path terom@8: terom@8: import degal terom@8: terom@8: images = shelve.open('images', 'c') terom@8: tag_images = shelve.open('tag_images', 'c') terom@8: tag_tags = shelve.open('tag_tags', 'c') terom@8: terom@8: # request params terom@8: vars = cgi.FieldStorage() terom@8: terom@8: if 'path' in vars : terom@8: path = vars['path'].value terom@8: else : terom@8: path = '.' terom@8: terom@8: image_list = [] terom@8: terom@8: if 'bulk_tag' in vars : terom@8: bulk_tags = vars['bulk_tag'].value.split() terom@8: else : terom@8: bulk_tags = None terom@8: terom@8: for fname in os.listdir(path) : terom@8: if degal.isImage(fname) : terom@8: image_path = os.path.join(path, fname) terom@8: thumb_path = os.path.join(path, degal.THUMB_DIR, fname) terom@8: html_path = image_path + '.html' terom@8: terom@8: title, descr, tags = images.get(image_path, (None, None, [])) terom@8: terom@8: if 'img_%s_title' % fname in vars : terom@8: title = vars['img_%s_title' % fname].value terom@8: terom@8: if 'img_%s_descr' % fname in vars : terom@8: descr = vars['img_%s_descr' % fname].value terom@8: terom@8: if 'img_%s_tags' % fname in vars : terom@8: tags = vars['img_%s_tags' % fname].value.split() terom@8: terom@8: if bulk_tags and 'img_%s_chk' % fname in vars : terom@8: tags.extend(bulk_tags) terom@8: terom@8: if title or descr or tags : terom@8: images[image_path] = (title, descr, tags) terom@8: terom@8: html = """ terom@8:
  • terom@8: terom@8:
    terom@8:
    terom@8:
    terom@8:
    terom@8: terom@8: terom@8: terom@8: terom@8:
  • terom@8: """ % dict( terom@8: html_path = html_path, terom@8: thumb_path = thumb_path, terom@8: fname = fname, terom@8: title = title and title or '', terom@8: descr = descr and descr or '', terom@8: tags = tags and ' '.join(tags) or '', terom@8: ) terom@8: terom@8: image_list.append((fname, html)) terom@8: terom@8: image_list.sort() terom@8: terom@8: print "Content-Type: text/html" terom@8: print terom@8: print degal.Template('taggr').render( terom@8: TITLE = "Taggr - %s" % path, terom@8: BREADCRUMB = "TODO", terom@8: CONTENT = "", terom@8: PATH = path, terom@8: ) terom@8: