terom@14: # DeGAL - A pretty simple web image gallery terom@14: # Copyright (C) 2007 Tero Marttila terom@14: # http://marttila.de/~terom/degal/ terom@14: # terom@14: # This program is free software; you can redistribute it and/or modify terom@14: # it under the terms of the GNU General Public License as published by terom@14: # the Free Software Foundation; either version 2 of the License, or terom@14: # (at your option) any later version. terom@14: # terom@14: # This program is distributed in the hope that it will be useful, terom@14: # but WITHOUT ANY WARRANTY; without even the implied warranty of terom@14: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terom@14: # GNU General Public License for more details. terom@14: # terom@14: # You should have received a copy of the GNU General Public License terom@14: # along with this program; if not, write to the terom@14: # Free Software Foundation, Inc., terom@14: # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. terom@14: # terom@14: terom@28: import logging, sys terom@12: terom@28: log_level = logging.INFO terom@28: stack = [] terom@12: terom@28: class g : terom@28: out_depth = 0 terom@28: node = None terom@12: terom@28: def title (title, *args) : terom@28: stack.append(title) terom@15: terom@29: print "%s - %s" % (" "*g.out_depth, title % args) terom@28: terom@28: g.out_depth += 1 terom@28: terom@28: def down (dir_name, *args) : terom@28: stack.append(dir_name % args) terom@28: g.node = None terom@28: terom@28: def next (fname, *args) : terom@28: g.node = fname % args terom@28: terom@28: def up () : terom@28: stack.pop(-1) terom@28: g.node = None terom@28: g.out_depth = min(g.out_depth, len(stack)) terom@28: terom@28: def done () : terom@28: print "done" terom@28: terom@28: def log (level, message, *args, **kwargs) : terom@28: wait = kwargs.get("wait", False) terom@28: terom@28: if level >= log_level : terom@28: if g.out_depth != len(stack) : terom@28: for segment in stack[g.out_depth:] : terom@28: print "%sd %s" % (" "*g.out_depth, segment) terom@28: g.out_depth += 1 terom@28: terom@30: if g.node : terom@30: print "%sf %s" % (" "*g.out_depth, g.node) terom@30: g.node = None terom@28: terom@28: if wait : terom@29: print "%s - %s..." % (" "*g.out_depth, message % args), terom@28: sys.stdout.flush() terom@28: else : terom@29: print "%s - %s" % (" "*g.out_depth, message % args) terom@28: terom@28: def _level (level) : terom@28: def _log_func (message, *args, **kwargs) : terom@28: log(level, message, *args, **kwargs) terom@28: terom@28: return _log_func terom@28: terom@28: debug = _level(logging.DEBUG) terom@28: info = _level(logging.INFO) terom@28: warning = _level(logging.WARNING) terom@28: error = _level(logging.ERROR) terom@28: