[Commits] (vajda) - renamed Item.iterAttributes() to Item.iterAttributeValues()

commits at osafoundation.org commits at osafoundation.org
Sun Mar 21 11:39:16 PST 2004


Commit by: vajda
Modified files:
osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py 1.6 1.7
osaf/chandler/Chandler/repository/item/Item.py 1.110 1.111
osaf/chandler/Chandler/repository/parcel/Util.py 1.5 1.6
osaf/chandler/Chandler/repository/schema/Kind.py 1.54 1.55
osaf/chandler/Chandler/repository/tests/TestAlias.py 1.1 1.2
osaf/chandler/Chandler/repository/tests/TestItems.py 1.7 1.8

Log message:
   - renamed Item.iterAttributes() to Item.iterAttributeValues()
   - implemented Kind.iterAttributes()


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/item/Item.py.diff?r1=text&tr1=1.110&r2=text&tr2=1.111
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/parcel/Util.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/schema/Kind.py.diff?r1=text&tr1=1.54&r2=text&tr2=1.55
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/tests/TestAlias.py.diff?r1=text&tr1=1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/tests/TestItems.py.diff?r1=text&tr1=1.7&r2=text&tr2=1.8

Index: osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py
diff -u osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py:1.6 osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py:1.7
--- osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py:1.6	Mon Mar  1 16:18:42 2004
+++ osaf/chandler/Chandler/parcels/OSAF/views/repositoryviewer/Repository.py	Sun Mar 21 11:38:39 2004
@@ -1,8 +1,8 @@
 """ Classes used by the repository view
 """
 
-__version__ = "$Revision: 1.6 $"
-__date__ = "$Date: 2004/03/02 00:18:42 $"
+__version__ = "$Revision: 1.7 $"
+__date__ = "$Date: 2004/03/21 19:38:39 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -105,7 +105,7 @@
             # all reference-only. Then we concatenate the two lists and sort
             # the result, and append that to the HTMLText.
             valueAttr = []
-            for k, v in item.iterAttributes(valuesOnly=True):
+            for k, v in item.iterAttributeValues(valuesOnly=True):
                 if isinstance(v, dict):
                     tmpList = ["<li><b>%s:</b></li><ul>" % k]
                     for attr in v:
@@ -122,7 +122,7 @@
                     valueAttr.append((k,"<li><b>%s: </b>%s</li>" % (k, value)))
     
             refAttrs = []
-            for k, v in item.iterAttributes(referencesOnly=True):
+            for k, v in item.iterAttributeValues(referencesOnly=True):
                 if isinstance(v, dict) or isinstance(v, list):
                     tmpList = ["<li><b>%s:</b></li><ul>" % k]
                     for attr in v:

Index: osaf/chandler/Chandler/repository/tests/TestItems.py
diff -u osaf/chandler/Chandler/repository/tests/TestItems.py:1.7 osaf/chandler/Chandler/repository/tests/TestItems.py:1.8
--- osaf/chandler/Chandler/repository/tests/TestItems.py:1.7	Tue Feb  3 19:37:52 2004
+++ osaf/chandler/Chandler/repository/tests/TestItems.py	Sun Mar 21 11:38:44 2004
@@ -2,8 +2,8 @@
 Basic Unit tests for Chandler repository
 """
 
-__revision__  = "$Revision: 1.7 $"
-__date__      = "$Date: 2004/02/04 03:37:52 $"
+__revision__  = "$Revision: 1.8 $"
+__date__      = "$Date: 2004/03/21 19:38:44 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -162,7 +162,7 @@
 
         # Test iterating over literal attributes
         literalAttributeNames = ['notFoundAttributes', 'classes'] 
-        for i in kind.iterAttributes(valuesOnly=True):
+        for i in kind.iterAttributeValues(valuesOnly=True):
             self.failUnless(i[0] in literalAttributeNames)
 
         # Test hasAttributeValue
@@ -172,7 +172,7 @@
         # Test iterating over reference attributes
         referenceAttributeNames = ['superKinds', 'attributes', 'kind',
                                    'inheritedAttributes', 'items']
-        for i in kind.iterAttributes(referencesOnly=True):
+        for i in kind.iterAttributeValues(referencesOnly=True):
             self.failUnless(i[0] in referenceAttributeNames)
             self.failUnless(isinstance(i[1], RefDict) or
                             isinstance(i[1], Kind))

Index: osaf/chandler/Chandler/repository/parcel/Util.py
diff -u osaf/chandler/Chandler/repository/parcel/Util.py:1.5 osaf/chandler/Chandler/repository/parcel/Util.py:1.6
--- osaf/chandler/Chandler/repository/parcel/Util.py:1.5	Fri Feb 13 16:23:21 2004
+++ osaf/chandler/Chandler/repository/parcel/Util.py	Sun Mar 21 11:38:41 2004
@@ -2,8 +2,8 @@
 Utility functions for displaying repository contents
 """
 
-__revision__  = "$Revision: 1.5 $"
-__date__      = "$Date: 2004/02/14 00:23:21 $"
+__revision__  = "$Revision: 1.6 $"
+__date__      = "$Date: 2004/03/21 19:38:41 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -33,7 +33,7 @@
         else:
             print attr.getItemPath(), "(from %s)" % source.getItemPath()
 
-    for (name, value) in item.iterAttributes():
+    for (name, value) in item.iterAttributeValues():
 
         t = type(value)
 

Index: osaf/chandler/Chandler/repository/tests/TestAlias.py
diff -u osaf/chandler/Chandler/repository/tests/TestAlias.py:1.1 osaf/chandler/Chandler/repository/tests/TestAlias.py:1.2
--- osaf/chandler/Chandler/repository/tests/TestAlias.py:1.1	Sun Jan 11 22:39:04 2004
+++ osaf/chandler/Chandler/repository/tests/TestAlias.py	Sun Mar 21 11:38:44 2004
@@ -2,8 +2,8 @@
 Unit tests for Aliases
 """
 
-__revision__  = "$Revision: 1.1 $"
-__date__      = "$Date: 2004/01/12 06:39:04 $"
+__revision__  = "$Revision: 1.2 $"
+__date__      = "$Date: 2004/03/21 19:38:44 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -74,7 +74,7 @@
 
 #        newKind = self.kind.newItem('newKind', self.rep)
 #        print k
-        for a in self.alias.iterAttributes():
+        for a in self.alias.iterAttributeValues():
 #            print a
             a1 =  self.kind.getAttribute(a[0])
             print a1

Index: osaf/chandler/Chandler/repository/schema/Kind.py
diff -u osaf/chandler/Chandler/repository/schema/Kind.py:1.54 osaf/chandler/Chandler/repository/schema/Kind.py:1.55
--- osaf/chandler/Chandler/repository/schema/Kind.py:1.54	Sat Feb 14 00:18:55 2004
+++ osaf/chandler/Chandler/repository/schema/Kind.py	Sun Mar 21 11:38:42 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.54 $"
-__date__      = "$Date: 2004/02/14 08:18:55 $"
+__revision__  = "$Revision: 1.55 $"
+__date__      = "$Date: 2004/03/21 19:38:42 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -103,35 +103,75 @@
         else:
             return self._inheritAttribute(name) is not None
 
+    def iterAttributes(self, inherited=True,
+                       localOnly=False, globalOnly=False):
+        """
+        Return a generator of C{(name, attribute)} pairs for iterating over the
+        Chandler attributes defined for and inherited by this kind.
+
+        @param inherited: if C{True}, iterate also over attributes that are
+        inherited by this kind via its superKinds.
+        @type inherited: boolean
+        @param localOnly: if C{True}, only pairs for local attributes are
+        returned. Local attributes are defined as direct children items
+        of the kinds they're defined on and are not meant to be shared
+        except through inheritance. The name of a local attribute is defined
+        to be the name of its corresponding attribute item.
+        @type localOnly: boolean
+        @param globalOnly: if C{True}, only pairs for the global attributes
+        are returned. Global attributes are not defined as direct children
+        items and are intended to be shareable by multiple kinds. The name
+        of a global attribute is defined to be the alias with which it was
+        added into the kind's C{attributes} attribute. This alias name may
+        of course be the same as the corresponding attribute's item name.
+        @type globalOnly: boolean
+        """
+
+        if inherited:
+            for superKind in self._getSuperKinds():
+                for pair in superKind.iterAttributes(inherited,
+                                                     localOnly, globalOnly):
+                    yield pair
+
+        if not localOnly:
+            attributes = self.getAttributeValue('attributes', default=None)
+            if attributes is not None:
+                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)
+
     def _inheritAttribute(self, name):
 
         if self.hasValue('notFoundAttributes', name):
             return None
 
-        inheritingKinds = self._getInheritingKinds()
-        if inheritingKinds is not None:
-            cache = True
-            for inheritingKind in inheritingKinds:
-                if inheritingKind is not None:
-                    attribute = inheritingKind.getAttribute(name)
-                    if attribute is not None:
-                        self.addValue('inheritedAttributes', attribute,
-                                      alias=name)
-                        return attribute
-                else:
-                    cache = False
+        cache = True
+        for superKind in self._getSuperKinds():
+            if superKind is not None:
+                attribute = superKind.getAttribute(name)
+                if attribute is not None:
+                    self.addValue('inheritedAttributes', attribute, alias=name)
+                    return attribute
+            else:
+                cache = False
                     
-            if cache:
-                self.addValue('notFoundAttributes', name)
+        if cache:
+            self.addValue('notFoundAttributes', name)
 
         return None
 
-    def _getInheritingKinds(self):
+    def _getSuperKinds(self):
 
-        if self.hasAttributeValue('superKinds'):
-            return self.superKinds
-
-        raise ValueError, 'No superKind for %s' %(self.getItemPath())
+        try:
+            return self.getAttributeValue('superKinds',
+                                          _attrDict=self._references)
+        except AttributeError:
+            raise ValueError, 'No superKind for %s' %(self.getItemPath())
 
     def _xmlRefs(self, generator, withSchema, version, mode):
 
@@ -146,9 +186,7 @@
 
     def isSubKindOf(self, superKind):
 
-        superKinds = self.getAttributeValue('superKinds',
-                                            _attrDict=self._references,
-                                            default=[])
+        superKinds = self._getSuperKinds()
 
         if superKinds:
             for kind in superKinds:
@@ -220,10 +258,5 @@
 
 class ItemKind(Kind):
 
-    def _getInheritingKinds(self):
-
-        return None
-
-
-class SchemaRoot(Item):
-    pass
+    def _getSuperKinds(self):
+        return []

Index: osaf/chandler/Chandler/repository/item/Item.py
diff -u osaf/chandler/Chandler/repository/item/Item.py:1.110 osaf/chandler/Chandler/repository/item/Item.py:1.111
--- osaf/chandler/Chandler/repository/item/Item.py:1.110	Mon Mar  8 14:56:52 2004
+++ osaf/chandler/Chandler/repository/item/Item.py	Sun Mar 21 11:38:40 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.110 $"
-__date__      = "$Date: 2004/03/08 22:56:52 $"
+__revision__  = "$Revision: 1.111 $"
+__date__      = "$Date: 2004/03/21 19:38:40 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -617,7 +617,7 @@
             for child in self._children:
                 yield child
 
-    def iterAttributes(self, valuesOnly=False, referencesOnly=False):
+    def iterAttributeValues(self, valuesOnly=False, referencesOnly=False):
         """
         Return a generator of C{(name, value)} tuples for iterating over
         Chandler attribute values of this item. 



More information about the Commits mailing list