[CalendarServer-changes] [10699] CalendarServer/branches/release/CalendarServer-4.3-dev/ calendarserver/tools/purge.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue Feb 12 11:30:15 PST 2013
Revision: 10699
http://trac.calendarserver.org//changeset/10699
Author: cdaboo at apple.com
Date: 2013-02-12 11:30:15 -0800 (Tue, 12 Feb 2013)
Log Message:
-----------
Do per-resource changes in a separate transaction.
Modified Paths:
--------------
CalendarServer/branches/release/CalendarServer-4.3-dev/calendarserver/tools/purge.py
Modified: CalendarServer/branches/release/CalendarServer-4.3-dev/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.3-dev/calendarserver/tools/purge.py 2013-02-12 18:42:04 UTC (rev 10698)
+++ CalendarServer/branches/release/CalendarServer-4.3-dev/calendarserver/tools/purge.py 2013-02-12 19:30:15 UTC (rev 10699)
@@ -27,13 +27,12 @@
from pycalendar.datetime import PyCalendarDateTime
-from twext.python.log import Logger
+from twext.python.log import Logger, StandardIOObserver
from twext.web2.responsecode import NO_CONTENT
from twisted.application.service import Service
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
-from twisted.python.log import addObserver, removeObserver
from twistedcaldav import caldavxml
from twistedcaldav.caldavxml import TimeRange
@@ -55,36 +54,6 @@
DEFAULT_BATCH_SIZE = 100
DEFAULT_RETAIN_DAYS = 365
-class StandardIOObserver (object):
- """
- Log observer that writes to standard I/O.
- """
- def emit(self, eventDict):
- text = None
-
- if eventDict["isError"]:
- output = sys.stderr
- if "failure" in eventDict:
- text = eventDict["failure"].getTraceback()
- else:
- output = sys.stdout
-
- if not text:
- text = " ".join([str(m) for m in eventDict["message"]]) + "\n"
-
- output.write(text)
- output.flush()
-
-
- def start(self):
- addObserver(self.emit)
-
-
- def stop(self):
- removeObserver(self.emit)
-
-
-
class WorkerService(Service):
def __init__(self, store):
@@ -859,78 +828,97 @@
for childName in childNames:
- childResource = (yield collection.getChild(childName))
- # Always delete inbox items
- if self.completely or collName == "inbox":
- action = self.CANCELEVENT_SHOULD_DELETE
- else:
- event = (yield childResource.iCalendar())
- event = perUserFilter.filter(event)
- action = self._cancelEvent(event, self.when, cua)
-
- uri = "/calendars/__uids__/%s/%s/%s" % (uid, collName, childName)
- request.path = uri
- if action == self.CANCELEVENT_MODIFIED:
- count += 1
- request._rememberResource(childResource, uri)
- storer = StoreCalendarObjectResource(
- request=request,
- destination=childResource,
- destination_uri=uri,
- destinationcal=True,
- destinationparent=collection,
- calendar=str(event),
+ try:
+ perresource_request = FakeRequest(self.root, None, None)
+ perresource_request.checkedSACL = True
+ perresource_request.authnUser = perresource_request.authzUser = davxml.Principal(
+ davxml.HRef.fromString("/principals/__uids__/%s/" % (uid,))
)
- if self.verbose:
- if self.dryrun:
- print "Would modify: %s" % (uri,)
- else:
- print "Modifying: %s" % (uri,)
- if not self.dryrun:
- result = (yield storer.run())
- elif action == self.CANCELEVENT_SHOULD_DELETE:
- incrementCount = self.dryrun
- request._rememberResource(childResource, uri)
- if self.verbose:
- if self.dryrun:
- print "Would delete: %s" % (uri,)
- else:
- print "Deleting: %s" % (uri,)
- if not self.dryrun:
- retry = False
- try:
- result = (yield childResource.storeRemove(request, self.doimplicit, uri))
- if result != NO_CONTENT:
- print "Error deleting %s/%s/%s: %s" % (uid,
- collName, childName, result)
- retry = True
- else:
- incrementCount = True
+ childResource = (yield collection.getChild(childName))
- except Exception, e:
- print "Exception deleting %s/%s/%s: %s" % (uid,
- collName, childName, str(e))
- traceback.print_stack()
- retry = True
+ # Always delete inbox items
+ if self.completely or collName == "inbox":
+ action = self.CANCELEVENT_SHOULD_DELETE
+ else:
+ event = (yield childResource.iCalendar())
+ event = perUserFilter.filter(event)
+ action = self._cancelEvent(event, self.when, cua)
- if retry and self.doimplicit:
- # Try again with implicit scheduling off
- print "Retrying deletion of %s/%s/%s with implicit scheduling turned off" % (uid, collName, childName)
+ uri = "/calendars/__uids__/%s/%s/%s" % (uid, collName, childName)
+ perresource_request.path = uri
+ if action == self.CANCELEVENT_MODIFIED:
+ perresource_request._rememberResource(childResource, uri)
+ storer = StoreCalendarObjectResource(
+ request=perresource_request,
+ destination=childResource,
+ destination_uri=uri,
+ destinationcal=True,
+ destinationparent=collection,
+ calendar=str(event),
+ )
+ if self.verbose:
+ if self.dryrun:
+ print "Would modify: %s" % (uri,)
+ else:
+ print "Modifying: %s" % (uri,)
+ if not self.dryrun:
+ result = (yield storer.run())
+ count += 1
+
+ elif action == self.CANCELEVENT_SHOULD_DELETE:
+ incrementCount = self.dryrun
+ perresource_request._rememberResource(childResource, uri)
+ if self.verbose:
+ if self.dryrun:
+ print "Would delete: %s" % (uri,)
+ else:
+ print "Deleting: %s" % (uri,)
+ if not self.dryrun:
+ retry = False
try:
- result = (yield childResource.storeRemove(request, False, uri))
+ result = (yield childResource.storeRemove(perresource_request, self.doimplicit, uri))
if result != NO_CONTENT:
print "Error deleting %s/%s/%s: %s" % (uid,
collName, childName, result)
+ retry = True
else:
incrementCount = True
+
except Exception, e:
- print "Still couldn't delete %s/%s/%s even with implicit scheduling turned off: %s" % (uid, collName, childName, str(e))
+ print "Exception deleting %s/%s/%s: %s" % (uid,
+ collName, childName, str(e))
traceback.print_stack()
+ retry = True
- if incrementCount:
- count += 1
+ if retry and self.doimplicit:
+ # Try again with implicit scheduling off
+ print "Retrying deletion of %s/%s/%s with implicit scheduling turned off" % (uid, collName, childName)
+ try:
+ result = (yield childResource.storeRemove(perresource_request, False, uri))
+ if result != NO_CONTENT:
+ print "Error deleting %s/%s/%s: %s" % (uid,
+ collName, childName, result)
+ else:
+ incrementCount = True
+ except Exception, e:
+ print "Still couldn't delete %s/%s/%s even with implicit scheduling turned off: %s" % (uid, collName, childName, str(e))
+ traceback.print_stack()
+ if incrementCount:
+ count += 1
+
+ txn = getattr(perresource_request, "_newStoreTransaction", None)
+ # Commit
+ if txn is not None:
+ (yield txn.commit())
+ except Exception, e:
+ # Abort
+ txn = getattr(perresource_request, "_newStoreTransaction", None)
+ if txn is not None:
+ (yield txn.abort())
+ raise e
+
txn = getattr(request, "_newStoreTransaction", None)
# Commit
if txn is not None:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130212/97bac6a7/attachment-0001.html>
More information about the calendarserver-changes
mailing list