[Commits] (vajda) - inverted _setRef and __setitem__ APIs on RefList

commits at osafoundation.org commits at osafoundation.org
Mon Oct 25 18:29:03 PDT 2004


Commit by: vajda
Modified files:
chandler/application/Parcel.py 1.33 1.34
chandler/repository/item/Item.py 1.171 1.172
chandler/repository/item/ItemHandler.py 1.53 1.54
chandler/repository/item/RefCollections.py 1.2 1.3
chandler/repository/item/Values.py 1.22 1.23
chandler/repository/persistence/Repository.py 1.86 1.87
chandler/repository/persistence/RepositoryView.py 1.18 1.19
chandler/repository/persistence/XMLRefs.py 1.1 1.2
chandler/repository/persistence/XMLRepository.py 1.85 1.86
chandler/repository/tests/RepositoryTestCase.py 1.17 1.18
chandler/repository/tests/TestMerge.py 1.9 1.10
chandler/repository/tests/data/packs/cineguide/khepburn.movies 1.9 1.10
chandler/repository/tests/data/packs/cineguide/schema/attributes/Next.attr None 1.1
chandler/repository/tests/data/packs/cineguide/schema/attributes/Previous.attr None 1.1
chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind 1.8 1.9
chandler/repository/util/Streams.py 1.16 1.17

Log message:
   - inverted _setRef and __setitem__ APIs on RefList
   - deprecated Item|Repository|RepositoryView.__iter__() and fixed errors
   - fixed merge bug that caused a BadRef error


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/application/Parcel.py.diff?r1=text&tr1=1.33&r2=text&tr2=1.34
http://cvs.osafoundation.org/index.cgi/chandler/repository/item/Item.py.diff?r1=text&tr1=1.171&r2=text&tr2=1.172
http://cvs.osafoundation.org/index.cgi/chandler/repository/item/ItemHandler.py.diff?r1=text&tr1=1.53&r2=text&tr2=1.54
http://cvs.osafoundation.org/index.cgi/chandler/repository/item/RefCollections.py.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
http://cvs.osafoundation.org/index.cgi/chandler/repository/item/Values.py.diff?r1=text&tr1=1.22&r2=text&tr2=1.23
http://cvs.osafoundation.org/index.cgi/chandler/repository/persistence/Repository.py.diff?r1=text&tr1=1.86&r2=text&tr2=1.87
http://cvs.osafoundation.org/index.cgi/chandler/repository/persistence/RepositoryView.py.diff?r1=text&tr1=1.18&r2=text&tr2=1.19
http://cvs.osafoundation.org/index.cgi/chandler/repository/persistence/XMLRefs.py.diff?r1=text&tr1=1.1&r2=text&tr2=1.2
http://cvs.osafoundation.org/index.cgi/chandler/repository/persistence/XMLRepository.py.diff?r1=text&tr1=1.85&r2=text&tr2=1.86
http://cvs.osafoundation.org/index.cgi/chandler/repository/tests/RepositoryTestCase.py.diff?r1=text&tr1=1.17&r2=text&tr2=1.18
http://cvs.osafoundation.org/index.cgi/chandler/repository/tests/TestMerge.py.diff?r1=text&tr1=1.9&r2=text&tr2=1.10
http://cvs.osafoundation.org/index.cgi/chandler/repository/tests/data/packs/cineguide/khepburn.movies.diff?r1=text&tr1=1.9&r2=text&tr2=1.10
http://cvs.osafoundation.org/index.cgi/chandler/repository/tests/data/packs/cineguide/schema/attributes/Next.attr?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/repository/tests/data/packs/cineguide/schema/attributes/Previous.attr?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind.diff?r1=text&tr1=1.8&r2=text&tr2=1.9
http://cvs.osafoundation.org/index.cgi/chandler/repository/util/Streams.py.diff?r1=text&tr1=1.16&r2=text&tr2=1.17

Index: chandler/repository/persistence/RepositoryView.py
diff -u chandler/repository/persistence/RepositoryView.py:1.18 chandler/repository/persistence/RepositoryView.py:1.19
--- chandler/repository/persistence/RepositoryView.py:1.18	Mon Oct 18 13:05:06 2004
+++ chandler/repository/persistence/RepositoryView.py	Mon Oct 25 18:28:57 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.18 $"
-__date__      = "$Date: 2004/10/18 20:05:06 $"
+__revision__  = "$Revision: 1.19 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -532,10 +532,10 @@
 
     def __iter__(self):
         """
-        See L{iterRoots}
+        (deprecated) Use L{iterRoots} instead.
         """
 
-        return self.iterRoots()
+        raise DeprecationWarning, 'Use RepositoryView.iterRoots() instead'
     
     def iterChildren(self):
         """

Index: chandler/repository/item/RefCollections.py
diff -u chandler/repository/item/RefCollections.py:1.2 chandler/repository/item/RefCollections.py:1.3
--- chandler/repository/item/RefCollections.py:1.2	Tue Oct 19 11:31:07 2004
+++ chandler/repository/item/RefCollections.py	Mon Oct 25 18:28:57 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.2 $"
-__date__      = "$Date: 2004/10/19 18:31:07 $"
+__revision__  = "$Revision: 1.3 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -305,26 +305,15 @@
 
         return self._getRef(key)
 
-    def _setRef(self, other, **kwds):
-
-        load = kwds.get('load', True)
-        self.__setitem__(other._uuid, other,
-                         previousKey=kwds.get('previous'),
-                         nextKey=kwds.get('next'),
-                         alias=kwds.get('alias'),
-                         load=load,
-                         direct=False)
-
-        if not load:
-            other._references._getRef(self._otherName, self._item)
+    def _getRef(self, key, load=True):
 
-    def __setitem__(self, key, value,
-                    previousKey=None, nextKey=None, alias=None,
-                    load=True, direct=True):
+        load = load and not self._item.isNew()
+        return super(RefList, self).__getitem__(key, load)
 
-        if direct:
-            raise AssertionError, '%s: direct set not supported' %(self)
+    def _setRef(self, other, **kwds):
 
+        key = other._uuid
+        load = kwds.get('load', True)
         loading = self._getRepository().isLoading()
         
         old = super(RefList, self).get(key, None, load)
@@ -334,15 +323,24 @@
             else:
                 self._setDirty()
 
-        link = super(RefList, self).__setitem__(key, value,
-                                                previousKey, nextKey, alias)
+        link = super(RefList, self).__setitem__(key, other,
+                                                kwds.get('previous'),
+                                                kwds.get('next'),
+                                                kwds.get('alias'))
 
         if not loading:
             if self._indexes:
                 for index in self._indexes.itervalues():
                     index.insertKey(key, link._previousKey)
 
-        return value
+        if not load:
+            other._references._getRef(self._otherName, self._item)
+
+        return other
+
+    def __setitem__(self, key, value):
+
+        raise AssertionError, '%s: direct set not supported, use append' %(self)
 
     def placeItem(self, item, after, *indexNames):
         """
@@ -503,11 +501,6 @@
         if key is not None:
             self._setDirty(noMonitors=True)
 
-    def _getRef(self, key, load=True):
-
-        load = load and not self._item.isNew()
-        return super(RefList, self).__getitem__(key, load)
-
     def get(self, key, default=None, load=True):
         """
         Get the item referenced at C{key}.

Index: chandler/repository/tests/TestMerge.py
diff -u chandler/repository/tests/TestMerge.py:1.9 chandler/repository/tests/TestMerge.py:1.10
--- chandler/repository/tests/TestMerge.py:1.9	Mon Sep 27 13:49:17 2004
+++ chandler/repository/tests/TestMerge.py	Mon Oct 25 18:28:58 2004
@@ -2,8 +2,8 @@
 Test merging of items
 """
 
-__revision__  = "$Revision: 1.9 $"
-__date__      = "$Date: 2004/09/27 20:49:17 $"
+__revision__  = "$Revision: 1.10 $"
+__date__      = "$Date: 2004/10/26 01:28:58 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -418,6 +418,35 @@
 
         self.assert_(m.title == 'changed title')
         self.assert_(len(m.writers) == 0)
+        self.assert_(main.check(), 'main check failed')
+
+    def testMergeNoOverlapVRSingle(self):
+
+        cineguidePack = os.path.join(self.testdir, 'data', 'packs',
+                                     'cineguide.pack')
+        self.rep.loadPack(cineguidePack)
+        self.rep.commit()
+
+        view = self.rep.createView('view')
+        main = self.rep.setCurrentView(view)
+
+        m2 = view.findPath('//CineGuide/m2')
+        m4 = view.findPath('//CineGuide/m4')
+        m2.next = m4
+        view.commit()
+        self.assert_(view.check(), 'view check failed')
+        
+        view = self.rep.setCurrentView(main)
+        m2 = main.findPath('//CineGuide/m2')
+        m2.title = 'changed title'
+        main.commit()
+
+        m2 = main.findPath('//CineGuide/m2')
+        m4 = main.findPath('//CineGuide/m4')
+        self.assert_(m2.title == 'changed title')
+        self.assert_(m2.next is m4)
+        self.assert_(m4.previous is m2)
+        self.assert_(main.check(), 'main check failed')
 
 
 if __name__ == "__main__":

Index: chandler/repository/item/Item.py
diff -u chandler/repository/item/Item.py:1.171 chandler/repository/item/Item.py:1.172
--- chandler/repository/item/Item.py:1.171	Tue Oct 19 11:31:07 2004
+++ chandler/repository/item/Item.py	Mon Oct 25 18:28:56 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.171 $"
-__date__      = "$Date: 2004/10/19 18:31:07 $"
+__revision__  = "$Revision: 1.172 $"
+__date__      = "$Date: 2004/10/26 01:28:56 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -85,10 +85,10 @@
 
     def __iter__(self):
         """
-        Iterate over the children of this item.
+        (deprecated) Use L{iterChildren} instead.
         """
 
-        return self.iterChildren()
+        raise DeprecationWarning, 'Use Item.iterChildren() instead'
 
     def _repr_(self):
 

Index: chandler/repository/util/Streams.py
diff -u chandler/repository/util/Streams.py:1.16 chandler/repository/util/Streams.py:1.17
--- chandler/repository/util/Streams.py:1.16	Mon Oct 18 13:05:12 2004
+++ chandler/repository/util/Streams.py	Mon Oct 25 18:29:01 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.16 $"
-__date__      = "$Date: 2004/10/18 20:05:12 $"
+__revision__  = "$Revision: 1.17 $"
+__date__      = "$Date: 2004/10/26 01:29:01 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -598,7 +598,7 @@
     def __init__(self, unicodeText):
 
         super(StringReader, self).__init__()
-        self.unicodeText = unicodeText
+        self.unicodeText = unicode(unicodeText)
 
     def read(self, length = -1):
 

Index: chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind
diff -u chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind:1.8 chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind:1.9
--- chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind:1.8	Mon Sep 27 13:49:19 2004
+++ chandler/repository/tests/data/packs/cineguide/schema/kinds/Movie.kind	Mon Oct 25 18:28:59 2004
@@ -14,6 +14,8 @@
     <ref alias="writers" type="path">/CineGuide/Attributes/writers</ref>
     <ref alias="synopsis" type="path">/CineGuide/Attributes/synopsis</ref>
     <ref alias="website" type="path">/CineGuide/Attributes/website</ref>
+    <ref alias="next" type="path">/CineGuide/Attributes/next</ref>
+    <ref alias="previous" type="path">/CineGuide/Attributes/previous</ref>
   </ref>
 
   <attribute name="displayAttribute">title</attribute>

Index: chandler/application/Parcel.py
diff -u chandler/application/Parcel.py:1.33 chandler/application/Parcel.py:1.34
--- chandler/application/Parcel.py:1.33	Mon Oct 18 17:57:29 2004
+++ chandler/application/Parcel.py	Mon Oct 25 18:28:56 2004
@@ -1088,11 +1088,10 @@
                  self.repository.findUUID(self.manager.itemUUID))
 
             # Hook up any local attributes to this kind
-            if item.hasChildren():
-                for child in item:
-                    if child.itsKind.itsUUID == self.manager.attrUUID:
-                        # child is an attribute
-                        item.addValue("attributes", child)
+            for child in item.iterChildren():
+                if child.itsKind.itsUUID == self.manager.attrUUID:
+                    # child is an attribute
+                    item.addValue("attributes", child)
 
     def makeValue(self, item, attributeName, attributeTypePath, value):
         """ Creates a value from a string, based on the type

Index: chandler/repository/persistence/XMLRefs.py
diff -u chandler/repository/persistence/XMLRefs.py:1.1 chandler/repository/persistence/XMLRefs.py:1.2
--- chandler/repository/persistence/XMLRefs.py:1.1	Mon Oct 18 13:05:06 2004
+++ chandler/repository/persistence/XMLRefs.py	Mon Oct 25 18:28:57 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.1 $"
-__date__      = "$Date: 2004/10/18 20:05:06 $"
+__revision__  = "$Revision: 1.2 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -210,21 +210,10 @@
         RefList._setItem(self, item)
         PersistentRefs._setItem(self, item)
 
-    def __setitem__(self, key, value,
-                    previousKey=None, nextKey=None, alias=None,
-                    load=True, direct=True):
+    def _setRef(self, other, **kwds):
 
         loading = self.view.isLoading()
-        if loading and previousKey is None and nextKey is None:
-            ref = self._loadRef(key)
-            if ref is not None:
-                previousKey, nextKey, refAlias = ref
-                if alias is not None:
-                    assert alias == refAlias
-
-        value = super(XMLRefList, self).__setitem__(key, value,
-                                                    previousKey, nextKey, alias,
-                                                    load, direct)
+        super(XMLRefList, self)._setRef(other, **kwds)
 
         if not loading:
             self._count += 1

Index: chandler/repository/persistence/Repository.py
diff -u chandler/repository/persistence/Repository.py:1.86 chandler/repository/persistence/Repository.py:1.87
--- chandler/repository/persistence/Repository.py:1.86	Mon Oct 18 13:05:06 2004
+++ chandler/repository/persistence/Repository.py	Mon Oct 25 18:28:57 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.86 $"
-__date__      = "$Date: 2004/10/18 20:05:06 $"
+__revision__  = "$Revision: 1.87 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -264,10 +264,10 @@
 
     def __iter__(self):
         """
-        Iterate over the roots of this repository using the current view.
+        (deprecated) Use L{iterRoots} instead.
         """
 
-        return self.view.__iter__()
+        raise DeprecationWarning, 'Use Repository.iterRoots() instead'
 
     def iterRoots(self, load=True):
         """

Index: chandler/repository/item/ItemHandler.py
diff -u chandler/repository/item/ItemHandler.py:1.53 chandler/repository/item/ItemHandler.py:1.54
--- chandler/repository/item/ItemHandler.py:1.53	Tue Oct 19 11:31:07 2004
+++ chandler/repository/item/ItemHandler.py	Mon Oct 25 18:28:57 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.53 $"
-__date__      = "$Date: 2004/10/19 18:31:07 $"
+__revision__  = "$Revision: 1.54 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -760,6 +760,9 @@
             if self.itemHandler is not None:
                 try:
                     self.itemHandler.startElement(tag, attrs)
+                    if self.itemHandler.exception is not None:
+                        self.exception = self.itemHandler.exception
+                        return
                 except Exception:
                     self.saveException()
                     return
@@ -775,6 +778,9 @@
             if self.itemHandler is not None:
                 try:
                     self.itemHandler.endElement(tag)
+                    if self.itemHandler.exception is not None:
+                        self.exception = self.itemHandler.exception
+                        return
                 except Exception:
                     self.saveException()
                     return
@@ -851,6 +857,7 @@
             elif origRef._isItem() and origRef._uuid == uuid:
                 itemRef = origRef
             else:
+                origItem._references._unloadValue(name, origRef, otherName)
                 itemRef = uuid
 
             self.references[name] = itemRef

Index: chandler/repository/tests/RepositoryTestCase.py
diff -u chandler/repository/tests/RepositoryTestCase.py:1.17 chandler/repository/tests/RepositoryTestCase.py:1.18
--- chandler/repository/tests/RepositoryTestCase.py:1.17	Mon Oct 18 13:05:09 2004
+++ chandler/repository/tests/RepositoryTestCase.py	Mon Oct 25 18:28:58 2004
@@ -1,8 +1,8 @@
 """
 A base class for repository testing
 """
-__revision__  = "$Revision: 1.17 $"
-__date__      = "$Date: 2004/10/18 20:05:09 $"
+__revision__  = "$Revision: 1.18 $"
+__date__      = "$Date: 2004/10/26 01:28:58 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -39,11 +39,12 @@
         self.rep = XMLRepository(os.path.join(self.testdir, '__repository__'))
 
         if os.path.exists(preloadedRepositoryPath):
-            self.ramdb =  False
-            self.rep.open(ramdb=False, fromPath=preloadedRepositoryPath)
+            self.ramdb = False
+            self.rep.open(ramdb=False, fromPath=preloadedRepositoryPath,
+                          stderr=True)
             self.rep.logger.info('Using preloaded repository')
         else:
-            self.rep.create(ramdb=self.ramdb)
+            self.rep.create(ramdb=self.ramdb, stderr=True)
 
             self.rep.loadPack(self.schemaPack)
             self.rep.loadPack(self.chandlerPack)

Index: chandler/repository/item/Values.py
diff -u chandler/repository/item/Values.py:1.22 chandler/repository/item/Values.py:1.23
--- chandler/repository/item/Values.py:1.22	Tue Oct 19 11:31:07 2004
+++ chandler/repository/item/Values.py	Mon Oct 25 18:28:57 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.22 $"
-__date__      = "$Date: 2004/10/19 18:31:07 $"
+__revision__  = "$Revision: 1.23 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -317,9 +317,10 @@
 
     def _setValue(self, name, other, otherName, **kwds):
 
-        value = self.get(name)
-        if value is not None and value._isItem():
-            value._references._removeRef(otherName, self._item)
+        if name in self:
+            value = self._getRef(name)
+            if value is not None and value._isItem():
+                value._references._removeRef(otherName, self._item)
 
         self._setRef(name, other, otherName, **kwds)
         if other is not None:

Index: chandler/repository/tests/data/packs/cineguide/khepburn.movies
diff -u chandler/repository/tests/data/packs/cineguide/khepburn.movies:1.9 chandler/repository/tests/data/packs/cineguide/khepburn.movies:1.10
--- chandler/repository/tests/data/packs/cineguide/khepburn.movies:1.9	Mon Oct 18 13:05:10 2004
+++ chandler/repository/tests/data/packs/cineguide/khepburn.movies	Mon Oct 25 18:28:58 2004
@@ -27,6 +27,7 @@
   </item>
 
   <item>
+    <name>m2</name>
     <kind type="path">//Schema/CineGuide/Kinds/Movie</kind>
 
     <attribute name="title">Morning Glory</attribute>
@@ -47,6 +48,7 @@
   </item>
 
   <item>
+    <name>m3</name>
     <kind type="path">//Schema/CineGuide/Kinds/Movie</kind>
 
     <attribute name="title">Little Women</attribute>
@@ -54,6 +56,8 @@
     <attribute name="released">1933-MM-DD</attribute>
 
     <ref name="director" type="path">//CineGuide/GCukor</ref>
+    <ref name="previous" type="path">//CineGuide/m2</ref>
+
     <ref name="writers">
       <ref type="path">//CineGuide/LMAlcott</ref>
       <ref type="path">//CineGuide/SYMason</ref>
@@ -69,6 +73,7 @@
   </item>
 
   <item>
+    <name>m4</name>
     <kind type="path">//Schema/CineGuide/Kinds/Movie</kind>
 
     <attribute name="title">Spitfire</attribute>
@@ -90,6 +95,7 @@
   </item>
 
   <item>
+    <name>m5</name>
     <kind type="path">//Schema/CineGuide/Kinds/Movie</kind>
 
     <attribute name="title">Alice Adams</attribute>

Index: chandler/repository/persistence/XMLRepository.py
diff -u chandler/repository/persistence/XMLRepository.py:1.85 chandler/repository/persistence/XMLRepository.py:1.86
--- chandler/repository/persistence/XMLRepository.py:1.85	Mon Oct 18 17:57:32 2004
+++ chandler/repository/persistence/XMLRepository.py	Mon Oct 25 18:28:57 2004
@@ -1,10 +1,10 @@
 
-__revision__  = "$Revision: 1.85 $"
-__date__      = "$Date: 2004/10/19 00:57:32 $"
+__revision__  = "$Revision: 1.86 $"
+__date__      = "$Date: 2004/10/26 01:28:57 $"
 __copyright__ = "Copyright (c) 2003-2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
-import os, os.path, re, libxml2, cStringIO
+import os, os.path, libxml2, cStringIO
 
 from datetime import datetime
 from threading import currentThread
@@ -326,8 +326,6 @@
         index = xml.index('version=', xml.index('version=') + 9) + 9
 
         return long(xml[index:xml.index('"', index)])
-
-    nameExp = re.compile("<name>(.*)</name>")
     
 
 class XMLStore(Store):



More information about the Commits mailing list