terom@12: #!/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@2: import shelve terom@1: import cgi terom@1: import os, os.path terom@1: terom@18: import inc terom@18: terom@1: vars = cgi.FieldStorage() terom@1: terom@1: key = vars['key'].value terom@6: terom@6: if 'index' in vars : terom@6: index = int(vars['index'].value.lstrip('/')) terom@6: else : terom@6: index = None terom@6: terom@2: db = shelve.open('shorturls2', 'r') terom@1: terom@1: try : terom@2: type, dirpath, fname = db[key] terom@2: terom@9: if type == 'img' : terom@9: fname += '.html' terom@9: elif type == 'dir' : terom@9: fname = '' terom@9: terom@6: if index : terom@6: if index > 1 : terom@9: fname = 'index_%s.html' % (index - 1) terom@5: terom@6: dirpath = '../%s' % dirpath terom@6: terom@6: path = os.path.join(dirpath, fname) terom@18: terom@18: print "Status: 302" terom@18: print "Location: ../%s" % path terom@18: print terom@18: print "../%s" % path terom@18: terom@1: finally : terom@1: db.close()