|
1 #!/usr/bin/env python2.5 |
|
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 import os.path, os |
|
24 from optparse import OptionParser |
|
25 |
|
26 from lib import folder, shorturl, log |
|
27 |
|
28 def main (dir='.', targets=()) : |
|
29 root_filter = {} |
|
30 |
|
31 for target in targets : |
|
32 f = root_filter |
|
33 for path_part in target.split('/') : |
|
34 if path_part : |
|
35 if path_part not in f : |
|
36 f[path_part] = {} |
|
37 |
|
38 f = f[path_part] |
|
39 |
|
40 log.title("Indexing %s...", dir) |
|
41 root = folder.Folder(dir) |
|
42 root.index(root_filter) |
|
43 log.up() |
|
44 |
|
45 log.title("Syncing ShortURLs...") |
|
46 shorturl.updateDB(root) |
|
47 log.up() |
|
48 |
|
49 log.title("Rendering updated dirs...") |
|
50 root.render() |
|
51 log.up() |
|
52 |
|
53 if __name__ == '__main__' : |
|
54 parser = OptionParser(usage="usage: %prog [options] ... [target ...]") |
|
55 |
|
56 parser.add_option("-d", "--dir", dest="dir", help="look for images in DIR and write the HTML there", metavar="DIR", default=".") |
|
57 |
|
58 options, filter_targets = parser.parse_args() |
|
59 |
|
60 main(options.dir, filter_targets) |