X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fexecution%2Fattribute.py;h=3afc96f9df222a61dd7a4e102051e33eec818521;hb=8ef508f12834ed9e8781edd692059b67e945b5f0;hp=bf0a8536a3a23e391e75a318145e65a5671eaf17;hpb=a55b5cf0818ced6ab8dc3e88fad7f6616675e826;p=nepi.git diff --git a/src/nepi/execution/attribute.py b/src/nepi/execution/attribute.py index bf0a8536..3afc96f9 100644 --- a/src/nepi/execution/attribute.py +++ b/src/nepi/execution/attribute.py @@ -19,6 +19,8 @@ ### Attribute Types class Types: + """ Allowed types for the Attribute value + """ String = "STRING" Bool = "BOOL" Enumerate = "ENUM" @@ -27,8 +29,7 @@ class Types: ### Attribute Flags class Flags: - """ Differents flags to characterize an attribute - + """ Flags to characterize the scope of an Attribute """ # Attribute value can not be read (it is hidden to the user) NoRead = 1 # 1 @@ -57,49 +58,46 @@ class Flags: class Attribute(object): + """ An Attribute exposes a configuration parameter of a resource """ - .. class:: Class Args : - An Attribute reflects a configuration parameter for - a particular resource. Attributes might be read only or - not. - - :param name: Name of the attribute + def __init__(self, name, help, type = Types.String, + flags = None, default = None, allowed = None, + range = None, set_hook = None): + """ + :param name: Name of the Attribute :type name: str - :param help: Attribute description + :param help: Description of the Attribute :type help: str - :param type: The type expected for the attribute value. - Should be one of Attribute.Types . + :param type: The type expected for the Attribute value. + Should be one of Attribute.Types :type type: str - :param flags: Defines attribute behavior (i.e. whether it is read-only, - read and write, etc). This parameter should take its values from - Attribute.Flags. Flags values can be bitwised. + :param flags: Defines Attribute behavior (i.e. whether it is read-only, + read and write, etc). This parameter must take its values from + Attribute.Flags. Flags values can be bitwised :type flags: hex - :param default: Default value of the attribute - :type default: depends on the type of attribute + :param default: Default value for the Attribute + :type default: Depends on the type of Attribute - :param allowed: List of values that the attribute can take. - This parameter is only meaningful for Enumerate type attributes. + :param allowed: List of values that the Attribute can take. + This parameter is only meaningful for Enumerate type Attributes :type allowed: list :param range: (max, min) tuple with range of possible values for - attributes. + Attributes. This parameter is only meaningful for Integer or Double type - attributes. + Attributes :type range: (int, int) or (float, float) :param set_hook: Function that will be executed whenever a new - value is set for the attribute. + value is set for the Attribute. :type set_hook: function """ - def __init__(self, name, help, type = Types.String, - flags = None, default = None, allowed = None, - range = None, set_hook = None): self._name = name self._help = help self._type = type @@ -113,41 +111,41 @@ class Attribute(object): @property def name(self): - """ Returns the name of the attribute """ + """ Returns the name of the Attribute """ return self._name @property def default(self): - """ Returns the default value of the attribute """ + """ Returns the default value of the Attribute """ return self._default @property def type(self): - """ Returns the type of the attribute """ + """ Returns the type of the Attribute """ return self._type @property def help(self): - """ Returns the help of the attribute """ + """ Returns the description of the Attribute """ return self._help @property def flags(self): - """ Returns the flags of the attribute """ + """ Returns the flags of the Attribute """ return self._flags @property def allowed(self): - """ Returns the allowed value for this attribute """ + """ Returns the set of allowed values for the Attribute """ return self._allowed @property def range(self): - """ Returns the range of the attribute """ + """ Returns the range of allowed numerical values for the Attribute """ return self._range def has_flag(self, flag): - """ Returns true if the attribute has the flag 'flag' + """ Returns True if the Attribute has the flag 'flag' :param flag: Flag to be checked :type flag: Flags @@ -155,11 +153,11 @@ class Attribute(object): return (self._flags & flag) == flag def get_value(self): - """ Returns the value of the attribute """ + """ Returns the value of the Attribute """ return self._value def set_value(self, value): - """ Change the value of the attribute after checking the type """ + """ Configure a new value for the Attribute """ valid = True if self.type == Types.Enumerate: @@ -193,5 +191,6 @@ class Attribute(object): @property def has_changed(self): - """ Returns true if the value has changed from the default """ + """ Returns True if the value has changed from the default """ return self.value != self.default +