1 #!/usr/bin/env python2.4 |
|
2 # |
|
3 # DeGAL - A pretty simple web image gallery |
|
4 # Copyright (C) 2007 Tero Marttila |
|
5 # http://marttila.de/~terom/degal/ |
|
6 # |
|
7 # This program is free software; you can redistribute it and/or modify |
|
8 # it under the terms of the GNU General Public License as published by |
|
9 # the Free Software Foundation; either version 2 of the License, or |
|
10 # (at your option) any later version. |
|
11 # |
|
12 # This program is distributed in the hope that it will be useful, |
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 # GNU General Public License for more details. |
|
16 # |
|
17 # You should have received a copy of the GNU General Public License |
|
18 # along with this program; if not, write to the |
|
19 # Free Software Foundation, Inc., |
|
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 # |
|
22 |
|
23 import shelve |
|
24 import cgi |
|
25 import os, os.path |
|
26 |
|
27 import inc |
|
28 |
|
29 vars = cgi.FieldStorage() |
|
30 |
|
31 key = vars['key'].value |
|
32 |
|
33 if 'index' in vars : |
|
34 index = int(vars['index'].value.lstrip('/')) |
|
35 else : |
|
36 index = None |
|
37 |
|
38 db = shelve.open('shorturls2', 'r') |
|
39 |
|
40 try : |
|
41 type, dirpath, fname = db[key] |
|
42 |
|
43 if type == 'img' : |
|
44 fname += '.html' |
|
45 elif type == 'dir' : |
|
46 fname = '' |
|
47 |
|
48 if index : |
|
49 if index > 1 : |
|
50 fname = 'index_%s.html' % (index - 1) |
|
51 |
|
52 dirpath = '../%s' % dirpath |
|
53 |
|
54 path = os.path.join(dirpath, fname) |
|
55 |
|
56 print "Status: 302" |
|
57 print "Location: ../%s" % path |
|
58 print |
|
59 print "../%s" % path |
|
60 |
|
61 finally : |
|
62 db.close() |
|