DOUBLE,
INTEGER
]
+
+ type_parsers = {
+ STRING : str,
+ BOOL : lambda x : str(x).lower() in ("1","on","yes","true"),
+ ENUM : str,
+ DOUBLE : float,
+ INTEGER : int,
+ }
### Attribute Flags
NoFlags = 0x00
# Attribute is read only and can't be modified by the user
# Note: ReadOnly implies DesignOnly
ReadOnly = 0x03
- # Attribute is invisible to the user
- # Note: Invisible implies ReadOnly and DesignOnly
- Invisible = 0x07
+ # Attribute is invisible to the user but can be modified
+ Invisible = 0x04
# Attribute has no default value in the testbed instance.
# So it needs to be set explicitely
HasNoDefaultValue = 0x08
def __init__(self, name, help, type, value = None, range = None,
- allowed = None, flags = NoFlags, validation_function = None):
+ allowed = None, flags = NoFlags, validation_function = None,
+ category = None):
if not type in Attribute.types:
raise AttributeError("invalid type %s " % type)
self._name = name
self._allowed = allowed
self._validation_function = validation_function
self._modified = False
+ self._category = category
@property
def name(self):
return self._flags
@property
- def invsible(self):
+ def invisible(self):
return (self._flags & Attribute.Invisible) == Attribute.Invisible
@property
def modified(self):
return self._modified
+ @property
+ def category(self):
+ return self._category
+
@property
def range(self):
return self._range
return self._value
def set_value(self, value):
- if self._is_in_range(value) and \
- self._is_in_allowed_values(value) and \
- self._is_valid(value):
+ if self.is_valid_value(value):
self._value = value
self._modified = True
else:
value = property(get_value, set_value)
+ def is_valid_value(self, value):
+ return self._is_in_range(value) and \
+ self._is_in_allowed_values(value) and \
+ self._is_valid(value)
+
def _is_in_range(self, value):
return not self.range or \
(value >= self.range[0] and value <= self.range[1])
def _is_in_allowed_values(self, value):
- return not self.allowed or value in self._allowed
+ return not self._allowed or value in self._allowed
def _is_valid(self, value):
return not self._validation_function or \
return self._attributes.values()
@property
- def attributes_name(self):
+ def attributes_list(self):
return self._attributes.keys()
def set_attribute_value(self, name, value):
def get_attribute_allowed(self, name):
return self._attributes[name].allowed
+ def get_attribute_category(self, name):
+ return self._attributes[name].category
+
def is_attribute_read_only(self, name):
return self._attributes[name].read_only
def is_attribute_modified(self, name):
return self._attributes[name].modified
+ def is_attribute_value_valid(self, name, value):
+ return self._attributes[name].is_valid_value(value)
+
def add_attribute(self, name, help, type, value = None, range = None,
- allowed = None, flags = Attribute.NoFlags, validation_function = None):
+ allowed = None, flags = Attribute.NoFlags, validation_function = None,
+ category = None):
if name in self._attributes:
raise AttributeError("Attribute %s already exists" % name)
attribute = Attribute(name, help, type, value, range, allowed, flags,
- validation_function)
+ validation_function, category)
self._attributes[name] = attribute
def del_attribute(self, name):