2003-07-04 14:24:44 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2004-01-03 14:59:33 +00:00
|
|
|
# Copyright (C) 2000-2004 Bastian Kleineidam
|
2003-01-11 12:38:18 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2004-04-03 18:10:38 +00:00
|
|
|
import sys, os
|
2003-01-08 20:08:43 +00:00
|
|
|
|
|
|
|
|
# debug level constants (Quake-style)
|
|
|
|
|
ALWAYS = 0
|
|
|
|
|
BRING_IT_ON = 1
|
|
|
|
|
HURT_ME_PLENTY = 2
|
|
|
|
|
NIGHTMARE = 3
|
|
|
|
|
|
|
|
|
|
# the global debug level
|
|
|
|
|
_debuglevel = 0
|
|
|
|
|
|
|
|
|
|
def get_debuglevel ():
|
|
|
|
|
return _debuglevel
|
|
|
|
|
|
2004-04-03 18:10:38 +00:00
|
|
|
|
2003-01-08 20:08:43 +00:00
|
|
|
def set_debuglevel (i):
|
2003-12-29 19:12:33 +00:00
|
|
|
if i>=NIGHTMARE:
|
|
|
|
|
import gc
|
|
|
|
|
gc.set_debug(gc.DEBUG_LEAK)
|
2003-01-08 20:08:43 +00:00
|
|
|
global _debuglevel
|
|
|
|
|
_debuglevel = i
|
|
|
|
|
|
2004-04-03 18:10:38 +00:00
|
|
|
|
2003-01-08 20:08:43 +00:00
|
|
|
from AnsiColor import colorize
|
|
|
|
|
|
|
|
|
|
def _text (*args, **kwargs):
|
|
|
|
|
text = " ".join(map(str, args))
|
|
|
|
|
print >>sys.stderr, colorize(text, color=kwargs.get('color'))
|
|
|
|
|
|
2004-01-28 09:03:11 +00:00
|
|
|
# memory leak debugging
|
|
|
|
|
#import gc, os
|
|
|
|
|
#gc.set_debug(gc.DEBUG_LEAK)
|
|
|
|
|
|
2003-01-08 20:08:43 +00:00
|
|
|
# debug function, using the debug level
|
|
|
|
|
def debug (level, *args):
|
|
|
|
|
if level <= _debuglevel:
|
2004-05-26 23:48:28 +00:00
|
|
|
_text("DEBUG", *args)
|
2003-01-08 20:08:43 +00:00
|
|
|
|
2004-01-28 09:03:11 +00:00
|
|
|
|
2003-01-08 20:08:43 +00:00
|
|
|
def info (*args):
|
2004-05-26 23:48:28 +00:00
|
|
|
_text("INFO", *args, **{'color':'default'})
|
2003-01-08 20:08:43 +00:00
|
|
|
|
2004-04-03 18:10:38 +00:00
|
|
|
|
2003-01-08 20:08:43 +00:00
|
|
|
def warn (*args):
|
2004-05-26 23:48:28 +00:00
|
|
|
_text("WARN", *args, **{'color':'bold;yellow'})
|
2003-01-08 20:08:43 +00:00
|
|
|
|
2004-04-03 18:10:38 +00:00
|
|
|
|
2003-01-08 20:08:43 +00:00
|
|
|
def error (*args):
|
2004-05-26 23:48:28 +00:00
|
|
|
_text("ERROR", *args, **{'color':'bold;red'})
|