Allow filtering attributes that do NOT have some flags (in get_attribute_list)
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 12 Jul 2011 16:21:45 +0000 (18:21 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 12 Jul 2011 16:21:45 +0000 (18:21 +0200)
src/nepi/core/attributes.py
src/nepi/core/execute.py
src/nepi/core/testbed_impl.py
src/nepi/util/proxy.py

index 75a2116..3de13cf 100644 (file)
@@ -168,12 +168,22 @@ class AttributesMap(object):
     def attributes(self):
         return self._attributes.values()
 
-    def get_attribute_list(self, filter_flags = None):
+    def get_attribute_list(self, filter_flags = None, exclude = False):
+        """
+        Returns the list of attributes.
+        
+        Params:
+            filter_flags: if given, only attributes with (all) the specified
+                flags will be returned.
+            
+            exclude: if True, only attributes without (any of) the specified
+                flags will be returned.
+        """
         attributes = self._attributes
         if filter_flags != None:
             def filter_attrs(attr_data):
                 (attr_id, attr) = attr_data
-                return attr.has_flag(filter_flags)
+                return attr.has_flag(filter_flags) == (not exclude)
             attributes = dict(filter(filter_attrs, attributes.iteritems()))
         return attributes.keys()
 
index 84def93..70df1c7 100644 (file)
@@ -165,7 +165,7 @@ class TestbedController(object):
         """
         raise NotImplementedError
 
-    def get_attribute_list(self, guid, filter_flags = None):
+    def get_attribute_list(self, guid, filter_flags = None, exclude = False):
         raise NotImplementedError
 
     def get_factory_id(self, guid):
index 4b20056..336da50 100644 (file)
@@ -374,10 +374,10 @@ class TestbedController(execute.TestbedController):
         
         return addresses[index][attribute_index]
 
-    def get_attribute_list(self, guid, filter_flags = None):
+    def get_attribute_list(self, guid, filter_flags = None, exclude = False):
         factory = self._get_factory(guid)
         attribute_list = list()
-        return factory.box_attributes.get_attribute_list(filter_flags)
+        return factory.box_attributes.get_attribute_list(filter_flags, exclude)
 
     def get_factory_id(self, guid):
         factory = self._get_factory(guid)
index 45943c6..c89f1d8 100644 (file)
@@ -650,10 +650,10 @@ class TestbedControllerServer(BaseServer):
         return self._testbed.status(guid)
 
     @Marshalling.handles(GET_ATTRIBUTE_LIST)
-    @Marshalling.args(int, int)
+    @Marshalling.args(int, int, Marshalling.bool)
     @Marshalling.retval( Marshalling.pickled_data )
-    def get_attribute_list(self, guid, filter_flags = None):
-        return self._testbed.get_attribute_list(guid, filter_flags)
+    def get_attribute_list(self, guid, filter_flags = None, exclude = False):
+        return self._testbed.get_attribute_list(guid, filter_flags, exclude)
 
     @Marshalling.handles(GET_FACTORY_ID)
     @Marshalling.args(int)