[CalendarServer-changes] [6852] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 2 17:00:57 PST 2011


Revision: 6852
          http://trac.macosforge.org/projects/calendarserver/changeset/6852
Author:   sagen at apple.com
Date:     2011-02-02 17:00:56 -0800 (Wed, 02 Feb 2011)
Log Message:
-----------
calendarserver_purge_principals now removes addressbook data.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/purge.py
    CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py
    CalendarServer/trunk/doc/calendarserver_purge_principals.8

Modified: CalendarServer/trunk/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/purge.py	2011-02-02 19:35:24 UTC (rev 6851)
+++ CalendarServer/trunk/calendarserver/tools/purge.py	2011-02-03 01:00:56 UTC (rev 6852)
@@ -90,12 +90,12 @@
     name = os.path.basename(sys.argv[0])
     print "usage: %s [options]" % (name,)
     print ""
-    print "  Remove a principal's events from the calendar server"
+    print "  Remove a principal's events and contacts from the calendar server"
     print ""
     print "options:"
     print "  -f --config <path>: Specify caldavd.plist configuration path"
     print "  -h --help: print this help and exit"
-    print "  -n --dry-run: only calculate how many events to purge"
+    print "  -n --dry-run: only calculate how many events and contacts to purge"
     print "  -v --verbose: print progress information"
     print ""
 
@@ -691,9 +691,7 @@
                 childResource = (yield collection.getChild(childName))
                 event = (yield childResource.iCalendar())
                 event = perUserFilter.filter(event)
-                # print "BEFORE CANCEL", event
                 action = cancelEvent(event, when, cua)
-                # print "AFTER CANCEL", action, event
 
                 uri = "/calendars/__uids__/%s/%s/%s" % (guid, collName, childName)
                 request.path = uri
@@ -730,8 +728,29 @@
                             print "Error deleting %s/%s/%s: %s" % (guid,
                                 collName, childName, result)
 
+
+    txn = request._newStoreTransaction
+
+    # Remove VCards
+    abHome = (yield txn.addressbookHomeWithUID(guid))
+    if abHome is not None:
+        for abColl in list( (yield abHome.addressbooks()) ):
+            for card in list( (yield abColl.addressbookObjects()) ):
+                cardName = card.name()
+                if verbose:
+                    uri = "/addressbooks/__uids__/%s/%s/%s" % (guid, abColl.name(), cardName)
+                    if dryrun:
+                        print "Would delete: %s" % (uri,)
+                    else:
+                        print "Deleting: %s" % (uri,)
+                if not dryrun:
+                    (yield abColl.removeObjectResourceWithName(cardName))
+                count += 1
+            if not dryrun:
+                # Also remove the addressbook collection itself
+                (yield abHome.removeChildWithName(abColl.name()))
+
     # Commit
-    txn = request._newStoreTransaction
     (yield txn.commit())
 
     if proxies and not dryrun:

Modified: CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py	2011-02-02 19:35:24 UTC (rev 6851)
+++ CalendarServer/trunk/calendarserver/tools/test/test_purge_old_events.py	2011-02-03 01:00:56 UTC (rev 6852)
@@ -21,7 +21,10 @@
 from twisted.trial import unittest
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twext.web2.http_headers import MimeType
+from twistedcaldav.vcard import Component as VCardComponent
 
+
+
 from txdav.common.datastore.test.util import buildStore, populateCalendarsFrom, CommonCommonTests
 
 from calendarserver.tap.util import getRootResource
@@ -300,7 +303,16 @@
 """.replace("\n", "\r\n")
 
 
+VCARD_1 = """BEGIN:VCARD
+VERSION:3.0
+N:User;Test
+FN:Test User
+EMAIL;type=INTERNET;PREF:testuser at example.com
+UID:12345-67890-1.1
+END:VCARD
+""".replace("\n", "\r\n")
 
+
 class PurgeOldEventsTests(CommonCommonTests, unittest.TestCase):
     """
     Tests for deleting events older than a given date
@@ -331,7 +343,21 @@
         self._sqlCalendarStore = yield buildStore(self, self.notifierFactory)
         yield self.populate()
 
+        self.patch(config.DirectoryService.params, "xmlFile",
+            os.path.join(
+                os.path.dirname(__file__), "purge", "accounts.xml"
+            )
+        )
+        self.patch(config.ResourceService.params, "xmlFile",
+            os.path.join(
+                os.path.dirname(__file__), "purge", "resources.xml"
+            )
+        )
+        self.patch(config.Memcached.Pools.Default, "ClientEnabled", False)
+        self.rootResource = getRootResource(config, self._sqlCalendarStore)
+        self.directory = self.rootResource.getDirectory()
 
+
     @inlineCallbacks
     def populate(self):
         yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
@@ -455,79 +481,64 @@
 
     @inlineCallbacks
     def test_purgeOldEvents(self):
-        self.patch(config.DirectoryService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "accounts.xml"
-            )
-        )
-        self.patch(config.ResourceService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "resources.xml"
-            )
-        )
-        self.patch(config.Memcached.Pools.Default, "ClientEnabled", False)
-        rootResource = getRootResource(config, self._sqlCalendarStore)
-        directory = rootResource.getDirectory()
 
         # Dry run
-        total = (yield purgeOldEvents(self._sqlCalendarStore, directory,
-            rootResource, datetime.datetime(2010, 4, 1), 2, dryrun=True,
+        total = (yield purgeOldEvents(self._sqlCalendarStore, self.directory,
+            self.rootResource, datetime.datetime(2010, 4, 1), 2, dryrun=True,
             verbose=False))
         self.assertEquals(total, 4)
 
         # Actually remove
-        total = (yield purgeOldEvents(self._sqlCalendarStore, directory,
-            rootResource, datetime.datetime(2010, 4, 1), 2, verbose=False))
+        total = (yield purgeOldEvents(self._sqlCalendarStore, self.directory,
+            self.rootResource, datetime.datetime(2010, 4, 1), 2, verbose=False))
         self.assertEquals(total, 4)
 
         # There should be no more left
-        total = (yield purgeOldEvents(self._sqlCalendarStore, directory,
-            rootResource, datetime.datetime(2010, 4, 1), 2, verbose=False))
+        total = (yield purgeOldEvents(self._sqlCalendarStore, self.directory,
+            self.rootResource, datetime.datetime(2010, 4, 1), 2, verbose=False))
         self.assertEquals(total, 0)
 
     @inlineCallbacks
     def test_purgeGUID(self):
-        self.patch(config.DirectoryService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "accounts.xml"
-            )
-        )
-        self.patch(config.ResourceService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "resources.xml"
-            )
-        )
-        self.patch(config.Memcached.Pools.Default, "ClientEnabled", False)
-        rootResource = getRootResource(config, self._sqlCalendarStore)
-        directory = rootResource.getDirectory()
-        total, ignored = (yield purgeGUID("home2", directory, rootResource,
-            verbose=False, proxies=False,
+        txn = self._sqlCalendarStore.newTransaction()
+
+        # Create an addressbook and one CardDAV resource
+        abHome = (yield txn.addressbookHomeWithUID("home1", create=True))
+        abColl = (yield abHome.addressbookWithName("addressbook"))
+        (yield abColl.createAddressBookObjectWithName("card1",
+            VCardComponent.fromString(VCARD_1)))
+        self.assertEquals(len( (yield abColl.addressbookObjects()) ), 1)
+
+        # Verify there are 3 events in calendar1
+        calHome = (yield txn.calendarHomeWithUID("home1"))
+        calColl = (yield calHome.calendarWithName("calendar1"))
+        self.assertEquals(len( (yield calColl.calendarObjects()) ), 3)
+
+        # Make the newly created objects available to the purgeGUID transaction
+        (yield txn.commit())
+
+        # Purge home1
+        total, ignored = (yield purgeGUID("home1", self.directory,
+            self.rootResource, verbose=False, proxies=False,
             when=datetime.datetime(2010, 4, 1, 12, 0, 0, 0, utc)))
-        self.assertEquals(total, 1)
 
+        # 2 items deleted: 1 event and 1 vcard
+        self.assertEquals(total, 2)
 
+        txn = self._sqlCalendarStore.newTransaction()
+        abHome = (yield txn.addressbookHomeWithUID("home1"))
+        abColl = (yield abHome.addressbookWithName("addressbook"))
+        self.assertEquals(abColl, None)
+
+
     @inlineCallbacks
     def test_purgeOrphanedAttachments(self):
 
         (yield self._addAttachment())
 
-        self.patch(config.DirectoryService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "accounts.xml"
-            )
-        )
-        self.patch(config.ResourceService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "resources.xml"
-            )
-        )
-        self.patch(config.Memcached.Pools.Default, "ClientEnabled", False)
-        rootResource = getRootResource(config, self._sqlCalendarStore)
-        directory = rootResource.getDirectory()
-
         # Remove old events first
-        total = (yield purgeOldEvents(self._sqlCalendarStore, directory,
-            rootResource, datetime.datetime(2010, 4, 1), 2, verbose=False))
+        total = (yield purgeOldEvents(self._sqlCalendarStore, self.directory,
+            self.rootResource, datetime.datetime(2010, 4, 1), 2, verbose=False))
         self.assertEquals(total, 4)
 
         # Dry run

Modified: CalendarServer/trunk/doc/calendarserver_purge_principals.8
===================================================================
--- CalendarServer/trunk/doc/calendarserver_purge_principals.8	2011-02-02 19:35:24 UTC (rev 6851)
+++ CalendarServer/trunk/doc/calendarserver_purge_principals.8	2011-02-03 01:00:56 UTC (rev 6852)
@@ -30,7 +30,7 @@
 .Op guid ...
 .Sh DESCRIPTION
 .Nm
-is a tool for removing one or more principals' future events and proxy assignments from the calendar server.  Events in the past are retained, but any ongoing events are canceled.
+is a tool for removing one or more principals' future events, proxy assignments, and contacts from the calendar server.  Events in the past are retained, but any ongoing events are canceled.
 .Pp
 .Nm
 should be run as a user with the same priviledges as the Calendar
@@ -43,7 +43,7 @@
 .It Fl f, -config Ar FILE
 Use the Calendar Server configuration specified in the given file.  Defaults to /etc/caldavd/caldavd.plist.
 .It Fl n, -dry-run
-Calculate and display how many events would be removed, but don't actually remove them.  
+Calculate and display how many events and contacts would be removed, but don't actually remove them.  
 .It Fl v, -verbose
 Print progress information.
 .El
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110202/5b81f43e/attachment-0001.html>


More information about the calendarserver-changes mailing list