|
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 |
|
24 import shelve |
|
25 import cgi |
|
26 import os, os.path |
|
27 |
|
28 vars = cgi.FieldStorage() |
|
29 |
|
30 key = vars['key'].value |
|
31 |
|
32 if 'index' in vars : |
|
33 index = int(vars['index'].value.lstrip('/')) |
|
34 else : |
|
35 index = None |
|
36 |
|
37 db = shelve.open('shorturls2', 'r') |
|
38 |
|
39 try : |
|
40 type, dirpath, fname = db[key] |
|
41 |
|
42 if type == 'img' : |
|
43 fname += '.html' |
|
44 elif type == 'dir' : |
|
45 fname = '' |
|
46 |
|
47 if index : |
|
48 if index > 1 : |
|
49 fname = 'index_%s.html' % (index - 1) |
|
50 |
|
51 dirpath = '../%s' % dirpath |
|
52 |
|
53 path = os.path.join(dirpath, fname) |
|
54 finally : |
|
55 db.close() |
|
56 |
|
57 print "Status: 302" |
|
58 print "Location: ../%s" % path |
|
59 print |
|
60 print "../%s" % path |
|
61 |