[Commits] (pavlov) refactoring most of the sharing code in to Sync.py -- fixing numerous synchronization problems.

commits at osafoundation.org commits at osafoundation.org
Mon Aug 16 17:26:44 PDT 2004


Commit by: pavlov
Modified files:
chandler/parcels/osaf/framework/webdav/Sync.py None 1.1
chandler/parcels/osaf/framework/webdav/DAVItem.py 1.3 1.4
chandler/parcels/osaf/framework/webdav/Dav.py 1.4 1.5
chandler/parcels/osaf/framework/webdav/Export.py 1.5 1.6
chandler/parcels/osaf/framework/webdav/Import.py 1.5 1.6
chandler/parcels/osaf/framework/webdav/TestDAV.py 1.3 1.4

Log message:
refactoring most of the sharing code in to Sync.py -- fixing numerous synchronization problems.


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Sync.py?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/DAVItem.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Dav.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Export.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Import.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/TestDAV.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4

Index: chandler/parcels/osaf/framework/webdav/TestDAV.py
diff -u chandler/parcels/osaf/framework/webdav/TestDAV.py:1.3 chandler/parcels/osaf/framework/webdav/TestDAV.py:1.4
--- chandler/parcels/osaf/framework/webdav/TestDAV.py:1.3	Mon Aug 16 11:46:53 2004
+++ chandler/parcels/osaf/framework/webdav/TestDAV.py	Mon Aug 16 17:26:42 2004
@@ -1,5 +1,5 @@
-__revision__  = "$Revision: 1.3 $"
-__date__      = "$Date: 2004/08/16 18:46:53 $"
+__revision__  = "$Revision: 1.4 $"
+__date__      = "$Date: 2004/08/17 00:26:42 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -39,10 +39,12 @@
         testItem3 = DAV(url).get()
 
         print testItem, testItem2, testItem3
+
+        
         """ export item collections """
         """
         ic = ItemCollection.NamedCollection()
-        for index in range(10):
+        for index in range(5):
             ic.add(GenerateItems.GenerateCalendarEvent(100))
 
         a = DAV('http://code-bear.com/dav/' + str(ic.itsUUID)).putCollection(ic)

Index: chandler/parcels/osaf/framework/webdav/Import.py
diff -u chandler/parcels/osaf/framework/webdav/Import.py:1.5 chandler/parcels/osaf/framework/webdav/Import.py:1.6
--- chandler/parcels/osaf/framework/webdav/Import.py:1.5	Mon Aug 16 11:43:44 2004
+++ chandler/parcels/osaf/framework/webdav/Import.py	Mon Aug 16 17:26:42 2004
@@ -97,3 +97,5 @@
             item.setAttributeValue(name, attr.type.makeValue(value))
 
     item.sharedVersion = item._version
+
+    return True

Index: chandler/parcels/osaf/framework/webdav/Export.py
diff -u chandler/parcels/osaf/framework/webdav/Export.py:1.5 chandler/parcels/osaf/framework/webdav/Export.py:1.6
--- chandler/parcels/osaf/framework/webdav/Export.py:1.5	Mon Aug 16 11:43:44 2004
+++ chandler/parcels/osaf/framework/webdav/Export.py	Mon Aug 16 17:26:42 2004
@@ -64,6 +64,7 @@
     item.etag = r.getheader('ETag', default='')
     item.lastModified = r.getheader('Last-Modified', default='')
     item.sharedVersion = item._version
+    item.sharedURL = dav.url
 
     # ew...
     sharing = Globals.repository.findPath('//parcels/osaf/framework/GlobalShare') 

Index: chandler/parcels/osaf/framework/webdav/DAVItem.py
diff -u chandler/parcels/osaf/framework/webdav/DAVItem.py:1.3 chandler/parcels/osaf/framework/webdav/DAVItem.py:1.4
--- chandler/parcels/osaf/framework/webdav/DAVItem.py:1.3	Thu Aug 12 11:00:32 2004
+++ chandler/parcels/osaf/framework/webdav/DAVItem.py	Mon Aug 16 17:26:42 2004
@@ -47,8 +47,6 @@
         r = self.dav.newConnection().propfind(url, body, depth)
 
         xmlgoop = r.read()
-        print url
-        print xmlgoop
 
         doc = libxml2.parseDoc(xmlgoop)
 

Index: chandler/parcels/osaf/framework/webdav/Dav.py
diff -u chandler/parcels/osaf/framework/webdav/Dav.py:1.4 chandler/parcels/osaf/framework/webdav/Dav.py:1.5
--- chandler/parcels/osaf/framework/webdav/Dav.py:1.4	Mon Aug 16 11:43:44 2004
+++ chandler/parcels/osaf/framework/webdav/Dav.py	Mon Aug 16 17:26:42 2004
@@ -3,7 +3,8 @@
 from repository.item.Item import Item
 from repository.util.URL import URL
 
-import Import, Export
+import application.Globals as Globals
+import Import, Export, Sync
 
 """
  * If I make ItemCollections use a refcollection under the hood as a real attribute
@@ -25,12 +26,42 @@
     def newConnection(self):
         return DAVConnection(self.url)
 
-    # importing
+    def putResource(self, body, mimetype='text/plain/'):
+        return self.newConnection().put(unicode(self.url), body, mimetype, None)
+        # return status.. or maybe just throw an exception if the put failed
+
+    def getHeaders(self):
+        return self.newConnection().head(unicode(self.url))
+
+    def _getETag(self):
+        return self.getHeaders().getheader('ETag', default='')
+
+    def _getLastModified(self):
+        return self.getHeaders().getheader('Last-Modified', default='')
+
+
     def get(self):
         """ returns a newly created Item """
-        return Import.getItem(self)
+        return Sync.getItem(self)
+
+    def put(self, item):
+        # add an entry here to say that we're already here
+        sharing = Globals.repository.findPath('//parcels/osaf/framework/GlobalShare') 
+        sharing.itemMap[item.itsUUID] = item.itsUUID
+
+        item.sharedURL = self.url
+        self.sync(item)
+
+    def sync(self, item):
+        return Sync.syncItem(self, item)
+
+
+    etag = property(_getETag)
+    lastModified = property(_getLastModified)
+
 
     def getCollection(self):
+        # this code can't work.
         """ gives back a new ItemCollection """
         collection = self.get()
 
@@ -47,15 +78,12 @@
         # get a listing of all items in the collection... propfind depth 1
 
         # make a new ItemCollection based on the properties of the dav
-        # collection
+        # collection        if not changed:
 
         # for each resource found in the dav collection, get it and add it to
         # our itemcollection
-        pass
 
-    # exporting
-    def put(self, item):
-        Export.putItem(self, item)
+
 
     def putCollection(self, itemCollection):
         """
@@ -79,8 +107,26 @@
 
         return self.url
 
-    def sync(self, item):
-        return Import.sync(item)
+
+
+
+    def syncCollection(self, itemCollection):
+        """ gives back a new ItemCollection """
+        # this will update the itemcollection if needed
+        self.sync(itemCollection)
+
+
+        # if the collection item itself hasn't changed, sync up the current
+        # items in the collection
+        for item in itemCollection:
+            DAV(item.sharedURL).sync(item)
+            
+            listXmlGoop = collection._getAttribute('http://www.osafoundation.org/', 'items')
+            nodes = Import.makeAndParse(listXmlGoop)
+
+            for node in nodes:
+                item = DAV(node.content).get()
+                collection.add(item)
 
 
 class DAVConnection(davlib.DAV):



More information about the Commits mailing list