[Commits] (pavlov) adding local versioning checks for
putting/syncing.
commits at osafoundation.org
commits at osafoundation.org
Mon Aug 16 11:43:45 PDT 2004
Commit by: pavlov
Modified files:
chandler/parcels/osaf/framework/webdav/Dav.py 1.3 1.4
chandler/parcels/osaf/framework/webdav/Export.py 1.4 1.5
chandler/parcels/osaf/framework/webdav/Import.py 1.4 1.5
chandler/parcels/osaf/framework/webdav/TestDAV.py 1.1 1.2
Log message:
adding local versioning checks for putting/syncing.
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Dav.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Export.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Import.py.diff?r1=text&tr1=1.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/TestDAV.py.diff?r1=text&tr1=1.1&r2=text&tr2=1.2
Index: chandler/parcels/osaf/framework/webdav/Import.py
diff -u chandler/parcels/osaf/framework/webdav/Import.py:1.4 chandler/parcels/osaf/framework/webdav/Import.py:1.5
--- chandler/parcels/osaf/framework/webdav/Import.py:1.4 Thu Aug 12 11:00:32 2004
+++ chandler/parcels/osaf/framework/webdav/Import.py Mon Aug 16 11:43:44 2004
@@ -48,11 +48,25 @@
else:
print oldEtag, di.etag
- newItem.etag = di.etag
- newItem.lastModified = di.lastModified
+ sync(newItem, di)
+
+ return newItem
+
+def sync(item, di=None):
+ if not di:
+ # fetch the item
+ di = DAVItem.DAVItem(item.sharedURL)
+
+ if item.sharedVersion == item._version:
+ print 'same version', item.sharedVersion
+ return False
+
+ item.etag = di.etag
+ item.lastModified = di.lastModified
+
# XXX hack...
- sharing.itemMap[origUUID] = newItem.itsUUID
+ sharing.itemMap[origUUID] = item.itsUUID
for (name, attr) in kind.iterAttributes(True):
@@ -70,17 +84,16 @@
if attr.cardinality == 'list':
for node in nodes:
otherItem = DAV(node.content).get()
- newItem.addValue(name, otherItem)
+ item.addValue(name, otherItem)
elif attr.cardinality == 'single':
node = nodes[0]
otherItem = DAV(node.content).get()
- newItem.setAttributeValue(name, otherItem)
+ item.setAttributeValue(name, otherItem)
else:
raise Exception
else:
- #newItem.setAttributeValue(name, value)
print 'Got.....: ', value
- newItem.setAttributeValue(name, attr.type.makeValue(value))
+ item.setAttributeValue(name, attr.type.makeValue(value))
- return newItem
+ item.sharedVersion = item._version
Index: chandler/parcels/osaf/framework/webdav/Dav.py
diff -u chandler/parcels/osaf/framework/webdav/Dav.py:1.3 chandler/parcels/osaf/framework/webdav/Dav.py:1.4
--- chandler/parcels/osaf/framework/webdav/Dav.py:1.3 Thu Aug 12 11:00:32 2004
+++ chandler/parcels/osaf/framework/webdav/Dav.py Mon Aug 16 11:43:44 2004
@@ -79,8 +79,8 @@
return self.url
- def sync(self):
- raise NotImplementedError
+ def sync(self, item):
+ return Import.sync(item)
class DAVConnection(davlib.DAV):
Index: chandler/parcels/osaf/framework/webdav/Export.py
diff -u chandler/parcels/osaf/framework/webdav/Export.py:1.4 chandler/parcels/osaf/framework/webdav/Export.py:1.5
--- chandler/parcels/osaf/framework/webdav/Export.py:1.4 Thu Aug 12 11:00:32 2004
+++ chandler/parcels/osaf/framework/webdav/Export.py Mon Aug 16 11:43:44 2004
@@ -27,20 +27,35 @@
# instead of this, we should figure out a way to know if the item has changed since its last
# etag.. maybe watch for commits? if it has, then we should see if the thing on the server
# has changed.. if-match? and then try again. we gotta get rid of this hack....
- if hasattr(item, 'davified'):
+ #
+ # first check and see if item.hasAttributeValue('etag'). if not then put
+ # the item without thinking.
+ # if it does have an etag, then we need to see if the local Item has changed
+ # since they last time we pushed it to the server. If it hasn't changed,
+ # then just return. If it has changed, then we need to sync our copy with
+ # the server prior to pushing things back up to the server
+ if item.sharedVersion == item._version:
+ # this isn't quite right...
+ # we really still need to check the etag before returning here,
+ # but this will allow us to at least put new changes if we have
+ # them locally... see the comment just below about the etag
return
- item.davified = True
url = unicode(dav.url)
# need to put an If-Match header here with the item's etag if it exists
extraHeaders = {}
- etag = item.getAttributeValue('etag', default=None)
- if etag:
- extraHeaders['If-Match'] = etag
+ # XXX not quite right. need to only do this if we have an etag, the etag on
+ # the server is the same, AND the version has changed
+ #
+ #etag = item.getAttributeValue('etag', default=None)
+ #if etag:
+ # extraHeaders['If-Match'] = etag
r = dav.newConnection().put(url, item.itsKind.itsName, 'text/plain', None, extraHeaders)
+ print r.read()
+
# now we need to see if this request failed due to the etags being different
# need to handle merging/conflicts here...
@@ -48,6 +63,7 @@
# set them here, even though we have to set them again later
item.etag = r.getheader('ETag', default='')
item.lastModified = r.getheader('Last-Modified', default='')
+ item.sharedVersion = item._version
# ew...
sharing = Globals.repository.findPath('//parcels/osaf/framework/GlobalShare')
@@ -78,7 +94,7 @@
data = data + '<itemref>' + unicode(durl) + '</itemref>'
else:
- # add literal list stuff here
+ # XXX TODO add literal list stuff here
pass
data = data + ']]></osaf:%s>' % (name)
else:
@@ -111,5 +127,7 @@
item.etag = r.getheader('ETag', default='')
item.lastModified = r.getheader('Last-Modified', default='')
+ item.sharedVersion = item._version
+
return url
#print propstring
Index: chandler/parcels/osaf/framework/webdav/TestDAV.py
diff -u chandler/parcels/osaf/framework/webdav/TestDAV.py:1.1 chandler/parcels/osaf/framework/webdav/TestDAV.py:1.2
--- chandler/parcels/osaf/framework/webdav/TestDAV.py:1.1 Thu Aug 12 11:00:32 2004
+++ chandler/parcels/osaf/framework/webdav/TestDAV.py Mon Aug 16 11:43:44 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.1 $"
-__date__ = "$Date: 2004/08/12 18:00:32 $"
+__revision__ = "$Revision: 1.2 $"
+__date__ = "$Date: 2004/08/16 18:43:44 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -22,14 +22,12 @@
self.loadParcel("http://osafoundation.org/parcels/osaf/framework/webdav")
self.loadParcel("http://osafoundation.org/parcels/osaf/contentmodel/calendar")
- # return early for now so that these tests are not run by default
- return
-
""" item exporting """
testItem = GenerateItems.GenerateCalendarEvent(100)
url = 'http://code-bear.com/dav/' + testItem.itsUUID.str16()
a = DAV(url)
a.put(testItem)
+ a.put(testItem)
print url
""" item fetching """
More information about the Commits
mailing list