#!/usr/bin/python
#
# $Id: debug.py,v 1.2 2009-12-02 14:46:44 jloden Exp $
#

import sys

class Debug(object):
    def __init__(self):
        self.TVDEBUG = False

    def setDebug(self, val=None):
        if val is None: # if it's none, then just toggle our current value
            if self.TVDEBUG:
                self.TVDEBUG = False
                return
            else:
                self.TVDEBUG = True
                return
        # else just assign the truthiness of val to TVDEBUG
        self.TVDEBUG = bool(val)

    def getDebug(self):
        return self.TVDEBUG

    def debug(self, errstr):
        """Print a DEBUG message to stdout."""
        if self.getDebug():
            sys.stdout.write("DEBUG: %s\n" % (errstr))

    def error(self, errstr):
        """Print an ERROR message to stderr."""
        sys.stderr.write("ERROR: %s\n" % (errstr))

    def info(self, errstr):
        """Print an INFO message to stdout."""
        sys.stdout.write("INFO: %s\n" % (errstr))

tvdebug = Debug()

