.t_c@s dZddlTddlmZddlZdefdYZdefdYZd efd YZd efd YZd efdYZ defdYZ defdYZ de fdYZ defdYZ defdYZdS(s Field - base class for a field of a collection of statistics $Id: //eng/vdo-releases/magnesium/src/python/vdo/statistics/Field.py#1 $ i(t*(t LabeledValueNtFieldcBsneZdZejdZejdZejdZedZ dZ dZ dZ dZ RS( sD Field is the base class for a field of a statistics structure. s ([A-Z][a-z])s([a-z])([A-Z])s\$([a-zA-Z0-9_]+)cCs.|jjd|}|jjd|S(s Convert a camel-cased string to a set of space separated, lower case words. Preserves uppercase acronyms, so 'launchVDOErrorCount' becomes 'launch VDO error count'. :param string: The string to convert :return: The converted string cSsd|jjS(Nt (tgrouptlower(tmatch((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt1scSsdj|jS(NR(tjointgroups(R((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR3s(t decamelRE1tsubt decamelRE2(tclststringtlowered((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt_decamel%s  cs"|jjd|fdS(s Convert a string describing how to derive a field's value into a lambda. :param string The string to convert :return: An equivalent lambda s"parent.getSampleValue(stats, "\1")cs tS(N(teval(tstatstparent(t derivation(s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR?s(t fieldNamesR (tselfR((Rs8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt_generateLambda5s  cKs"||_|jdd|_|jdkr:||jn||_|jdt|_|jr|jd|j|jnd |_|j |jdd|_ |jdd }|d k|_ dj d |j}|j |r|n||_ |rtd j |jnd S( s Create a new field. :param name: The name of the field :param cType: The class representing the C representation for this field when sampled via an ioctl :param **kwargs: Keyword arguments which may be: available: Specifies python code to apply to other fields of the parent structure to decide whether this value is available. Defaults to True. derived: Specifies python code to apply to other fields of the parent structure to derive the value of this field. Defaults to None. display: If not True, this field will not be included in labeled output. Defaults to True. label: The label for this field. If unspecified, the label will be derived from the field name. length: if > 1, indicates this field is an array of the specified cType, otherwise is is a scalar. Defaults to 1. tlengthitdisplaytlabelt availabletTruetderivedsgetattr(stats, '{name}')tnamesunknown arguments to Field: {0}N(RtpopRtcTypeRRRtNoneRRRtinStructtformattgetValuet Exceptiontkeys(RRR tkwargsRt defaultValue((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__init__As %0cCs)|j||stS|j||S(s Extract the value for this field from a sample. :param stats: The raw stats returned from an ioctl :param parent: The parent of this field :return: The value of this field in the current sample (Rt NotAvailableR$(RRR((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt extractSamplels cCstj||j|S(s Label a sampled value for this field. :param sample: The sampled field value :param prefix: The prefix for the label :return: A LabeledValue for a value of this field (RtmakeR(Rtsampletprefix((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pytlabeledzs (t__name__t __module__t__doc__tretcompileR R Rt classmethodRRR)R+R/(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyRs + t IntegerFieldcBseZdZdZRS(s4 Base class for fields which are integer types. cCsttt|j||S(s :inherit: (tinttsuperR6R+(RRR((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR+s(R0R1R2R+(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR6st BoolFieldcBseZdZdZRS(cKs tt|j|t|dS(N(R8R9R)tc_byte(RRR'((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR)scCstt|j||dkS(Ni(R8R9R+(RRR((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR+s(R0R1R)R+(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR9s t Uint8FieldcBseZdZRS(cKs tt|j|t|dS(N(R8R;R)R:(RRR'((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR)s(R0R1R)(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR;st Uint32FieldcBseZdZRS(cKs tt|j|t|dS(N(R8R<R)tc_uint(RRR'((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR)s(R0R1R)(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR<st Uint64FieldcBseZdZRS(cKs tt|j|t|dS(N(R8R>R)t c_ulonglong(RRR'((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR)s(R0R1R)(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR>stFloatingPointFieldcBseZdZdZRS(s; Base class for fields which are floating point types. cCsttt|j||S(s :inherit: (tfloatR8R@R+(RRR((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR+s(R0R1R2R+(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR@st FloatFieldcBseZdZRS(cKs tt|j|t|dS(N(R8RBR)tc_float(RRR'((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR)s(R0R1R)(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyRBst StringFieldcBseZdZRS(cKs tt|j|t|dS(N(R8RDR)tc_char(RRR'((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR)s(R0R1R)(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyRDsR*cBszeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d ZRS( sZ A value for numeric statistics which are currently not available; prints as 'N/A'. cCsdS(NsN/A((R((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__str__scCsdS(NR*((R((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__repr__scCs|S(N((Rtother((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__add__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__radd__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__sub__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__rsub__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__mul__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__rmul__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__div__scCs|S(N((RRH((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__rdiv__scCs|S(N((R((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__int__scCsd|djt|S(Ns{0:t}(R#tstr(Rtspec((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt __format__s(R0R1R2RFRGRIRJRKRLRMRNRORPRQRU(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyR*s           (R2tctypesRR3tobjectRR6R9R;R<R>R@RBRDR7R*(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyts  i