# HG changeset patch # User terom # Date 1198359061 0 # Node ID 46536daf9e0480d4e0191885aed2ab80c6f665d9 # Parent adde6ad8731ea9e34a742eb6ea715e123588b4e1 fix bug with shorturls in gallery.html, and some horrible, horrible crap for the CGI stuff - I need to drop everything now and take a fresh look tomorrow before it gets even worse diff -r adde6ad8731e -r 46536daf9e04 cgi-bin/inc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/inc.py Sat Dec 22 21:31:01 2007 +0000 @@ -0,0 +1,18 @@ +if __name__ == '__main__' : + raise Exception("Don't access inc.py directly") + +# setup env + +import sys +import os, os.path + +def splitn (path, n) : + for i in xrange(0, n) : + path = os.path.split(path)[0] + + return path + +degal_path = splitn(os.path.join(os.getcwd(), __file__), 2) + +os.chdir(degal_path) +sys.path.append(degal_path) diff -r adde6ad8731e -r 46536daf9e04 cgi-bin/series.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/series.py Sat Dec 22 21:31:01 2007 +0000 @@ -0,0 +1,215 @@ +#!/usr/bin/env python2.4 +# +# DeGAL - A pretty simple web image gallery +# Copyright (C) 2007 Tero Marttila +# http://marttila.de/~terom/degal/ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import shelve +import cgi +import Cookie +import os, os.path + +import degal + +# +# load request params +# +vars = cgi.FieldStorage() + +# these are interpeted different ways, hence the generic naming +arg1 = vars["keys"].value +if 'index' in vars : + arg2 = vars["index"].value +else : + arg2 = None + +# the cookie with the user's current series +cookie = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE', None)) + +# a special action? +if arg1 and arg1 in ('add', 'del', 'clear', 'view') or arg2 == 'load' : + # load the keys from the cookie + if 'series' in cookie : + keys = cookie["series"].value.split() + else : + keys = [] + + if arg2 == 'load' : + # set the keys in the user's cookie to those in the URL + keys = arg1.split() + + elif arg1 == 'add' and arg2 not in keys : + # add a code to the list of keys + keys.append(arg2) + + elif arg1 == 'del' and arg2 in keys : + # remove a key from the list of keys + keys.remove(arg2) + + elif arg1 == 'clear' : + # clear out the set of keys + keys = [] + + elif arg1 == 'view' : + # just view them + pass + + # set the series cookie value + cookie['series'] = ' '.join(keys) + cookie['series']['path'] = '/' + + # if we have keys, redirect to them, otherwise, back to index we go + if keys : + redirect_to = "../%s/" % ('+'.join(keys)) + else : + redirect_to = "../.." + + # do the redirect + print "Status: 302" + print "Location: %s" % redirect_to + print cookie + print + print "Redirect..." +else : + # we're just viewing + keys = arg1.split() + + # is this "My Series"? + my_series = 'series' in cookie and cookie['series'].value.split() == keys + + if arg2 : + index = int(arg2) + else : + index = None + + # load DB + db = shelve.open('shorturls2', 'r') + + # get the Image objects + photos = [] + + # + # Start ugly code-misreuse + # + + # monkey-patch the templates + rendered_templates = [] + + def _myRenderTo (self, path, **vars) : + rendered_templates.append(self.render(**vars)) + + # lalalalala... ooh, look; + + degal.Template.renderTo = _myRenderTo + # + # vvvvvvvvvvvvvvvvvvvv + # vvvvvvvvvvvvvvvvvvvv + # + # >>>> SHINY PINK ELEPHANT! <<<< + # + # ^^^^^^^^^^^^^^^^^^^^ + # ^^^^^^^^^^^^^^^^^^^^ + + # our own version of Folder + class Series (degal.Folder) : + def __init__ (self) : + super(Series, self).__init__() + + self.alive = True + self.filtered = False + self.subdirs = {} + self.images = {} + self.sorted_images = [] + self.title = "Series" + + if my_series : + self.descr = 'Clear your series' + else : + self.descr = 'Load as your series' + + self.shorturl_code = '' + + def breadcrumb (self) : + return [('../..', 'Gallery'), ('.', 'Series')] + + def inRoot (self, *fnames) : + return os.path.join('../..', *fnames) + + class Image (degal.Image) : + def __init__ (self, series, key, i) : + type, self.dir_name, self.image_name = db[key] + + super(Image, self).__init__(series, self.image_name) + + self.path = self._path() + self.shorturl_code = key + self.html_path = self.html_name = str(i + 1) + self.title = 'Image %d' % (i + 1, ) + self.descr = 'Standalone image: %s' % (self._path(), self._path().lstrip('./')) + self.img_size = (-1, -1) + self.filesize = 0 + self.timestamp = 0 + + if my_series : + self.series_act = "del" + self.series_verb = "Remove from" + else : + self.series_act = self.series_verb = "" + + def breadcrumb (self) : + return [('../..', 'Gallery'), ('.', 'Series'), (self.html_name, self.title)] + + def _path (self, blaa='') : + return os.path.join('../..', self.dir_name, blaa, self.image_name) + + def thumbImgTag (self) : + return degal.link(self.html_name, "%s" % (self._path(degal.THUMB_DIR), '', self.title)) + + def previewImgTag (self) : + return degal.link(self._path(), "%s" % (self._path(degal.PREVIEW_DIR), '', self.title)) + + series = Series() + + try : + prev = None + + for i, key in enumerate(keys) : + img = Image(series, key, i) + + if prev : + prev.next = img + + img.prev = prev + prev = img + + series.sorted_images.append(img) + finally : + db.close() + + if index : + img = series.sorted_images[index - 1] + + img.render() + else : + series.render() + + print "Content-Type: text/html" + print + print rendered_templates[0] + diff -r adde6ad8731e -r 46536daf9e04 cgi-bin/shorturl.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/shorturl.py Sat Dec 22 21:31:01 2007 +0000 @@ -0,0 +1,62 @@ +#!/usr/bin/env python2.4 +# +# DeGAL - A pretty simple web image gallery +# Copyright (C) 2007 Tero Marttila +# http://marttila.de/~terom/degal/ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import shelve +import cgi +import os, os.path + +import inc + +vars = cgi.FieldStorage() + +key = vars['key'].value + +if 'index' in vars : + index = int(vars['index'].value.lstrip('/')) +else : + index = None + +db = shelve.open('shorturls2', 'r') + +try : + type, dirpath, fname = db[key] + + if type == 'img' : + fname += '.html' + elif type == 'dir' : + fname = '' + + if index : + if index > 1 : + fname = 'index_%s.html' % (index - 1) + + dirpath = '../%s' % dirpath + + path = os.path.join(dirpath, fname) + + print "Status: 302" + print "Location: ../%s" % path + print + print "../%s" % path + +finally : + db.close() diff -r adde6ad8731e -r 46536daf9e04 cgi-bin/taggr.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/taggr.py Sat Dec 22 21:31:01 2007 +0000 @@ -0,0 +1,105 @@ +#!/usr/bin/env python2.4 +# +# DeGAL - A pretty simple web image gallery +# Copyright (C) 2007 Tero Marttila +# http://marttila.de/~terom/degal/ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + + +import cgi +import shelve +import os, os.path + +import degal + +images = shelve.open('images', 'c') +tag_images = shelve.open('tag_images', 'c') +tag_tags = shelve.open('tag_tags', 'c') + +# request params +vars = cgi.FieldStorage() + +if 'path' in vars : + path = vars['path'].value +else : + path = '.' + +image_list = [] + +if 'bulk_tag' in vars : + bulk_tags = vars['bulk_tag'].value.split() +else : + bulk_tags = None + +for fname in os.listdir(path) : + if degal.isImage(fname) : + image_path = os.path.join(path, fname) + thumb_path = os.path.join(path, degal.THUMB_DIR, fname) + html_path = image_path + '.html' + + title, descr, tags = images.get(image_path, (None, None, [])) + + if 'img_%s_title' % fname in vars : + title = vars['img_%s_title' % fname].value + + if 'img_%s_descr' % fname in vars : + descr = vars['img_%s_descr' % fname].value + + if 'img_%s_tags' % fname in vars : + tags = vars['img_%s_tags' % fname].value.split() + + if bulk_tags and 'img_%s_chk' % fname in vars : + tags.extend(bulk_tags) + + if title or descr or tags : + images[image_path] = (title, descr, tags) + + html = """ +
  • + +
    +
    +
    +
    + + + + +
  • + """ % dict( + html_path = html_path, + thumb_path = thumb_path, + fname = fname, + title = title and title or '', + descr = descr and descr or '', + tags = tags and ' '.join(tags) or '', + ) + + image_list.append((fname, html)) + +image_list.sort() + +print "Content-Type: text/html" +print +print degal.Template('taggr').render( + TITLE = "Taggr - %s" % path, + BREADCRUMB = "TODO", + CONTENT = "", + PATH = path, +) + diff -r adde6ad8731e -r 46536daf9e04 degal-lighttpd.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/degal-lighttpd.conf Sat Dec 22 21:31:01 2007 +0000 @@ -0,0 +1,16 @@ +# prefix for degal's URLs, no trailing slash +var.degal-url = "/photos" + +# filesystem path to degal, no trailing slash +var.degal-path = "C:/Dokumente und Einstellungen/me/Eigene Dateien/python/degal" + +url.rewrite-once = ( +# "^" + var.degal-url + "/s/([^/]+)(/.*)?$" => var.degal-path + "/shorturl.py?key=$1&index=$2", + "/this" => "/photos/index.html" +# "^/photos/s/([^/]+)(/.*)?$" => "/photos/index.html", # "/shorturl.py?key=$1&index=$2", +# "^" + var.degal-url + "/series/([^/]+)/(.*)$" => var.degal-path + "/series.py?keys=$1&index=$2" +) + +cgi.assign = ( + ".py" => "python" +) diff -r adde6ad8731e -r 46536daf9e04 lib/settings.py --- a/lib/settings.py Sat Dec 22 19:19:05 2007 +0000 +++ b/lib/settings.py Sat Dec 22 21:31:01 2007 +0000 @@ -17,3 +17,6 @@ VERSION = "0.5" ROOT_IGNORE = ('lib', 'templates') + +if __name__ == '__main__' : + print __file__ diff -r adde6ad8731e -r 46536daf9e04 lib/utils.py --- a/lib/utils.py Sat Dec 22 19:19:05 2007 +0000 +++ b/lib/utils.py Sat Dec 22 21:31:01 2007 +0000 @@ -49,13 +49,3 @@ def path_join (*parts) : return os.path.join(*[part for part in parts if part is not None]) - -from optparse import OptionParser - -def optparse (options) : - parser = OptionParser() - - - parser.add_option - - \ No newline at end of file diff -r adde6ad8731e -r 46536daf9e04 templates/gallery.html --- a/templates/gallery.html Sat Dec 22 19:19:05 2007 +0000 +++ b/templates/gallery.html Sat Dec 22 21:31:01 2007 +0000 @@ -52,5 +52,5 @@ ${description}

    -

    ShortURL: ${shorturl_code}

    +

    ShortURL: ${shorturl_code}

    diff -r adde6ad8731e -r 46536daf9e04 www/series.cgi --- a/www/series.cgi Sat Dec 22 19:19:05 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,215 +0,0 @@ -#!/usr/bin/env python2.4 -# -# DeGAL - A pretty simple web image gallery -# Copyright (C) 2007 Tero Marttila -# http://marttila.de/~terom/degal/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the -# Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -import shelve -import cgi -import Cookie -import os, os.path - -import degal - -# -# load request params -# -vars = cgi.FieldStorage() - -# these are interpeted different ways, hence the generic naming -arg1 = vars["keys"].value -if 'index' in vars : - arg2 = vars["index"].value -else : - arg2 = None - -# the cookie with the user's current series -cookie = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE', None)) - -# a special action? -if arg1 and arg1 in ('add', 'del', 'clear', 'view') or arg2 == 'load' : - # load the keys from the cookie - if 'series' in cookie : - keys = cookie["series"].value.split() - else : - keys = [] - - if arg2 == 'load' : - # set the keys in the user's cookie to those in the URL - keys = arg1.split() - - elif arg1 == 'add' and arg2 not in keys : - # add a code to the list of keys - keys.append(arg2) - - elif arg1 == 'del' and arg2 in keys : - # remove a key from the list of keys - keys.remove(arg2) - - elif arg1 == 'clear' : - # clear out the set of keys - keys = [] - - elif arg1 == 'view' : - # just view them - pass - - # set the series cookie value - cookie['series'] = ' '.join(keys) - cookie['series']['path'] = '/' - - # if we have keys, redirect to them, otherwise, back to index we go - if keys : - redirect_to = "../%s/" % ('+'.join(keys)) - else : - redirect_to = "../.." - - # do the redirect - print "Status: 302" - print "Location: %s" % redirect_to - print cookie - print - print "Redirect..." -else : - # we're just viewing - keys = arg1.split() - - # is this "My Series"? - my_series = 'series' in cookie and cookie['series'].value.split() == keys - - if arg2 : - index = int(arg2) - else : - index = None - - # load DB - db = shelve.open('shorturls2', 'r') - - # get the Image objects - photos = [] - - # - # Start ugly code-misreuse - # - - # monkey-patch the templates - rendered_templates = [] - - def _myRenderTo (self, path, **vars) : - rendered_templates.append(self.render(**vars)) - - # lalalalala... ooh, look; - - degal.Template.renderTo = _myRenderTo - # - # vvvvvvvvvvvvvvvvvvvv - # vvvvvvvvvvvvvvvvvvvv - # - # >>>> SHINY PINK ELEPHANT! <<<< - # - # ^^^^^^^^^^^^^^^^^^^^ - # ^^^^^^^^^^^^^^^^^^^^ - - # our own version of Folder - class Series (degal.Folder) : - def __init__ (self) : - super(Series, self).__init__() - - self.alive = True - self.filtered = False - self.subdirs = {} - self.images = {} - self.sorted_images = [] - self.title = "Series" - - if my_series : - self.descr = 'Clear your series' - else : - self.descr = 'Load as your series' - - self.shorturl_code = '' - - def breadcrumb (self) : - return [('../..', 'Gallery'), ('.', 'Series')] - - def inRoot (self, *fnames) : - return os.path.join('../..', *fnames) - - class Image (degal.Image) : - def __init__ (self, series, key, i) : - type, self.dir_name, self.image_name = db[key] - - super(Image, self).__init__(series, self.image_name) - - self.path = self._path() - self.shorturl_code = key - self.html_path = self.html_name = str(i + 1) - self.title = 'Image %d' % (i + 1, ) - self.descr = 'Standalone image: %s' % (self._path(), self._path().lstrip('./')) - self.img_size = (-1, -1) - self.filesize = 0 - self.timestamp = 0 - - if my_series : - self.series_act = "del" - self.series_verb = "Remove from" - else : - self.series_act = self.series_verb = "" - - def breadcrumb (self) : - return [('../..', 'Gallery'), ('.', 'Series'), (self.html_name, self.title)] - - def _path (self, blaa='') : - return os.path.join('../..', self.dir_name, blaa, self.image_name) - - def thumbImgTag (self) : - return degal.link(self.html_name, "%s" % (self._path(degal.THUMB_DIR), '', self.title)) - - def previewImgTag (self) : - return degal.link(self._path(), "%s" % (self._path(degal.PREVIEW_DIR), '', self.title)) - - series = Series() - - try : - prev = None - - for i, key in enumerate(keys) : - img = Image(series, key, i) - - if prev : - prev.next = img - - img.prev = prev - prev = img - - series.sorted_images.append(img) - finally : - db.close() - - if index : - img = series.sorted_images[index - 1] - - img.render() - else : - series.render() - - print "Content-Type: text/html" - print - print rendered_templates[0] - diff -r adde6ad8731e -r 46536daf9e04 www/shorturl.cgi --- a/www/shorturl.cgi Sat Dec 22 19:19:05 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -#!/usr/bin/env python2.4 -# -# DeGAL - A pretty simple web image gallery -# Copyright (C) 2007 Tero Marttila -# http://marttila.de/~terom/degal/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the -# Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - - -import shelve -import cgi -import os, os.path - -vars = cgi.FieldStorage() - -key = vars['key'].value - -if 'index' in vars : - index = int(vars['index'].value.lstrip('/')) -else : - index = None - -db = shelve.open('shorturls2', 'r') - -try : - type, dirpath, fname = db[key] - - if type == 'img' : - fname += '.html' - elif type == 'dir' : - fname = '' - - if index : - if index > 1 : - fname = 'index_%s.html' % (index - 1) - - dirpath = '../%s' % dirpath - - path = os.path.join(dirpath, fname) -finally : - db.close() - -print "Status: 302" -print "Location: ../%s" % path -print -print "../%s" % path - diff -r adde6ad8731e -r 46536daf9e04 www/taggr.cgi --- a/www/taggr.cgi Sat Dec 22 19:19:05 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -#!/usr/bin/env python2.4 -# -# DeGAL - A pretty simple web image gallery -# Copyright (C) 2007 Tero Marttila -# http://marttila.de/~terom/degal/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the -# Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - - -import cgi -import shelve -import os, os.path - -import degal - -images = shelve.open('images', 'c') -tag_images = shelve.open('tag_images', 'c') -tag_tags = shelve.open('tag_tags', 'c') - -# request params -vars = cgi.FieldStorage() - -if 'path' in vars : - path = vars['path'].value -else : - path = '.' - -image_list = [] - -if 'bulk_tag' in vars : - bulk_tags = vars['bulk_tag'].value.split() -else : - bulk_tags = None - -for fname in os.listdir(path) : - if degal.isImage(fname) : - image_path = os.path.join(path, fname) - thumb_path = os.path.join(path, degal.THUMB_DIR, fname) - html_path = image_path + '.html' - - title, descr, tags = images.get(image_path, (None, None, [])) - - if 'img_%s_title' % fname in vars : - title = vars['img_%s_title' % fname].value - - if 'img_%s_descr' % fname in vars : - descr = vars['img_%s_descr' % fname].value - - if 'img_%s_tags' % fname in vars : - tags = vars['img_%s_tags' % fname].value.split() - - if bulk_tags and 'img_%s_chk' % fname in vars : - tags.extend(bulk_tags) - - if title or descr or tags : - images[image_path] = (title, descr, tags) - - html = """ -
  • - -
    -
    -
    -
    - - - - -
  • - """ % dict( - html_path = html_path, - thumb_path = thumb_path, - fname = fname, - title = title and title or '', - descr = descr and descr or '', - tags = tags and ' '.join(tags) or '', - ) - - image_list.append((fname, html)) - -image_list.sort() - -print "Content-Type: text/html" -print -print degal.Template('taggr').render( - TITLE = "Taggr - %s" % path, - BREADCRUMB = "TODO", - CONTENT = "", - PATH = path, -) -