#!/usr/bin/python
"""Bunch of utilities from gagzilla"""
import sys

kDebug = 1

def FatalError(msg):
    """Print the Error mesg and exit."""
    print "Error: " + msg
    sys.exit(0);

def Warning(msg):
    """Print the waring mesg and continue"""
    print "Warning: " + msg

def debug(msg):
    if kDebug: print msg

def firstOrZero(list):
    if len(list) : return list[0]
    else: return 0;

def printFile(file):
    try:
        f = open(file)
        print f.read()
        f.close()
    except IOError:
        pass

def IfElse(a, b, c):
    if a: return b
    else: return c

def PrintTrace(e=None, html=1):
    import traceback
    if html:
        print """<H3>Oops! something bad happened! <br>contact <A
        HREF="mailto:gagan@netscape.com">gagan@netscape.com</A></H3>\n<HR><PRE>"""
        traceback.print_exc()
        print 'Actual exception thrown-\n%s' % e
        print '\n</PRE><HR>\n'
    else:
        traceback.print_exc()
