author | Tero Marttila <terom@fixme.fi> |
Wed, 03 Jun 2009 19:23:10 +0300 | |
branch | use-distutils |
changeset 44 | 533b7e8b5d3b |
parent 41 | 3b1579a7bffb |
permissions | -rw-r--r-- |
44
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
1 |
import logging, sys |
14
4b5478da5850
remove hanging utils.py in root, and add GPL license header to all .py files
terom
parents:
12
diff
changeset
|
2 |
|
44
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
3 |
""" |
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
4 |
Fancy tree-structured logging output |
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
5 |
""" |
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
|
6 |
|
28 | 7 |
log_level = logging.INFO |
8 |
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
|
9 |
|
28 | 10 |
class g : |
11 |
out_depth = 0 |
|
12 |
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
|
13 |
|
28 | 14 |
def title (title, *args) : |
15 |
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
|
16 |
|
29 | 17 |
print "%s - %s" % (" "*g.out_depth, title % args) |
28 | 18 |
|
19 |
g.out_depth += 1 |
|
20 |
||
21 |
def down (dir_name, *args) : |
|
22 |
stack.append(dir_name % args) |
|
23 |
g.node = None |
|
24 |
||
25 |
def next (fname, *args) : |
|
26 |
g.node = fname % args |
|
27 |
||
28 |
def up () : |
|
29 |
stack.pop(-1) |
|
30 |
g.node = None |
|
31 |
g.out_depth = min(g.out_depth, len(stack)) |
|
32 |
||
33 |
def done () : |
|
34 |
print "done" |
|
35 |
||
36 |
def log (level, message, *args, **kwargs) : |
|
37 |
wait = kwargs.get("wait", False) |
|
38 |
||
39 |
if level >= log_level : |
|
40 |
if g.out_depth != len(stack) : |
|
41 |
for segment in stack[g.out_depth:] : |
|
42 |
print "%sd %s" % (" "*g.out_depth, segment) |
|
43 |
g.out_depth += 1 |
|
44 |
||
30 | 45 |
if g.node : |
46 |
print "%sf %s" % (" "*g.out_depth, g.node) |
|
47 |
g.node = None |
|
28 | 48 |
|
49 |
if wait : |
|
29 | 50 |
print "%s - %s..." % (" "*g.out_depth, message % args), |
28 | 51 |
sys.stdout.flush() |
52 |
else : |
|
29 | 53 |
print "%s - %s" % (" "*g.out_depth, message % args) |
28 | 54 |
|
55 |
def _level (level) : |
|
56 |
def _log_func (message, *args, **kwargs) : |
|
57 |
log(level, message, *args, **kwargs) |
|
58 |
||
59 |
return _log_func |
|
60 |
||
61 |
debug = _level(logging.DEBUG) |
|
62 |
info = _level(logging.INFO) |
|
63 |
warning = _level(logging.WARNING) |
|
64 |
error = _level(logging.ERROR) |
|
65 |