Cleanup of debug structure and logic.
1 parent 392d975 commit 0f39b75dca3c5b5517fd4e72af95333f966f2a90
@tundra tundra authored on 25 Jan 2010
Showing 1 changed file
View
61
tren.py
 
# Program Information
 
PROGNAME = "tren.py"
RCSID = "$Id: tren.py,v 1.108 2010/01/25 22:21:26 tundra Exp $"
PROGENV = PROGNAME.split(".py")[0].upper()
RCSID = "$Id: tren.py,v 1.109 2010/01/25 23:23:30 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
# Constants
#####
 
MAXINCLUDES = 50 # Maximum number of includes allowed
 
PADWIDTH = 30 # Column width
 
#####
# Literals
#####
#####
# Debug Messages
#####
 
dDEBUG = "DEBUG"
DEBUGFLAG = "-d"
dCMDLINE = "Command Line"
dDEBUG = "DEBUG"
dPAIR = "Option/Target Pair"
dPROGENV = "$" + PROGENV
dRESOLVEDOPTS = "Resolved Command Line"
 
 
#####
# Error Messages
#####
#####
# Turn A List Into Columns With Space Padding
#####
 
def ColumnPad(list, padchar=" ", padwidth=20):
def ColumnPad(list, padchar=" ", padwidth=PADWIDTH):
 
retval = ""
for l in list:
l = str(l)
# Dump The State Of The Program
#####
 
def DumpState():
 
# Dump the command line
DebugMsg(ColumnPad(["Command Line", sys.argv]))
DebugMsg(ColumnPad(["$TREN", os.getenv("TREN")]))
DebugMsg(ColumnPad(["Resolved Options", OPTIONS]))
 
# Names of all the state variables we want dumped
state = [
"DEBUG",
 
 
OPTIONS = sys.argv[1:]
 
envopt = os.getenv(PROGNAME.split(".py")[0].upper())
envopt = os.getenv(PROGENV)
if envopt:
OPTIONS = envopt.split() + OPTIONS
 
# Resolve include file references allowing for nested includes.
except IOError as e:
ErrorMsg(eFILEOPEN % (file, e.args[1]))
sys.exit(1)
 
# We also need to detect a request for debugging now
# so we don't have to wait for getopt to parse it
# to begin seeing debugging output
 
if DEBUGFLAG in OPTIONS:
DEBUG = True
while DEBUGFLAG in OPTIONS:
OPTIONS.remove(DEBUGFLAG)
 
# Break command line into "option ... targets ..." pairs.
 
 
options = OPTIONS # Save for later
DOINGOPTS = True
cmd = []
 
while OPTIONS:
 
if cmd:
COMMANDLINES.append(cmd)
 
 
 
if DEBUG:
 
# Dump what we know about the command line
 
DebugMsg(ColumnPad([dCMDLINE, sys.argv]))
DebugMsg(ColumnPad([dPROGENV, os.getenv("TREN")]))
DebugMsg(ColumnPad([dRESOLVEDOPTS, options]))
 
 
# Now process the command line in "opts... targets" pairs
 
for commandline in COMMANDLINES:
if DEBUG:
DebugMsg(ColumnPad([dPAIR, " ".join(commandline)]))
 
try:
opts, args = getopt.getopt(commandline, '1abbCcdEefghl:qr:tvXx]')
opts, args = getopt.getopt(commandline, '1abbCcEefghl:qr:tvXx]')
except getopt.GetoptError as e:
ErrorMsg(eBADARG % e.args[0])
sys.exit(1)
 
if opt == "-C":
CASE = True
if opt == "-c":
CASE = False
if opt == "-d":
DumpState()
if opt == "-E":
ERRORCONTINUE = True
if opt == "-e":
TARGET = EXT
REGEX = False
if opt == "-x":
REGEX = True
 
if DEBUG:
# Dump final program state
DumpState()