Sindbad~EG File Manager
3
x?ag� � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlT ddlmZ dd lZG d
d� de �Z
G dd
� d
e
�ZG dd� de�ZG dd� de�Z
G dd� de�ZG dd� de�ZG dd� de
�ZG dd� de�ZG dd� de
�ZG dd� de�Zd S )z�
Field - base class for a field of a collection of statistics
$Id: //eng/vdo-releases/aluminum/src/python/vdo/statistics/Field.py#2 $
� )�absolute_import)�division)�print_function)�unicode_literals)�*� )�LabeledValueNc @ sZ e Zd ZdZejd�Zejd�Zejd�Ze dd� �Z
dd� Zd d
� Zdd� Z
d
d� ZdS )�FieldzD
Field is the base class for a field of a statistics structure.
z([A-Z][a-z])z([a-z])([A-Z])z\$([a-zA-Z0-9_]+)c C s$ | j jdd� |�}| jjdd� |�S )a
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
c S s d| j � j� S )N� )�group�lower)�match� r �/usr/lib/python3.6/Field.py�<lambda>5 s z Field._decamel.<locals>.<lambda>c S s dj | j� �S )Nr
)�join�groups)r
r r r r 7 s )�
decamelRE1�sub�
decamelRE2)�cls�stringZloweredr r r �_decamel) s zField._decamelc s | j jd|�� � fdd�S )z�
Convert a string describing how to derive a field's value into a lambda.
:param string The string to convert
:return: An equivalent lambda
z"parent.getSampleValue(stats, "\1")c s t � �S )N)�eval)�stats�parent)�
derivationr r r C s z'Field._generateLambda.<locals>.<lambda>)�
fieldNamesr )�selfr r )r r �_generateLambda9 s zField._generateLambdac K s� || _ |jdd�| _| jdkr(|| j n|| _|jdd�| _| jrV|jd| j| j ��nd| _| j|jdd��| _|jd d�}|dk| _ d
j
| j d�}| j|r�|n|�| _|r�tdj
|j
� ���dS )
a�
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.
�lengthr �displayT�labelN� available�True�derivedzgetattr(stats, '{name}'))�namezunknown arguments to Field: {0})r&