[Commits] (pavlov) adding item collectioning syncing.. fixing some
bugs
commits at osafoundation.org
commits at osafoundation.org
Thu Aug 19 13:32:57 PDT 2004
Commit by: pavlov
Modified files:
chandler/parcels/osaf/framework/webdav/DAVItem.py 1.5 1.6
chandler/parcels/osaf/framework/webdav/Dav.py 1.7 1.8
chandler/parcels/osaf/framework/webdav/Sync.py 1.4 1.5
chandler/parcels/osaf/framework/webdav/TestDAV.py 1.4 1.5
chandler/parcels/osaf/framework/webdav/davlib.py 1.1 1.2
Log message:
adding item collectioning syncing.. fixing some bugs
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/DAVItem.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Dav.py.diff?r1=text&tr1=1.7&r2=text&tr2=1.8
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/Sync.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.4&r2=text&tr2=1.5
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/webdav/davlib.py.diff?r1=text&tr1=1.1&r2=text&tr2=1.2
Index: chandler/parcels/osaf/framework/webdav/Dav.py
diff -u chandler/parcels/osaf/framework/webdav/Dav.py:1.7 chandler/parcels/osaf/framework/webdav/Dav.py:1.8
--- chandler/parcels/osaf/framework/webdav/Dav.py:1.7 Tue Aug 17 13:24:05 2004
+++ chandler/parcels/osaf/framework/webdav/Dav.py Thu Aug 19 13:32:55 2004
@@ -57,13 +57,14 @@
def put(self, item):
# add an entry here to say that we're already here
- sharing = Globals.repository.findPath('//parcels/osaf/framework/GlobalShare')
+ sharing = Globals.repository.findPath('//parcels/osaf/framework/GlobalShare')
+ #if item.itsUUID not in sharing.values(): # only add us if we originated here
sharing.itemMap[item.itsUUID] = item.itsUUID
-
+
if item.hasAttributeValue('sharedURL'):
# we only support you sharing to a single URL at the moment
# it is an error to try and share to another place..
- if item.sharedURL != self.url:
+ if unicode(item.sharedURL) != unicode(self.url):
print 'Warning: trying to share %s to %s' % (unicode(item.sharedURL), unicode(self.url))
# for now, force our current url to be the shared url
self.url = item.sharedURL
Index: chandler/parcels/osaf/framework/webdav/Sync.py
diff -u chandler/parcels/osaf/framework/webdav/Sync.py:1.4 chandler/parcels/osaf/framework/webdav/Sync.py:1.5
--- chandler/parcels/osaf/framework/webdav/Sync.py:1.4 Tue Aug 17 13:00:47 2004
+++ chandler/parcels/osaf/framework/webdav/Sync.py Thu Aug 19 13:32:55 2004
@@ -91,6 +91,10 @@
makePropString('uuid', '//core', item.itsUUID.str16())
for (name, value) in item.iterAttributeValues():
+ # don't export these local attributes
+ if name in ['etag', 'lastModified', 'sharedURL']:
+ continue
+
# the attribute's namespace is its path...
namespace = kind.getAttribute(name).itsPath[0:-1]
@@ -101,9 +105,9 @@
listData = ''
for i in value:
if isinstance(i, Item):
- # mmm, recursion
defaultURL = dav.url.join(i.itsUUID.str16())
durl = i.getAttributeValue('sharedURL', default=defaultURL)
+ # mmm, recursion
DAV(durl).put(i)
listData += '<itemref>' + unicode(durl) + '</itemref>'
else:
@@ -127,9 +131,25 @@
else:
raise Exception
+ #
+ # XXX refactor this code with the code above
+ #
+ if item.isItemOf(Globals.repository.findPath('//parcels/osaf/contentmodel/ItemCollection')):
+ listData = ''
+ for i in item:
+ # mmm, recursion
+ defaultURL = dav.url.join(i.itsUUID.str16())
+ durl = i.getAttributeValue('sharedURL', default=defaultURL)
+ DAV(durl).put(i)
+ listData += '<itemref>' + unicode(durl) + '</itemref>'
+ props += makePropString('results', '//special/case', listData)
+ #
+ # End refactor
+ #
+
r = dav.newConnection().setprops2(url, props)
- print url, r.status, r.reason
- print r.read()
+ #print url, r.status, r.reason
+ #print r.read()
@@ -176,6 +196,40 @@
print 'Got.....: ', value
item.setAttributeValue(name, attr.type.makeValue(value))
+
+ #
+ # XXX refactor this code
+ #
+ if item.isItemOf(Globals.repository.findPath('//parcels/osaf/contentmodel/ItemCollection')):
+ value = davItem._getAttribute('results', '//special/case')
+
+ # time for some xml parsing! yum!
+
+ # given a chunk of text that is a flat xml tree like:
+ # "<foo/><foo/><foo/>"
+ # parse it and return a list of the nodes
+ xmlgoop = davlib.XML_DOC_HEADER + \
+ '<doc>' + value + '</doc>'
+ doc = libxml2.parseDoc(xmlgoop)
+ nodes = doc.xpathEval('/doc/*')
+
+ serverCollectionResults = []
+ for node in nodes:
+ otherItem = DAV(node.content).get()
+ serverCollectionResults.append(otherItem)
+
+ print 'Merging itemCollection'
+ # for now, just sync with whatever the server gave us
+ for i in serverCollections:
+ if i not in item:
+ item.add(i)
+ for i in item:
+ if i not in serverCollections:
+ item.remove(i)
+ #
+ # End refactor
+ #
+
item.etag = davItem.etag
item.lastModified = davItem.lastModified
item.sharedVersion = item._version # XXX should we commit first?
@@ -186,23 +240,26 @@
def getItem(dav):
repository = Globals.repository
- # fetch the item
- davItem = DAVItem.DAVItem(dav)
+ # Fetch the headers (uuid, kind, etag, lastmodified) from the WebDAV server.
+ davItem = DAVItem.DAVItem(dav, True)
sharing = repository.findPath('//parcels/osaf/framework/GlobalShare')
# get the exported item's UUID and see if we have already fetched it
origUUID = davItem.itsUUID
newItem = repository.findUUID(sharing.itemMap[origUUID])
- if newItem:
- dav.sync(newItem)
- return newItem
- # otherwise, create a new item for the davItem
- kind = davItem.itsKind
- newItem = kind.newItem(None, repository.findPath('//userdata/contentitems'))
+ if not newItem:
+ # create a new item for the davItem
+ kind = davItem.itsKind
+ newItem = kind.newItem(None, repository.findPath('//userdata/contentitems'))
+ newItem.sharedURL = dav.url
+ # set the version to avoid sync thinking there are local changes
+ newItem.sharedVersion = newItem._version
+
+ # toss this in to the itemMap so we can find it later
+ sharing.itemMap[origUUID] = newItem.itsUUID
- # XXX i'd much rather just call syncItem() here...
- syncFromServer(newItem, davItem)
+ dav.sync(newItem)
return newItem
Index: chandler/parcels/osaf/framework/webdav/DAVItem.py
diff -u chandler/parcels/osaf/framework/webdav/DAVItem.py:1.5 chandler/parcels/osaf/framework/webdav/DAVItem.py:1.6
--- chandler/parcels/osaf/framework/webdav/DAVItem.py:1.5 Tue Aug 17 13:24:05 2004
+++ chandler/parcels/osaf/framework/webdav/DAVItem.py Thu Aug 19 13:32:55 2004
@@ -22,31 +22,26 @@
class DAVItem(object):
""" utility class that represents an item from a webdav server """
- def __init__(self, dav):
+ def __init__(self, dav, headersOnly=False):
super(DAVItem, self).__init__()
self.dav = dav
- self.doc = self._allprop(unicode(dav.url))
+ self.doc = self._getprops(unicode(dav.url), headersOnly)
- def _allprop(self, url, depth = 0):
+ def _getprops(self, url, headersOnly=False):
""" Fetch all the properties of a resource """
+ # XXX this doesn't work, but should...
+ # if headersOnly:
+ # props = '<O:uuid/><O:kind/>'
+ # else:
+ # props = '<D:allprop/>'
+
body = davlib.XML_DOC_HEADER + \
- '<D:propfind xmlns:D="DAV:">' + \
+ '<D:propfind xmlns:D="DAV:" xmlns:O="//core">' + \
'<D:allprop/><D:getetag/><D:getlastmodified/>' + \
'</D:propfind>'
- # In order to get see if the etag matches something, we need
- # to first fetch the item, get its uuid and getetag properties.
- # At that point we can look it up in the itemMap and see if we
- # already have it, and then match the etag associated with that.
- #
- # for now, lets just fetch all the properties and match the etag
- # later.
- #
- # we could also make the get code smarter by allowing you to "get"
- # an item that was already shared (and hence has a url and an etag
- # already. This might be the best solution.
- r = self.dav.newConnection().propfind(url, body, depth)
+ r = self.dav.newConnection().propfind(url, body, 0)
if r.status == 404:
raise Dav.NotFound
Index: chandler/parcels/osaf/framework/webdav/davlib.py
diff -u chandler/parcels/osaf/framework/webdav/davlib.py:1.1 chandler/parcels/osaf/framework/webdav/davlib.py:1.2
--- chandler/parcels/osaf/framework/webdav/davlib.py:1.1 Mon Jun 28 13:03:20 2004
+++ chandler/parcels/osaf/framework/webdav/davlib.py Thu Aug 19 13:32:55 2004
@@ -9,7 +9,7 @@
#
# Since this isn't in the Python distribution yet, we'll use the CVS ID
# for tracking:
-# $Id: davlib.py,v 1.1 2004/06/28 20:03:20 pavlov Exp $
+# $Id: davlib.py,v 1.2 2004/08/19 20:32:55 pavlov Exp $
#
import httplib
@@ -215,8 +215,6 @@
'<D:set><D:prop>' + xmlstuff + '</D:prop></D:set>' + \
'</D:propertyupdate>'
- print body
-
return self.proppatch(url, body)
Index: chandler/parcels/osaf/framework/webdav/TestDAV.py
diff -u chandler/parcels/osaf/framework/webdav/TestDAV.py:1.4 chandler/parcels/osaf/framework/webdav/TestDAV.py:1.5
--- chandler/parcels/osaf/framework/webdav/TestDAV.py:1.4 Mon Aug 16 17:26:42 2004
+++ chandler/parcels/osaf/framework/webdav/TestDAV.py Thu Aug 19 13:32:55 2004
@@ -1,5 +1,5 @@
-__revision__ = "$Revision: 1.4 $"
-__date__ = "$Date: 2004/08/17 00:26:42 $"
+__revision__ = "$Revision: 1.5 $"
+__date__ = "$Date: 2004/08/19 20:32:55 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -21,16 +21,21 @@
self.loadParcel("http://osafoundation.org/parcels/osaf/framework/webdav")
self.loadParcel("http://osafoundation.org/parcels/osaf/contentmodel/calendar")
+ self.loadParcel("http://osafoundation.org/parcels/osaf/contentmodel")
return
+ # this should return None
+ #DAV('http://code-bear.com/dav/this_item_doesnt_exist').get()
+
""" item exporting """
testItem = GenerateItems.GenerateCalendarEvent(100)
- url = 'http://code-bear.com/dav/' + testItem.itsUUID.str16()
+ url = 'http://code-bear.com/dav/' + 'my_test_item' #testItem.itsUUID.str16()
a = DAV(url)
+ print 'put 1'
a.put(testItem)
+ print 'put 2'
a.put(testItem)
- print url
""" item fetching """
# fetch the item we put above
@@ -38,6 +43,8 @@
testItem2 = DAV(url).get()
testItem3 = DAV(url).get()
+
+
print testItem, testItem2, testItem3
More information about the Commits
mailing list