Added logic to more cleanly handle long error and debug messages.
1 parent f6d7f74 commit bf8e36ae630d85e817365d25983473d45bfd5ab6
@tundra tundra authored on 27 Jan 2010
Showing 1 changed file
View
58
tren.py
# Program Information
 
PROGNAME = "tren.py"
PROGENV = PROGNAME.split(".py")[0].upper()
RCSID = "$Id: tren.py,v 1.112 2010/01/26 23:02:40 tundra Exp $"
RCSID = "$Id: tren.py,v 1.113 2010/01/27 17:34:57 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
 
 
 
#####
# Constants
# General Program Constants
#####
 
MAXINCLUDES = 50 # Maximum number of includes allowed
 
 
#####
# Message Formatting Constants
#####
 
# Make sure these make sense: MAXLINELEN > PADWIDTH + WRAPINDENT
# because of the way line conditioning/wrap works.
 
MAXLINELEN = 75 # Maximum length of printed line
PADCHAR = " " # Padding character
PADWIDTH = 30 # Column width
WRAPINDENT = 8 # Extra indent on wrapped lines
 
 
#####
# Literals
#####
eTOOMANYINC = "Too Many Includes! (Max Is %d) Possible Circular Reference?" % MAXINCLUDES
 
 
#####
# Informational Messages
# Warning Messages
#####
 
 
#####
#####
# Turn A List Into Columns With Space Padding
#####
 
def ColumnPad(list, padchar=" ", padwidth=PADWIDTH):
def ColumnPad(list, padchar=PADCHAR, padwidth=PADWIDTH):
 
retval = ""
for l in list:
l = str(l)
# End of 'ColumnPad()'
 
 
#####
# Condition Line Length With Fancy Wrap And Formatting
#####
 
def ConditionLine(msg,
padchar=PADCHAR, \
padwidth=PADWIDTH, \
wrapindent=WRAPINDENT, \
maxlinelen=MAXLINELEN):
 
retval = []
 
retval.append(msg[:maxlinelen])
msg = msg[maxlinelen:]
 
while msg:
msg = padchar * (padwidth + wrapindent) + msg
retval.append(msg[:maxlinelen])
msg = msg[maxlinelen:]
 
return retval
 
# End of 'ConditionLine()'
 
 
#####
# Print A Debug Message
#####
 
def DebugMsg(msg):
PrintStderr(PROGNAME + " " + VERSION + " " + dDEBUG + ": " + msg)
l = ConditionLine(msg)
for msg in l:
PrintStderr(PROGNAME + " " + VERSION + " " + dDEBUG + ": " + msg)
 
# End of 'DebugMsg()'
 
 
# Print An Error Message
#####
 
def ErrorMsg(emsg):
PrintStderr(PROGNAME + " " + VERSION + " " + eERROR + ": " + emsg)
l = ConditionLine(emsg)
for emsg in l:
PrintStderr(PROGNAME + " " + VERSION + " " + eERROR + ": " + emsg)
 
# End of 'ErrorMsg()'