LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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