shorturl.cgi
author terom
Fri, 21 Dec 2007 22:14:01 +0000
changeset 16 980825f2aeed
parent 12 c2d8e9a754a1
permissions -rwxr-xr-x
fix settings.IMAGE_COUNT back to 50, and fix image.html to link to the raw image, not itself
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
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    23
2
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    24
import shelve
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    25
import cgi
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    26
import os, os.path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    27
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    28
vars = cgi.FieldStorage()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    29
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    30
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
    31
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    32
if 'index' in vars :
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    33
    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
    34
else :
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    35
    index = None
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    36
2
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    37
db = shelve.open('shorturls2', 'r')
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    38
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    39
try :
2
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    40
    type, dirpath, fname = db[key]
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    41
9
a0a13d5e406c ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents: 6
diff changeset
    42
    if type == 'img' :
a0a13d5e406c ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents: 6
diff changeset
    43
        fname += '.html'
a0a13d5e406c ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents: 6
diff changeset
    44
    elif type == 'dir' :
a0a13d5e406c ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents: 6
diff changeset
    45
        fname = ''
a0a13d5e406c ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents: 6
diff changeset
    46
6
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    47
    if index :
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    48
        if index > 1 : 
9
a0a13d5e406c ShortURLs for dirs without page numbers were broken, as fname was 'index'
terom
parents: 6
diff changeset
    49
            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
    50
6
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    51
        dirpath = '../%s' % dirpath
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    52
d9d1f8e5f384 fix alignment of teh paginator, and make shorturl dirs better (no index.html + pagination)
terom
parents: 5
diff changeset
    53
    path = os.path.join(dirpath, fname)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    54
finally :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    55
    db.close()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    56
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    57
print "Status: 302"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    58
print "Location: ../%s" % path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    59
print
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    60
print "../%s" % path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    61