ó .Åt_c@sBdZddlZdefd„ƒYZdefd„ƒYZdS(sc DisplaySpec $Id: //eng/vdo-releases/magnesium/src/python/vdo/statistics/StatFormatter.py#1 $ iÿÿÿÿNt StatFormattercBs/eZdZeed„Zd„Zd„ZRS(så An object which formats labeled values. Formatters are able to represent all of the verbose formatting for vdoStats and vdoMonitor (the df-style formatting in vdoStats is done by hand). A formatter is specified by supplying a description of the format for each level of the hierarchy of labeled values. If the values have more levels than the formatter has specified, the final level specification will be applied to all remaining value levels. A level specification is specified as a hash with any of the following keys: displayFilter: A function which takes a LabeledValue and return True if that value (and its children) should be displayed. Defaults to a tautology. indent: The additional indentation to apply from this level down. Defaults to no additional indentation. joiner: The string to use for joining label-value pairs at the current level. In YAML mode, defaults to a newline, otherwise defaults to a space. namer: The way of naming the current level. Can be any of these: None: Don't name this level list: A list of indexes into the value list at this level, the name of the level will be the concatenation of the values at those indexes. If the first element of the list is a string, it will be used as a prefix for the name. '=': Use the label of the value at this level as the name, use an equals sign to connect the name to the values '+': Use the label of the value at this level as the name, regardless of the formatter's mode string: Any other string will be used as the name True: Any other true value will use the label as the name if the mode indicates that the level should be named and otherwise won't name the level (non-hierarchical, multivalued levels don't get named). cCs¢||_||_d|_|jƒx&|D]}t||j|ƒ|_q,W|j}d}x>tr|j|ƒ}|jdkr‘||_Pn|j}q`WdS(s  Create a new formatter. :param displayLevels: An array of hashes describing how to format each level of the labled values to be formatted. :param hierarchical: If True, indentation will be increased at each level otherwise, indentation will only be modified at levels which specify the 'indent' parameter. Defaults to True. :param yaml: Whether to output as YAML or not. Defaults to True. tN( t hierarchicaltyamltNonetspectreverset DisplaySpectTruetsetIndentationtchild(tselft displayLevelsRRtleveltstindent((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyt__init__Ds        cCs|jj|ƒS(sn Format labeled values. :param lv: The values to format :return: The formatted value string (Rtformat(R tlv((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyRdscCs7y|j|ƒGHtjjƒWntk r2nXdS(sZ Format labeled values and print the result. :param lv: The values to format N(RtsyststdouttflushtIOError(R R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pytoutputns  (t__name__t __module__t__doc__RRRR(((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyRs' RcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s? An object which formats a single level of labeled values. cCsÓ||_d |_||_|jdd„ƒ|_|jddƒ|_|jd|jr`dndƒ|_|jd|jr„d ndƒ|_ |j |jd ƒƒ|_ d |_ d |_ |rÏ||_nd S( sG Create a new display specification. :param formatter : The formatter which owns this specification. :param child : The formatter for the next level down. :param parameters : A dict which defines the format at this level. Valid keys are documented in the header of this file. t displayFiltercSstS(N(R(R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyt‹sRRtjoiners t t nameJoiners: tnamerN(t formatterRtparentR tgetRRRRRt _setNamerR twidthtsubWidth(R R!R t parameters((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyRs       csĈs d„Stˆtƒr_tˆdtƒrFˆdˆdg‰n dˆg‰‡fd†StˆtƒrªˆdkrŠd|_d„Sˆdkrd „S‡fd †S|jjr½d „Sd „S( s› Set up the namer for this level from the specification. :param nameType: The type of namer to use :return: The specified namer function cSsdS(N(R(R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR siiRcs)ˆddj‡fd†ˆdDƒƒS(NiRc3s%|]}tˆj|jƒVqdS(N(tstrtvalue(t.0tn(R(s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pys ¨si(tjoin(R(tname(Rs@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR§st=cSs|jƒrdS|jS(N(t isMultiValuedRtlabel(R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR­st+cSs|jS(N(R0(R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR°scsˆS(N((R(tnameType(s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR²scSs|jS(N(R0(R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyRµscSs|jƒrdS|jS(N(R/RR0(R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR·s(t isinstancetlistR(RR!R(R R2((R-R2s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR$—s"       cCs„|j|ƒ}|sdS|jjrrt|jt|ƒƒd}dj|j|||j |j ƒrkdndƒS|j||j S(s› Get the name for a labeled value. :param lv: The value to name :return: The name for the value or None if the value should not be named is{0}{1:<{2}}{3}{4}s RN( R RR!RtmaxR%tlenRRRR/(R RR-t nameWidth((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pytgetName¹s cCs||j|_|jS(sm Set the indentation for this level. :param parentIndent: The indentation of the level above us (R(R t parentIndent((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR ÍscCs›|jr dS|jjrS|jr.|jjn |jƒ|_|jtƒ|_dS|jrv|jj|_|_dS|jƒ|_|jtƒ|_dS(s^ Set the width of the labels at this level. :param lv: The value being formatted N(R%R!RR"R&RtFalse(R R((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pytsetWidthÖs  $ cCsY|j|ƒsdS|j|ƒ|j|ƒ}|j|j|jƒ}|rU||S|S(sz Recursively format a labeled value. :param lv: The value to format :return: The formatted value string N(RRR;R8RR R(R RR-R)((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyRës  ( RRRRR$R8R R;R(((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyR{s  "  (RRtobjectRR(((s@/usr/lib/python2.7/site-packages/vdo/statistics/StatFormatter.pyts _