# HG changeset patch # User terom # Date 1198351145 0 # Node ID adde6ad8731ea9e34a742eb6ea715e123588b4e1 # Parent 980825f2aeedc0f8dce3bbfa7527edd3870c3236 moved css/cgi files to a seperate www/ dir diff -r 980825f2aeed -r adde6ad8731e series.cgi --- a/series.cgi Fri Dec 21 22:14:01 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 980825f2aeed -r adde6ad8731e shorturl.cgi --- a/shorturl.cgi Fri Dec 21 22:14:01 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 980825f2aeed -r adde6ad8731e style.css --- a/style.css Fri Dec 21 22:14:01 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -body { - background-color: #333333; - color: #cccccc; - font-family: "Arial", sans-serif; - font-size: small; -} - -a { - color: #ff8800; - text-decoration: none; -} - -a:hover { - text-decoration: underline; -} - -#thumbnails, #image, #description, h1 { - text-align: center; -} - -#thumbnails img { - margin: 0.2em; -} - -img { - border: 1px solid #666666; -} - -a:focus img { - border: 1px solid #cccccc; -} - -img:hover, a:focus img:hover { - border: 1px solid #ff8800; -} - -div#breadcrumb { - -} - -div#info { - font-size: x-small; - color: #666666; -} - -div#info p { - padding: 0px; - margin: 0px; -} - -p#about { - padding-top: 50px; - font-size: xx-small; - text-align: center; - -} - -div.paginate { - padding-top: 20px; - height: 50px; - width: 100%; - text-align: center; -} - -div.paginate ul { - margin: 0px; - padding: 0px; - - line-height: 30px; - white-space: nowrap; -} - -div.paginate li { - list-style-type: none; - display: inline; -} - -div.paginate li *, -div.paginate li strong, -div.paginate li span { - padding: 7px 10px; -} - -div.paginate li span { - color: #444444; -} - -div.paginate li a:hover { - text-decoration: none; - background-color: #666666; -} - -div#taggr { - border: 1px solid #666666; - - padding: 20px; -} - -div#taggr ul { - margin: 0px; - padding: 0px; -} - -div#taggr li { - border-bottom: 1px solid #444444; - - padding: 10px; - - list-style-type: none; - - text-align: center; -} - -div#tagger span.thumb { - clear: both; -} - -div#taggr span.inputs { - float: right; -} - -div#taggr input { - margin: 5px; -} - -div#taggr label { - float: left; - - width: 150px; -} - -div#taggr input.chk { - float: left; - - width: 30px; - height: 30px; - - border: 1px solid #000000; - - margin: auto; -} - - diff -r 980825f2aeed -r adde6ad8731e taggr.cgi --- a/taggr.cgi Fri Dec 21 22:14:01 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, -) - diff -r 980825f2aeed -r adde6ad8731e www/series.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/series.cgi Sat Dec 22 19:19:05 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 980825f2aeed -r adde6ad8731e www/shorturl.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/shorturl.cgi Sat Dec 22 19:19:05 2007 +0000 @@ -0,0 +1,61 @@ +#!/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 980825f2aeed -r adde6ad8731e www/style.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/style.css Sat Dec 22 19:19:05 2007 +0000 @@ -0,0 +1,143 @@ +body { + background-color: #333333; + color: #cccccc; + font-family: "Arial", sans-serif; + font-size: small; +} + +a { + color: #ff8800; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +#thumbnails, #image, #description, h1 { + text-align: center; +} + +#thumbnails img { + margin: 0.2em; +} + +img { + border: 1px solid #666666; +} + +a:focus img { + border: 1px solid #cccccc; +} + +img:hover, a:focus img:hover { + border: 1px solid #ff8800; +} + +div#breadcrumb { + +} + +div#info { + font-size: x-small; + color: #666666; +} + +div#info p { + padding: 0px; + margin: 0px; +} + +p#about { + padding-top: 50px; + font-size: xx-small; + text-align: center; + +} + +div.paginate { + padding-top: 20px; + height: 50px; + width: 100%; + text-align: center; +} + +div.paginate ul { + margin: 0px; + padding: 0px; + + line-height: 30px; + white-space: nowrap; +} + +div.paginate li { + list-style-type: none; + display: inline; +} + +div.paginate li *, +div.paginate li strong, +div.paginate li span { + padding: 7px 10px; +} + +div.paginate li span { + color: #444444; +} + +div.paginate li a:hover { + text-decoration: none; + background-color: #666666; +} + +div#taggr { + border: 1px solid #666666; + + padding: 20px; +} + +div#taggr ul { + margin: 0px; + padding: 0px; +} + +div#taggr li { + border-bottom: 1px solid #444444; + + padding: 10px; + + list-style-type: none; + + text-align: center; +} + +div#tagger span.thumb { + clear: both; +} + +div#taggr span.inputs { + float: right; +} + +div#taggr input { + margin: 5px; +} + +div#taggr label { + float: left; + + width: 150px; +} + +div#taggr input.chk { + float: left; + + width: 30px; + height: 30px; + + border: 1px solid #000000; + + margin: auto; +} + + diff -r 980825f2aeed -r adde6ad8731e www/taggr.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/taggr.cgi Sat Dec 22 19:19:05 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, +) +