LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
Classes | Functions
lsst.pex.config.history Namespace Reference

Classes

class  Color
 

Functions

def format (config, name=None, writeSourceLine=True, prefix="", verbose=False)
 

Function Documentation

◆ format()

def lsst.pex.config.history.format (   config,
  name = None,
  writeSourceLine = True,
  prefix = "",
  verbose = False 
)
Format the history record for a configuration, or a specific
configuration field.

Parameters
----------
config : `lsst.pex.config.Config`
    A configuration instance.
name : `str`, optional
    The name of a configuration field to specifically format the history
    for. Otherwise the history of all configuration fields is printed.
writeSourceLine : `bool`, optional
    If `True`, prefix each printout line with the code filename and line
    number where the configuration event occurred. Default is `True`.
prefix : `str`, optional
    A prefix for to add to each printout line. This prefix occurs first,
    even before any source line. The default is an empty string.
verbose : `bool`, optional
    Default is `False`.

Definition at line 168 of file history.py.

168 def format(config, name=None, writeSourceLine=True, prefix="", verbose=False):
169  """Format the history record for a configuration, or a specific
170  configuration field.
171 
172  Parameters
173  ----------
174  config : `lsst.pex.config.Config`
175  A configuration instance.
176  name : `str`, optional
177  The name of a configuration field to specifically format the history
178  for. Otherwise the history of all configuration fields is printed.
179  writeSourceLine : `bool`, optional
180  If `True`, prefix each printout line with the code filename and line
181  number where the configuration event occurred. Default is `True`.
182  prefix : `str`, optional
183  A prefix for to add to each printout line. This prefix occurs first,
184  even before any source line. The default is an empty string.
185  verbose : `bool`, optional
186  Default is `False`.
187  """
188 
189  if name is None:
190  for i, name in enumerate(config.history.keys()):
191  if i > 0:
192  print()
193  print(format(config, name))
194 
195  outputs = []
196  for value, stack, label in config.history[name]:
197  output = []
198  for frame in stack:
199  if frame.function in ("__new__", "__set__", "__setattr__", "execfile", "wrapper") or \
200  os.path.split(frame.filename)[1] in ("argparse.py", "argumentParser.py"):
201  if not verbose:
202  continue
203 
204  line = []
205  if writeSourceLine:
206  line.append(["%s" % ("%s:%d" % (frame.filename, frame.lineno)), "FILE", ])
207 
208  line.append([frame.content, "TEXT", ])
209  if False:
210  line.append([frame.function, "FUNCTION_NAME", ])
211 
212  output.append(line)
213 
214  outputs.append([value, output])
215 
216  # Find the maximum widths of the value and file:lineNo fields.
217  if writeSourceLine:
218  sourceLengths = []
219  for value, output in outputs:
220  sourceLengths.append(max([len(x[0][0]) for x in output]))
221  sourceLength = max(sourceLengths)
222 
223  valueLength = len(prefix) + max([len(str(value)) for value, output in outputs])
224 
225  # Generate the config history content.
226  msg = []
227  fullname = "%s.%s" % (config._name, name) if config._name is not None else name
228  msg.append(_colorize(re.sub(r"^root\.", "", fullname), "NAME"))
229  for value, output in outputs:
230  line = prefix + _colorize("%-*s" % (valueLength, value), "VALUE") + " "
231  for i, vt in enumerate(output):
232  if writeSourceLine:
233  vt[0][0] = "%-*s" % (sourceLength, vt[0][0])
234 
235  output[i] = " ".join([_colorize(v, t) for v, t in vt])
236 
237  line += ("\n%*s" % (valueLength + 1, "")).join(output)
238  msg.append(line)
239 
240  return "\n".join(msg)
241 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168
int max