�
.�t_c@sdZddlTddlmZddlZdefd��YZdefd��YZd efd
��YZdefd��YZd
efd��YZ defd��YZ
defd��YZdefd��YZdefd��YZ
defd��YZdS(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*(tLabeledValueNtFieldcBsneZdZejd�Zejd�Zejd�Zed��Z d�Z
d�Zd�Zd�Z
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|j�j�S(Nt (tgrouptlower(tmatch((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt<lambda>1scSsdj|j��S(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|���fd�S(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
t��S(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|j��nd|_|j |jdd��|_
|jdd�}|dk|_djd |j�}|j |r�|n|�|_
|rtd
j|j����ndS(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 tkwargsRtdefaultValue((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyt__init__As %0cCs)|j||�st�S|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
(RtNotAvailableR$(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
RRtclassmethodRRR)R+R/(((s8/usr/lib/python2.7/site-packages/vdo/statistics/Field.pyRs + tIntegerFieldcBseZdZd�ZRS(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.pyR6�st BoolFieldcBseZd�Zd�ZRS(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.pyR9�s t
Uint8FieldcBseZd�ZRS(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;�stUint32FieldcBseZd�ZRS(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<�stUint64FieldcBseZd�ZRS(cKs tt|�j|t|�dS(N(R8R>R)tc_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>�stFloatingPointFieldcBseZdZd�ZRS(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
FloatFieldcBseZd�ZRS(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.pyRB�stStringFieldcBseZd�ZRS(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.pyRD�sR*cBszeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zd
�Zd�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.pyt<module>s
i |