LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Classes | Functions
lsst.pex.config.history Namespace Reference

Classes

class  Color
 
class  StackFrame
 

Functions

def _colorize
 
def format
 

Function Documentation

def lsst.pex.config.history._colorize (   text,
  category 
)
private

Definition at line 110 of file history.py.

111 def _colorize(text, category):
112  text = Color(text, category)
113  return str(text)
114 
115 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def lsst.pex.config.history.format (   config,
  name = None,
  writeSourceLine = True,
  prefix = "",
  verbose = False 
)
Format the history record for config.name
Examples:
spatialCellExample.cc.

Definition at line 127 of file history.py.

128 def format(config, name=None, writeSourceLine=True, prefix="", verbose=False):
129  """Format the history record for config.name"""
130 
131  if name is None:
132  for i, name in enumerate(config.history.keys()):
133  if i > 0:
134  print
135  print format(config, name)
136 
137  outputs = []
138  for value, tb, label in config.history[name]:
139  output = []
140  for frame in [StackFrame(t) for t in tb]:
141  if frame.functionName in ("__new__", "__set__", "__setattr__", "execfile", "wrapper") or \
142  os.path.split(frame.fileName)[1] in ("argparse.py", "argumentParser.py"):
143  if not verbose:
144  continue
145 
146  line = []
147  if writeSourceLine:
148  line.append(["%s" % ("%s:%d" % (frame.fileName, frame.lineNumber)), "FILE",])
149 
150  line.append([frame.text, "TEXT",])
151  if False:
152  line.append([frame.functionName, "FUNCTION_NAME",])
153 
154  output.append(line)
155 
156  outputs.append([value, output])
157  #
158  # Find the maximum widths of the value and file:lineNo fields
159  #
160  if writeSourceLine:
161  sourceLengths = []
162  for value, output in outputs:
163  sourceLengths.append(max([len(x[0][0]) for x in output]))
164  sourceLength = max(sourceLengths)
165 
166  valueLength = len(prefix) + max([len(str(value)) for value, output in outputs])
167  #
168  # actually generate the config history
169  #
170  msg = []
171  fullname = "%s.%s" %(config._name, name) if config._name is not None else name
172  msg.append(_colorize(re.sub(r"^root\.", "", fullname), "NAME"))
173  for value, output in outputs:
174  line = prefix + _colorize("%-*s" % (valueLength, value), "VALUE") + " "
175  for i, vt in enumerate(output):
176  if writeSourceLine:
177  vt[0][0] = "%-*s" % (sourceLength, vt[0][0])
178 
179  output[i] = " ".join([_colorize(v, t) for v, t in vt])
180 
181  line += ("\n%*s" % (valueLength + 1, "")).join(output)
182  msg.append(line)
183 
184  return "\n".join(msg)
185