author | terom |
Thu, 31 Jan 2008 19:13:00 +0000 | |
changeset 28 | 70b6c13d084f |
parent 27 | 301d738b1181 |
child 29 | 990300aa8010 |
permissions | -rw-r--r-- |
14
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
1 |
# DeGAL - A pretty simple web image gallery |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
2 |
# Copyright (C) 2007 Tero Marttila |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
3 |
# http://marttila.de/~terom/degal/ |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
4 |
# |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
5 |
# This program is free software; you can redistribute it and/or modify |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
6 |
# it under the terms of the GNU General Public License as published by |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
7 |
# the Free Software Foundation; either version 2 of the License, or |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
8 |
# (at your option) any later version. |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
9 |
# |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
10 |
# This program is distributed in the hope that it will be useful, |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
13 |
# GNU General Public License for more details. |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
14 |
# |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
15 |
# You should have received a copy of the GNU General Public License |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
16 |
# along with this program; if not, write to the |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
17 |
# Free Software Foundation, Inc., |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
18 |
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
19 |
# |
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
20 |
|
28 | 21 |
import logging, sys |
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:
diff
changeset
|
22 |
|
28 | 23 |
log_level = logging.INFO |
24 |
stack = [] |
|
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:
diff
changeset
|
25 |
|
28 | 26 |
class g : |
27 |
out_depth = 0 |
|
28 |
node = None |
|
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:
diff
changeset
|
29 |
|
28 | 30 |
def title (title, *args) : |
31 |
stack.append(title) |
|
15
0fe851a29bc6
detool.py, meant to be a collection of utility operations, currently lets you move images and their html/thumb/preview files at the same time
terom
parents:
14
diff
changeset
|
32 |
|
28 | 33 |
print "%s- %s" % (" "*g.out_depth, title % args) |
34 |
||
35 |
g.out_depth += 1 |
|
36 |
||
37 |
def down (dir_name, *args) : |
|
38 |
stack.append(dir_name % args) |
|
39 |
g.node = None |
|
40 |
||
41 |
def next (fname, *args) : |
|
42 |
g.node = fname % args |
|
43 |
||
44 |
def up () : |
|
45 |
stack.pop(-1) |
|
46 |
g.node = None |
|
47 |
g.out_depth = min(g.out_depth, len(stack)) |
|
48 |
||
49 |
def done () : |
|
50 |
print "done" |
|
51 |
||
52 |
def log (level, message, *args, **kwargs) : |
|
53 |
wait = kwargs.get("wait", False) |
|
54 |
||
55 |
if level >= log_level : |
|
56 |
if g.out_depth != len(stack) : |
|
57 |
for segment in stack[g.out_depth:] : |
|
58 |
print "%sd %s" % (" "*g.out_depth, segment) |
|
59 |
g.out_depth += 1 |
|
60 |
||
61 |
if g.node : |
|
62 |
print "%sf %s" % (" "*g.out_depth, g.node) |
|
63 |
g.node = None |
|
64 |
||
65 |
if wait : |
|
66 |
print "%s- %s..." % (" "*g.out_depth, message % args), |
|
67 |
sys.stdout.flush() |
|
68 |
else : |
|
69 |
print "%s- %s" % (" "*g.out_depth, message % args) |
|
70 |
||
71 |
def _level (level) : |
|
72 |
def _log_func (message, *args, **kwargs) : |
|
73 |
log(level, message, *args, **kwargs) |
|
74 |
||
75 |
return _log_func |
|
76 |
||
77 |
debug = _level(logging.DEBUG) |
|
78 |
info = _level(logging.INFO) |
|
79 |
warning = _level(logging.WARNING) |
|
80 |
error = _level(logging.ERROR) |
|
81 |