degal.py
author terom
Thu, 31 Jan 2008 19:13:00 +0000
changeset 28 70b6c13d084f
parent 27 301d738b1181
permissions -rwxr-xr-x
fancy new log format
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 12
diff changeset
     1
#!/usr/bin/env python2.5
1
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
28
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    26
from lib import folder, shorturl, log
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 = {}
27
301d738b1181 fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
terom
parents: 24
diff changeset
    30
    
1
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]
28
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    39
    
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    40
    log.title("Indexing %s...", dir)
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
    41
    root = folder.Folder(dir)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    42
    root.index(root_filter)
28
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    43
    log.up()
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    44
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    45
    log.title("Syncing ShortURLs...")
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
    shorturl.updateDB(root)
28
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    47
    log.up()
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    48
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    49
    log.title("Rendering updated dirs...")
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    50
    root.render()
28
70b6c13d084f fancy new log format
terom
parents: 27
diff changeset
    51
    log.up()
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    52
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    53
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
    54
    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
    55
    
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
    56
    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
    57
    
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
    58
    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
    59
    
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
    60
    main(options.dir, filter_targets)