[CalendarServer-changes] [6226] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 31 17:41:37 PDT 2010


Revision: 6226
          http://trac.macosforge.org/projects/calendarserver/changeset/6226
Author:   glyph at apple.com
Date:     2010-08-31 17:41:36 -0700 (Tue, 31 Aug 2010)
Log Message:
-----------
include addressbooks in upgrade-to-database pass

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/txdav/caldav/datastore/util.py

Added Paths:
-----------
    CalendarServer/trunk/txdav/common/datastore/util.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2010-09-01 00:38:50 UTC (rev 6225)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2010-09-01 00:41:36 UTC (rev 6226)
@@ -90,7 +90,7 @@
 
 from txdav.common.datastore.sql import v1_schema
 from txdav.base.datastore.subpostgres import PostgresService
-from txdav.caldav.datastore.util import UpgradeToDatabaseService
+from txdav.common.datastore.util import UpgradeToDatabaseService
 from twext.python.filepath import CachingFilePath
 
 log = Logger()

Modified: CalendarServer/trunk/txdav/caldav/datastore/util.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/util.py	2010-09-01 00:38:50 UTC (rev 6225)
+++ CalendarServer/trunk/txdav/caldav/datastore/util.py	2010-09-01 00:41:36 UTC (rev 6226)
@@ -16,10 +16,6 @@
 """
 Utility logic common to multiple backend implementations.
 """
-from twext.python.log import LoggingMixIn
-from twisted.application.service import Service
-from txdav.common.datastore.file import CommonDataStore as FileStore
-from txdav.common.datastore.sql import CommonDataStore as SqlStore
 
 from twext.python.vcomponent import InvalidICalendarDataError
 from twext.python.vcomponent import VComponent
@@ -143,82 +139,3 @@
     # No migration for notifications, since they weren't present in earlier
     # released versions of CalendarServer.
 
-
-# TODO: implement addressbooks, import from txdav.common.datastore.file
-TOPPATHS = ['calendars']
-
-class UpgradeToDatabaseService(Service, LoggingMixIn, object):
-    """
-    Upgrade resources from a filesystem store to a database store.
-    """
-
-
-    @classmethod
-    def wrapService(cls, path, service, connectionFactory, sqlAttachmentsPath):
-        """
-        Create an L{UpgradeToDatabaseService} if there are still file-based
-        calendar or addressbook homes remaining in the given path.
-
-        Maintenance note: we may want to pass a SQL store in directly rather
-        than the combination of connection factory and attachments path, since
-        there always must be a SQL store, but the path should remain a path
-        because there may not I{be} a file-backed store present and we should
-        not create it as a result of checking for it.
-
-        @param path: a path pointing at the document root.
-        @type path: L{CachingFilePath}
-
-        @param service: the service to wrap.  This service should be started
-            when the upgrade is complete.  (This is accomplished by returning
-            it directly when no upgrade needs to be done, and by adding it to
-            the service hierarchy when the upgrade completes; assuming that the
-            service parent of the resulting service will be set to a
-            L{MultiService} or similar.)
-
-        @type service: L{IService}
-
-        @return: a service
-        @rtype: L{IService}
-        """
-        for homeType in TOPPATHS:
-            if path.child(homeType).exists():
-                self = cls(
-                    FileStore(path, None, True, True),
-                    SqlStore(connectionFactory, None, sqlAttachmentsPath,
-                             True, True),
-                    service
-                )
-                return self
-        return service
-
-
-    def __init__(self, fileStore, sqlStore, service):
-        """
-        Initialize the service.
-        """
-        self.wrappedService = service
-        self.fileStore = fileStore
-        self.sqlStore = sqlStore
-
-
-    def startService(self):
-        self.log_warn("Beginning filesystem -> database upgrade.")
-        for fileTxn, fileHome in self.fileStore.eachCalendarHome():
-            uid = fileHome.uid()
-            self.log_warn("Migrating UID %r" % (uid,))
-            sqlTxn = self.sqlStore.newTransaction()
-            sqlHome = sqlTxn.calendarHomeWithUID(uid, create=True)
-            migrateHome(fileHome, sqlHome)
-            fileTxn.commit()
-            sqlTxn.commit()
-            # FIXME: need a public remove...HomeWithUID() for de-provisioning
-            fileHome._path.remove()
-        for homeType in TOPPATHS:
-            homesPath = self.fileStore._path.child(homeType)
-            if homesPath.isdir():
-                homesPath.remove()
-        self.log_warn(
-            "Filesystem upgrade complete, launching database service."
-        )
-        self.wrappedService.setServiceParent(self.parent)
-

Added: CalendarServer/trunk/txdav/common/datastore/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/util.py	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/util.py	2010-09-01 00:41:36 UTC (rev 6226)
@@ -0,0 +1,109 @@
+# -*- test-case-name: txdav.caldav.datastore.test.test_sql,txdav.carddav.datastore.test.test_sql -*-
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twext.python.log import LoggingMixIn
+from twisted.application.service import Service
+from txdav.common.datastore.file import CommonDataStore as FileStore, TOPPATHS
+from txdav.common.datastore.sql import CommonDataStore as SqlStore
+from txdav.caldav.datastore.util import migrateHome as migrateCalendarHome
+from txdav.carddav.datastore.util import migrateHome as migrateAddressbookHome
+
+
+class UpgradeToDatabaseService(Service, LoggingMixIn, object):
+    """
+    Upgrade resources from a filesystem store to a database store.
+    """
+
+
+    @classmethod
+    def wrapService(cls, path, service, connectionFactory, sqlAttachmentsPath):
+        """
+        Create an L{UpgradeToDatabaseService} if there are still file-based
+        calendar or addressbook homes remaining in the given path.
+
+        Maintenance note: we may want to pass a SQL store in directly rather
+        than the combination of connection factory and attachments path, since
+        there always must be a SQL store, but the path should remain a path
+        because there may not I{be} a file-backed store present and we should
+        not create it as a result of checking for it.
+
+        @param path: a path pointing at the document root.
+        @type path: L{CachingFilePath}
+
+        @param service: the service to wrap.  This service should be started
+            when the upgrade is complete.  (This is accomplished by returning
+            it directly when no upgrade needs to be done, and by adding it to
+            the service hierarchy when the upgrade completes; assuming that the
+            service parent of the resulting service will be set to a
+            L{MultiService} or similar.)
+
+        @type service: L{IService}
+
+        @return: a service
+        @rtype: L{IService}
+        """
+        for homeType in TOPPATHS:
+            if path.child(homeType).exists():
+                self = cls(
+                    FileStore(path, None, True, True),
+                    SqlStore(connectionFactory, None, sqlAttachmentsPath,
+                             True, True),
+                    service
+                )
+                return self
+        return service
+
+
+    def __init__(self, fileStore, sqlStore, service):
+        """
+        Initialize the service.
+        """
+        self.wrappedService = service
+        self.fileStore = fileStore
+        self.sqlStore = sqlStore
+
+
+    def startService(self):
+        self.log_warn("Beginning filesystem -> database upgrade.")
+        for homeType, migrateFunc, eachFunc, destFunc in [
+            ("calendar", migrateCalendarHome,
+                self.fileStore.eachCalendarHome,
+                lambda uid, txn: txn.calendarHomeWithUID(uid, create=True)),
+            ("addressbook", migrateAddressbookHome, self.fileStore.eachAddressbookHome,
+                lambda uid, txn: txn.addressbookHomeWithUID(uid, create=True))
+            ]:
+            for fileTxn, fileHome in eachFunc():
+                uid = fileHome.uid()
+                self.log_warn("Migrating %s UID %r" % (homeType, uid))
+                sqlTxn = self.sqlStore.newTransaction()
+                sqlHome = destFunc(uid, sqlTxn)
+                migrateFunc(fileHome, sqlHome)
+                fileTxn.commit()
+                sqlTxn.commit()
+                # FIXME: need a public remove...HomeWithUID() for de-provisioning
+                fileHome._path.remove()
+        for homeType in TOPPATHS:
+            homesPath = self.fileStore._path.child(homeType)
+            if homesPath.isdir():
+                homesPath.remove()
+        self.log_warn(
+            "Filesystem upgrade complete, launching database service."
+        )
+        self.wrappedService.setServiceParent(self.parent)
+
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100831/8aa9b3d6/attachment-0001.html>


More information about the calendarserver-changes mailing list