degal.py
author terom
Fri, 21 Dec 2007 20:36:03 +0000
changeset 12 c2d8e9a754a1
parent 11 27dac27d1a58
child 24 001f52cd057e
permissions -rwxr-xr-x
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     1
#!/usr/bin/env python2.4
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     2
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     3
# DeGAL - A pretty simple web image gallery
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     4
# Copyright (C) 2007 Tero Marttila
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     5
# http://marttila.de/~terom/degal/
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     6
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     7
# This program is free software; you can redistribute it and/or modify
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     8
# it under the terms of the GNU General Public License as published by
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     9
# the Free Software Foundation; either version 2 of the License, or
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    10
# (at your option) any later version.
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    11
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    12
# This program is distributed in the hope that it will be useful,
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    15
# GNU General Public License for more details.
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    16
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    18
# along with this program; if not, write to the
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    19
# Free Software Foundation, Inc.,
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    20
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    21
#
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    22
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    23
import os.path, os
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: 11
diff changeset
    24
from optparse import OptionParser
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    25
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: 11
diff changeset
    26
from lib import folder, shorturl
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    27
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: 11
diff changeset
    28
def main (dir='.', targets=()) :
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    29
    root_filter = {}
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    30
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    31
    for target in targets :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    32
        f = root_filter
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    33
        for path_part in target.split('/') :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    34
            if path_part :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    35
                if path_part not in f :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    36
                    f[path_part] = {}
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: 11
diff changeset
    37
                    
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    38
                f = f[path_part]
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    39
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: 11
diff changeset
    40
    root = folder.Folder(dir)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    41
    root.index(root_filter)
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: 11
diff changeset
    42
    shorturl.updateDB(root)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    43
    root.render()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    44
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    45
if __name__ == '__main__' :
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: 11
diff changeset
    46
    parser = OptionParser(usage="usage: %prog [options] ... [target ...]")
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: 11
diff changeset
    47
    
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: 11
diff changeset
    48
    parser.add_option("-d", "--dir", dest="dir", help="look for images in DIR and write the HTML there", metavar="DIR", default=".")
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: 11
diff changeset
    49
    
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: 11
diff changeset
    50
    options, filter_targets = parser.parse_args()
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: 11
diff changeset
    51
    
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: 11
diff changeset
    52
    main(options.dir, filter_targets)