author | terom |
Sat, 22 Dec 2007 21:31:01 +0000 | |
changeset 18 | 46536daf9e04 |
parent 17 | www/shorturl.cgi@adde6ad8731e |
permissions | -rwxr-xr-x |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
1 |
#!/usr/bin/env python2.4 |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
2 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
3 |
# DeGAL - A pretty simple web image gallery |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
4 |
# Copyright (C) 2007 Tero Marttila |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
5 |
# http://marttila.de/~terom/degal/ |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
6 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
7 |
# This program is free software; you can redistribute it and/or modify |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
8 |
# it under the terms of the GNU General Public License as published by |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
9 |
# the Free Software Foundation; either version 2 of the License, or |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
10 |
# (at your option) any later version. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
11 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
12 |
# This program is distributed in the hope that it will be useful, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
15 |
# GNU General Public License for more details. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
16 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
17 |
# You should have received a copy of the GNU General Public License |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
18 |
# along with this program; if not, write to the |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
19 |
# Free Software Foundation, Inc., |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
20 |
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
21 |
# |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
9
diff
changeset
|
22 |
|
2 | 23 |
import shelve |
1 | 24 |
import cgi |
25 |
import os, os.path |
|
26 |
||
18
46536daf9e04
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
terom
parents:
17
diff
changeset
|
27 |
import inc |
46536daf9e04
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
terom
parents:
17
diff
changeset
|
28 |
|
1 | 29 |
vars = cgi.FieldStorage() |
30 |
||
31 |
key = vars['key'].value |
|
6
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
32 |
|
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
33 |
if 'index' in vars : |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
34 |
index = int(vars['index'].value.lstrip('/')) |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
35 |
else : |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
36 |
index = None |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
37 |
|
2 | 38 |
db = shelve.open('shorturls2', 'r') |
1 | 39 |
|
40 |
try : |
|
2 | 41 |
type, dirpath, fname = db[key] |
42 |
||
9
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
43 |
if type == 'img' : |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
44 |
fname += '.html' |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
45 |
elif type == 'dir' : |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
46 |
fname = '' |
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
47 |
|
6
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
48 |
if index : |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
49 |
if index > 1 : |
9
a0a13d5e406c
ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents:
6
diff
changeset
|
50 |
fname = 'index_%s.html' % (index - 1) |
5
156cdfffef8e
fix shorturls to dirs, and a new feature: pagination for index pages
terom
parents:
3
diff
changeset
|
51 |
|
6
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
52 |
dirpath = '../%s' % dirpath |
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
53 |
|
d9d1f8e5f384
fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents:
5
diff
changeset
|
54 |
path = os.path.join(dirpath, fname) |
18
46536daf9e04
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
terom
parents:
17
diff
changeset
|
55 |
|
46536daf9e04
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
terom
parents:
17
diff
changeset
|
56 |
print "Status: 302" |
46536daf9e04
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
terom
parents:
17
diff
changeset
|
57 |
print "Location: ../%s" % path |
46536daf9e04
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
terom
parents:
17
diff
changeset
|
58 |
|
46536daf9e04
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
terom
parents:
17
diff
changeset
|
59 |
print "../%s" % path |
46536daf9e04
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
terom
parents:
17
diff
changeset
|
60 |
|
1 | 61 |
finally : |
62 |
db.close() |