[prev in list] [next in list] [prev in thread] [next in thread]
List: calendarserver-changes
Subject: [CalendarServer-changes] [2340]
From: source_changes () macosforge ! org
Date: 2008-04-24 17:59:28
Message-ID: 20080424175928.4DD0C15DADBD () beta ! macosforge ! org
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Revision: 2340
http://trac.macosforge.org/projects/calendarserver/changeset/2340
Author: dreid@apple.com
Date: 2008-04-24 10:59:26 -0700 (Thu, 24 Apr 2008)
Log Message:
-----------
In updateCTag trigger a dataChanged notification and in createSimilarFile attach the \
cacheNotifier
Modified Paths:
--------------
CalendarServer/branches/propfind-cache/twistedcaldav/static.py
Modified: CalendarServer/branches/propfind-cache/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/static.py 2008-04-24 \
00:11:49 UTC (rev 2339)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/static.py 2008-04-24 \
17:59:26 UTC (rev 2340) @@ -71,6 +71,8 @@
from twistedcaldav.directory.calendar import DirectoryCalendarHomeResource
from twistedcaldav.directory.resource import AutoProvisioningResourceMixIn
+from twistedcaldav.cache import CacheChangeNotifier
+
class CalDAVFile (CalDAVResource, DAVFile):
"""
CalDAV-accessible L{DAVFile} resource.
@@ -117,9 +119,9 @@
responsecode.FORBIDDEN,
(caldavxml.caldav_namespace, "calendar-collection-location-ok")
))
-
+
return self.createCalendarCollection()
-
+
parent = self._checkParents(request, isPseudoCalendarCollectionResource)
parent.addCallback(_defer)
return parent
@@ -131,13 +133,13 @@
def onCalendarCollection(status):
if status != responsecode.CREATED:
raise HTTPError(status)
-
+
# Initialize CTag on the calendar collection
self.updateCTag()
-
+
# Create the index so its ready when the first PUTs come in
self.index().create()
-
+
return status
d = self.createSpecialCollection(davxml.ResourceType.calendar)
@@ -151,10 +153,10 @@
def onCollection(status):
if status != responsecode.CREATED:
raise HTTPError(status)
-
+
self.writeDeadProperty(resourceType)
return status
-
+
def onError(f):
try:
rmdir(self.fp)
@@ -167,7 +169,7 @@
d.addCallback(onCollection)
d.addErrback(onError)
return d
-
+
def iCalendarRolledup(self, request):
if self.isPseudoCalendarCollection():
# Generate a monolithic calendar
@@ -189,7 +191,7 @@
child = IDAVResource(child)
except TypeError:
child = None
-
+
if child is not None:
# Check privileges of child - skip if access denied
try:
@@ -203,7 +205,7 @@
for component in subcalendar.subcomponents():
calendar.addComponent(component)
-
+
yield calendar
return
@@ -256,7 +258,7 @@
d = self.locateParent(request, request.urlForResource(self))
d.addCallback(gotParent)
return d
-
+
return super(CalDAVFile, self).supportedPrivileges(request)
##
@@ -284,6 +286,9 @@
def updateCTag(self):
assert self.isCollection()
+ if hasattr(self, 'cacheNotifier'):
+ self.cacheNotifier.dataChanged()
+
self.writeDeadProperty(customxml.GETCTag(str(datetime.datetime.now())))
##
@@ -303,17 +308,17 @@
"""
Recursively descend the directory tree rooted at top,
calling the callback function for each regular file
-
+
@param top: L{FilePath} for the directory to walk.
"""
-
+
total = 0
for f in top.listdir():
-
+
# Ignore the database
if f.startswith("."):
continue
-
+
child = top.child(f)
if child.isdir():
# It's a directory, recurse into it
@@ -326,11 +331,11 @@
else:
# Unknown file type, print a message
pass
-
+
yield total
-
+
walktree = deferredGenerator(walktree)
-
+
return walktree(self.fp)
else:
return succeed(self.fp.getsize())
@@ -354,20 +359,20 @@
#
# Parse the URI
#
-
+
(scheme, host, path, query, fragment) = urlsplit(uri) #@UnusedVariable
-
+
# Request hostname and child uri hostname have to be the same.
if host and host != request.headers.getHeader("host"):
return False
-
+
# Child URI must start with request uri text.
parent = request.uri
if not parent.endswith("/"):
parent += "/"
-
+
return path.startswith(parent) and (len(path) > len(parent)) and (not \
immediateChild or (path.find("/", len(parent)) == -1))
-
+
def _checkParents(self, request, test):
"""
@param request: the request being processed.
@@ -392,7 +397,7 @@
return
yield None
-
+
_checkParents = deferredGenerator(_checkParents)
class AutoProvisioningFileMixIn (AutoProvisioningResourceMixIn):
@@ -413,7 +418,7 @@
parent = self.parent
if not parent.exists() and isinstance(parent, \
AutoProvisioningFileMixIn): parent.provision()
-
+
assert parent.exists(), "Parent %s of %s does not exist" % (parent, \
self)
assert parent.isCollection(), "Parent %s of %s is not a collection" % \
(parent, self)
@@ -434,7 +439,7 @@
class CalendarHomeProvisioningFile (AutoProvisioningFileMixIn, \
DirectoryCalendarHomeProvisioningResource, DAVFile): """
- Resource which provisions calendar home collections as needed.
+ Resource which provisions calendar home collections as needed.
"""
def __init__(self, path, directory, url):
"""
@@ -526,6 +531,7 @@
"""
CalDAVFile.__init__(self, path)
DirectoryCalendarHomeResource.__init__(self, parent, record)
+ self.cacheNotifier = CacheChangeNotifier(self.deadProperties())
def provisionChild(self, name):
if config.EnableDropBox:
@@ -536,7 +542,7 @@
NotificationsCollectionFileClass = NotificationsCollectionFile
else:
NotificationsCollectionFileClass = None
-
+
cls = {
"inbox" : ScheduleInboxFile,
"outbox" : ScheduleOutboxFile,
@@ -553,7 +559,9 @@
if path == self.fp.path:
return self
else:
- return CalDAVFile(path, \
principalCollections=self.principalCollections()) + similar = \
CalDAVFile(path, principalCollections=self.principalCollections()) + \
similar.cacheNotifier = self.cacheNotifier + return similar
def getChild(self, name):
# This avoids finding case variants of put children on case-insensitive \
filesystems. @@ -721,9 +729,9 @@
elements = []
elements.append(customxml.TimeStamp.fromString(timestamp))
elements.append(customxml.Changed(davxml.HRef.fromString(parentURL)))
-
+
xml = customxml.Notification(*elements)
-
+
d = waitForDeferred(put_common_base.storeResource(request, data=xml.toxml(), \
destination=self, destination_uri=request.urlForResource(self))) yield d
d.getResult()
[Attachment #5 (text/html)]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style \
type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: \
6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: \
verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: \
bold} #msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: \
bold; } #msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; \
padding: 6px; } #msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: \
6px; } #patch { width: 100%; }
#patch h4 {font-family: \
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, \
#patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins \
{background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del \
{background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, \
.info {color:#888;background:#fff;}
--></style>
<title>[2340] CalendarServer/branches/propfind-cache/twistedcaldav/static.py</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a \
href="http://trac.macosforge.org/projects/calendarserver/changeset/2340">2340</a></dd>
<dt>Author</dt> <dd>dreid@apple.com</dd>
<dt>Date</dt> <dd>2008-04-24 10:59:26 -0700 (Thu, 24 Apr 2008)</dd>
</dl>
<h3>Log Message</h3>
<pre>In updateCTag trigger a dataChanged notification and in createSimilarFile attach \
the cacheNotifier</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchespropfindcachetwistedcaldavstaticpy">CalendarServer/branches/propfind-cache/twistedcaldav/static.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchespropfindcachetwistedcaldavstaticpy"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/branches/propfind-cache/twistedcaldav/static.py (2339 => 2340)</h4> \
<pre class="diff"><span> <span class="info">--- \
CalendarServer/branches/propfind-cache/twistedcaldav/static.py 2008-04-24 00:11:49 \
UTC (rev 2339)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/static.py 2008-04-24 \
17:59:26 UTC (rev 2340) </span><span class="lines">@@ -71,6 +71,8 @@
</span><span class="cx"> from twistedcaldav.directory.calendar import \
DirectoryCalendarHomeResource </span><span class="cx"> from \
twistedcaldav.directory.resource import AutoProvisioningResourceMixIn </span><span \
class="cx"> </span><ins>+from twistedcaldav.cache import CacheChangeNotifier
+
</ins><span class="cx"> class CalDAVFile (CalDAVResource, DAVFile):
</span><span class="cx"> """
</span><span class="cx"> CalDAV-accessible L{DAVFile} resource.
</span><span class="lines">@@ -117,9 +119,9 @@
</span><span class="cx"> responsecode.FORBIDDEN,
</span><span class="cx"> (caldavxml.caldav_namespace, \
"calendar-collection-location-ok") </span><span class="cx"> \
)) </span><del>-
</del><ins>+
</ins><span class="cx"> return self.createCalendarCollection()
</span><del>-
</del><ins>+
</ins><span class="cx"> parent = self._checkParents(request, \
isPseudoCalendarCollectionResource) </span><span class="cx"> \
parent.addCallback(_defer) </span><span class="cx"> return parent
</span><span class="lines">@@ -131,13 +133,13 @@
</span><span class="cx"> def onCalendarCollection(status):
</span><span class="cx"> if status != responsecode.CREATED:
</span><span class="cx"> raise HTTPError(status)
</span><del>-
</del><ins>+
</ins><span class="cx"> # Initialize CTag on the calendar collection
</span><span class="cx"> self.updateCTag()
</span><del>-
</del><ins>+
</ins><span class="cx"> # Create the index so its ready when the first \
PUTs come in </span><span class="cx"> self.index().create()
</span><del>-
</del><ins>+
</ins><span class="cx"> return status
</span><span class="cx">
</span><span class="cx"> d = \
self.createSpecialCollection(davxml.ResourceType.calendar) </span><span \
class="lines">@@ -151,10 +153,10 @@ </span><span class="cx"> def \
onCollection(status): </span><span class="cx"> if status != \
responsecode.CREATED: </span><span class="cx"> raise \
HTTPError(status) </span><del>-
</del><ins>+
</ins><span class="cx"> self.writeDeadProperty(resourceType)
</span><span class="cx"> return status
</span><del>-
</del><ins>+
</ins><span class="cx"> def onError(f):
</span><span class="cx"> try:
</span><span class="cx"> rmdir(self.fp)
</span><span class="lines">@@ -167,7 +169,7 @@
</span><span class="cx"> d.addCallback(onCollection)
</span><span class="cx"> d.addErrback(onError)
</span><span class="cx"> return d
</span><del>-
</del><ins>+
</ins><span class="cx"> def iCalendarRolledup(self, request):
</span><span class="cx"> if self.isPseudoCalendarCollection():
</span><span class="cx"> # Generate a monolithic calendar
</span><span class="lines">@@ -189,7 +191,7 @@
</span><span class="cx"> child = IDAVResource(child)
</span><span class="cx"> except TypeError:
</span><span class="cx"> child = None
</span><del>-
</del><ins>+
</ins><span class="cx"> if child is not None:
</span><span class="cx"> # Check privileges of child - skip if \
access denied </span><span class="cx"> try:
</span><span class="lines">@@ -203,7 +205,7 @@
</span><span class="cx">
</span><span class="cx"> for component in \
subcalendar.subcomponents(): </span><span class="cx"> \
calendar.addComponent(component) </span><del>-
</del><ins>+
</ins><span class="cx"> yield calendar
</span><span class="cx"> return
</span><span class="cx">
</span><span class="lines">@@ -256,7 +258,7 @@
</span><span class="cx"> d = self.locateParent(request, \
request.urlForResource(self)) </span><span class="cx"> \
d.addCallback(gotParent) </span><span class="cx"> return d
</span><del>-
</del><ins>+
</ins><span class="cx"> return super(CalDAVFile, \
self).supportedPrivileges(request) </span><span class="cx">
</span><span class="cx"> ##
</span><span class="lines">@@ -284,6 +286,9 @@
</span><span class="cx">
</span><span class="cx"> def updateCTag(self):
</span><span class="cx"> assert self.isCollection()
</span><ins>+ if hasattr(self, 'cacheNotifier'):
+ self.cacheNotifier.dataChanged()
+
</ins><span class="cx"> \
self.writeDeadProperty(customxml.GETCTag(str(datetime.datetime.now()))) </span><span \
class="cx"> </span><span class="cx"> ##
</span><span class="lines">@@ -303,17 +308,17 @@
</span><span class="cx"> """
</span><span class="cx"> Recursively descend the directory tree \
rooted at top, </span><span class="cx"> calling the callback function \
for each regular file </span><del>-
</del><ins>+
</ins><span class="cx"> @param top: L{FilePath} for the directory to \
walk. </span><span class="cx"> """
</span><del>-
</del><ins>+
</ins><span class="cx"> total = 0
</span><span class="cx"> for f in top.listdir():
</span><del>-
</del><ins>+
</ins><span class="cx"> # Ignore the database
</span><span class="cx"> if f.startswith("."):
</span><span class="cx"> continue
</span><del>-
</del><ins>+
</ins><span class="cx"> child = top.child(f)
</span><span class="cx"> if child.isdir():
</span><span class="cx"> # It's a directory, recurse into it
</span><span class="lines">@@ -326,11 +331,11 @@
</span><span class="cx"> else:
</span><span class="cx"> # Unknown file type, print a message
</span><span class="cx"> pass
</span><del>-
</del><ins>+
</ins><span class="cx"> yield total
</span><del>-
</del><ins>+
</ins><span class="cx"> walktree = deferredGenerator(walktree)
</span><del>-
</del><ins>+
</ins><span class="cx"> return walktree(self.fp)
</span><span class="cx"> else:
</span><span class="cx"> return succeed(self.fp.getsize())
</span><span class="lines">@@ -354,20 +359,20 @@
</span><span class="cx"> #
</span><span class="cx"> # Parse the URI
</span><span class="cx"> #
</span><del>-
</del><ins>+
</ins><span class="cx"> (scheme, host, path, query, fragment) = urlsplit(uri) \
#@UnusedVariable </span><del>-
</del><ins>+
</ins><span class="cx"> # Request hostname and child uri hostname have to be \
the same. </span><span class="cx"> if host and host != \
request.headers.getHeader("host"): </span><span class="cx"> \
return False </span><del>-
</del><ins>+
</ins><span class="cx"> # Child URI must start with request uri text.
</span><span class="cx"> parent = request.uri
</span><span class="cx"> if not parent.endswith("/"):
</span><span class="cx"> parent += "/"
</span><del>-
</del><ins>+
</ins><span class="cx"> return path.startswith(parent) and (len(path) > \
len(parent)) and (not immediateChild or (path.find("/", len(parent)) == \
-1)) </span><del>-
</del><ins>+
</ins><span class="cx"> def _checkParents(self, request, test):
</span><span class="cx"> """
</span><span class="cx"> @param request: the request being processed.
</span><span class="lines">@@ -392,7 +397,7 @@
</span><span class="cx"> return
</span><span class="cx">
</span><span class="cx"> yield None
</span><del>-
</del><ins>+
</ins><span class="cx"> _checkParents = deferredGenerator(_checkParents)
</span><span class="cx">
</span><span class="cx"> class AutoProvisioningFileMixIn \
(AutoProvisioningResourceMixIn): </span><span class="lines">@@ -413,7 +418,7 @@
</span><span class="cx"> parent = self.parent
</span><span class="cx"> if not parent.exists() and isinstance(parent, \
AutoProvisioningFileMixIn): </span><span class="cx"> \
parent.provision() </span><del>-
</del><ins>+
</ins><span class="cx"> assert parent.exists(), "Parent %s of %s \
does not exist" % (parent, self) </span><span class="cx"> assert \
parent.isCollection(), "Parent %s of %s is not a collection" % (parent, \
self) </span><span class="cx">
</span><span class="lines">@@ -434,7 +439,7 @@
</span><span class="cx">
</span><span class="cx"> class CalendarHomeProvisioningFile \
(AutoProvisioningFileMixIn, DirectoryCalendarHomeProvisioningResource, DAVFile): \
</span><span class="cx"> """ </span><del>- Resource which \
provisions calendar home collections as needed. </del><ins>+ Resource which \
provisions calendar home collections as needed. </ins><span class="cx"> \
""" </span><span class="cx"> def __init__(self, path, directory, \
url): </span><span class="cx"> """
</span><span class="lines">@@ -526,6 +531,7 @@
</span><span class="cx"> """
</span><span class="cx"> CalDAVFile.__init__(self, path)
</span><span class="cx"> DirectoryCalendarHomeResource.__init__(self, parent, \
record) </span><ins>+ self.cacheNotifier = \
CacheChangeNotifier(self.deadProperties()) </ins><span class="cx">
</span><span class="cx"> def provisionChild(self, name):
</span><span class="cx"> if config.EnableDropBox:
</span><span class="lines">@@ -536,7 +542,7 @@
</span><span class="cx"> NotificationsCollectionFileClass = \
NotificationsCollectionFile </span><span class="cx"> else:
</span><span class="cx"> NotificationsCollectionFileClass = None
</span><del>-
</del><ins>+
</ins><span class="cx"> cls = {
</span><span class="cx"> "inbox" : ScheduleInboxFile,
</span><span class="cx"> "outbox" : ScheduleOutboxFile,
</span><span class="lines">@@ -553,7 +559,9 @@
</span><span class="cx"> if path == self.fp.path:
</span><span class="cx"> return self
</span><span class="cx"> else:
</span><del>- return CalDAVFile(path, \
principalCollections=self.principalCollections()) </del><ins>+ similar = \
CalDAVFile(path, principalCollections=self.principalCollections()) + \
similar.cacheNotifier = self.cacheNotifier + return similar
</ins><span class="cx">
</span><span class="cx"> def getChild(self, name):
</span><span class="cx"> # This avoids finding case variants of put children \
on case-insensitive filesystems. </span><span class="lines">@@ -721,9 +729,9 @@
</span><span class="cx"> elements = []
</span><span class="cx"> \
elements.append(customxml.TimeStamp.fromString(timestamp)) </span><span class="cx"> \
elements.append(customxml.Changed(davxml.HRef.fromString(parentURL))) </span><del>- \
</del><ins>+
</ins><span class="cx"> xml = customxml.Notification(*elements)
</span><del>-
</del><ins>+
</ins><span class="cx"> d = \
waitForDeferred(put_common_base.storeResource(request, data=xml.toxml(), \
destination=self, destination_uri=request.urlForResource(self))) </span><span \
class="cx"> yield d </span><span class="cx"> d.getResult()
</span></span></pre>
</div>
</div>
</body>
</html>
_______________________________________________
calendarserver-changes mailing list
calendarserver-changes@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo/calendarserver-changes
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic