LSSTApplications  17.0+10,17.0+51,17.0+90,18.0.0+10,18.0.0+15,18.0.0+36,18.0.0+4,18.0.0+6,18.0.0-2-ge43143a+6,18.1.0-1-g0001055+2,18.1.0-1-g1349e88+12,18.1.0-1-g2505f39+9,18.1.0-1-g380d4d4+12,18.1.0-1-g5e4b7ea+2,18.1.0-1-g7e8fceb,18.1.0-1-g85f8cd4+9,18.1.0-1-g9a6769a+3,18.1.0-1-ga1a4c1a+8,18.1.0-1-gc037db8+2,18.1.0-1-gd55f500+3,18.1.0-1-ge10677a+9,18.1.0-10-g73b8679e+15,18.1.0-13-g451e75588,18.1.0-13-gbfe7f7f+3,18.1.0-14-g2e73c10,18.1.0-2-g31c43f9+9,18.1.0-2-g9c63283+12,18.1.0-2-gdf0b915+12,18.1.0-2-gf03bb23+2,18.1.0-2-gfefb8b5,18.1.0-3-g52aa583+3,18.1.0-3-g8f4a2b1+3,18.1.0-3-g9cb968e+11,18.1.0-4-g7bbbad0+2,18.1.0-5-g510c42a+11,18.1.0-5-gaeab27e+12,18.1.0-6-gc4bdb98,18.1.0-6-gdda7f3e+14,18.1.0-9-g9613d271,w.2019.34
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