[Commits] (vajda) - fixed bug in Kind.iterAttributes()

commits at osafoundation.org commits at osafoundation.org
Tue Mar 23 16:27:24 PST 2004


Commit by: vajda
Modified files:
osaf/chandler/Chandler/repository/item/Item.py 1.111 1.112
osaf/chandler/Chandler/repository/schema/Kind.py 1.55 1.56

Log message:
   - fixed bug in Kind.iterAttributes()
   - improved Item.check() to detect undefined attributes


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/item/Item.py.diff?r1=text&tr1=1.111&r2=text&tr2=1.112
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/schema/Kind.py.diff?r1=text&tr1=1.55&r2=text&tr2=1.56

Index: osaf/chandler/Chandler/repository/schema/Kind.py
diff -u osaf/chandler/Chandler/repository/schema/Kind.py:1.55 osaf/chandler/Chandler/repository/schema/Kind.py:1.56
--- osaf/chandler/Chandler/repository/schema/Kind.py:1.55	Sun Mar 21 11:38:42 2004
+++ osaf/chandler/Chandler/repository/schema/Kind.py	Tue Mar 23 16:26:54 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.55 $"
-__date__      = "$Date: 2004/03/21 19:38:42 $"
+__revision__  = "$Revision: 1.56 $"
+__date__      = "$Date: 2004/03/24 00:26:54 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -133,17 +133,19 @@
                                                      localOnly, globalOnly):
                     yield pair
 
-        if not localOnly:
-            attributes = self.getAttributeValue('attributes', default=None)
-            if attributes is not None:
+        attributes = self.getAttributeValue('attributes', default=None)
+        if attributes is not None:
+
+            if not localOnly:
                 aliases = attributes._aliases
                 if aliases:
                     for (alias, uuid) in aliases.iteritems():
                         yield (alias, attributes[uuid])
-
-        if not globalOnly:
-            for attribute in self.iterChildren():
-                yield (attribute._name, attribute)
+    
+            if not globalOnly:
+                for attribute in self.iterChildren():
+                    if attribute._uuid in attributes:
+                        yield (attribute._name, attribute)
 
     def _inheritAttribute(self, name):
 

Index: osaf/chandler/Chandler/repository/item/Item.py
diff -u osaf/chandler/Chandler/repository/item/Item.py:1.111 osaf/chandler/Chandler/repository/item/Item.py:1.112
--- osaf/chandler/Chandler/repository/item/Item.py:1.111	Sun Mar 21 11:38:40 2004
+++ osaf/chandler/Chandler/repository/item/Item.py	Tue Mar 23 16:26:53 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.111 $"
-__date__      = "$Date: 2004/03/21 19:38:40 $"
+__revision__  = "$Revision: 1.112 $"
+__date__      = "$Date: 2004/03/24 00:26:53 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -585,7 +585,7 @@
         @return: C{None}
         """
         
-        for child in self:
+        for child in self.iterChildren():
             print child.getItemPath()
             if recursive:
                 child.dir(True)
@@ -682,34 +682,39 @@
             return True
 
         for key, value in self._values.iteritems():
-            attrType = self.getAttributeAspect(key, 'type', default=None)
-            if attrType is not None:
-                attrCard = self.getAttributeAspect(key, 'cardinality',
-                                                   default='single')
-                if attrCard == 'single':
-                    check = checkValue(key, value, attrType)
-                    result = result and check
-                elif attrCard == 'list':
-                    check = checkCardinality(key, value, list, 'list')
-                    result = result and check
-                    if check:
-                        for v in value:
-                            check = checkValue(key, v, attrType)
-                            result = result and check
-                elif attrCard == 'dict':
-                    check = checkCardinality(key, value, dict, 'dict')
-                    result = result and check
-                    if check:
-                        for v in value.itervalues():
-                            check = checkValue(key, v, attrType)
-                            result = result and check
+            attribute = self.kind.getAttribute(key)
+            if attribute is None:
+                logger.error('Item %s has a value for attribute %s but its kind %s has no definition for this attribute', self.getItemPath(), key, self.kind.getItemPath())
+                result = False
+            else:
+                attrType = self.getAttributeAspect(key, 'type', default=None)
+                if attrType is not None:
+                    attrCard = self.getAttributeAspect(key, 'cardinality',
+                                                       default='single')
+                    if attrCard == 'single':
+                        check = checkValue(key, value, attrType)
+                        result = result and check
+                    elif attrCard == 'list':
+                        check = checkCardinality(key, value, list, 'list')
+                        result = result and check
+                        if check:
+                            for v in value:
+                                check = checkValue(key, v, attrType)
+                                result = result and check
+                    elif attrCard == 'dict':
+                        check = checkCardinality(key, value, dict, 'dict')
+                        result = result and check
+                        if check:
+                            for v in value.itervalues():
+                                check = checkValue(key, v, attrType)
+                                result = result and check
         
         for key, value in self._references.iteritems():
             check = value.check(self, key)
             result = result and check
 
         if recursive:
-            for child in self:
+            for child in self.iterChildren():
                 check = child.check(True)
                 result = result and check
 
@@ -1157,7 +1162,7 @@
             self._status |= Item.DELETING
             others = []
 
-            for child in self:
+            for child in self.iterChildren():
                 child.delete(True)
 
             self._values.clear()



More information about the Commits mailing list