[CalendarServer-changes] [8314] CalendarServer/trunk/twistedcaldav/upgrade.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 17 11:13:37 PST 2011


Revision: 8314
          http://trac.macosforge.org/projects/calendarserver/changeset/8314
Author:   sagen at apple.com
Date:     2011-11-17 11:13:36 -0800 (Thu, 17 Nov 2011)
Log Message:
-----------
Call migrateFromOD() prior to upgrade_to_1()

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/upgrade.py

Modified: CalendarServer/trunk/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/upgrade.py	2011-11-17 19:08:27 UTC (rev 8313)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py	2011-11-17 19:13:36 UTC (rev 8314)
@@ -558,7 +558,6 @@
 
 
 
- at inlineCallbacks
 def upgrade_to_2(config):
     
     errorOccurred = False
@@ -575,45 +574,6 @@
         if os.path.exists(oldDbPath) and not os.path.exists(newDbPath):
             os.rename(oldDbPath, newDbPath)
 
-    def migrateFromOD():
-        #
-        # Migrates locations and resources from OD
-        #
-        triggerFile = "trigger_resource_migration"
-        triggerPath = os.path.join(config.ServerRoot, triggerFile)
-        if os.path.exists(triggerPath):
-            os.remove(triggerPath)
-    
-            log.warn("Migrating locations and resources")
-    
-            directory = getDirectory()
-            userService = directory.serviceForRecordType("users")
-            resourceService = directory.serviceForRecordType("resources")
-            if (
-                not isinstance(userService, OpenDirectoryService) or
-                not isinstance(resourceService, XMLDirectoryService)
-            ):
-                # Configuration requires no migration
-                return succeed(None)
-    
-            # Fetch the autoSchedule assignments from resourceinfo.sqlite and pass
-            # those to migrateResources
-            autoSchedules = {}
-            dbPath = os.path.join(config.DataRoot, ResourceInfoDatabase.dbFilename)
-            if os.path.exists(dbPath):
-                resourceInfoDatabase = ResourceInfoDatabase(config.DataRoot)
-                results = resourceInfoDatabase._db_execute(
-                    "select GUID, AUTOSCHEDULE from RESOURCEINFO"
-                )
-                for guid, autoSchedule in results:
-                    autoSchedules[guid] = autoSchedule
-    
-            # Create internal copies of resources and locations based on what is
-            # found in OD, overriding the autoSchedule default with existing
-            # assignments from resourceinfo.sqlite
-            return migrateResources(userService, resourceService,
-                autoSchedules=autoSchedules)
-
     def flattenHome(calHome):
 
         log.debug("Flattening calendar home: %s" % (calHome,))
@@ -658,9 +618,9 @@
 
         except Exception, e:
             log.error("Failed to upgrade calendar home %s: %s" % (calHome, e))
-            return False
+            return succeed(False)
         
-        return True
+        return succeed(True)
 
     def flattenHomes():
         """
@@ -695,10 +655,6 @@
         
     renameProxyDB()
     errorOccurred = flattenHomes()
-    try:
-        yield migrateFromOD()
-    except:
-        errorOccurred = True
         
     if errorOccurred:
         raise UpgradeError("Data upgrade failed, see error.log for details")
@@ -716,6 +672,11 @@
 @inlineCallbacks
 def upgradeData(config):
 
+    try:
+        (yield migrateFromOD(config))
+    except Exception, e:
+        raise UpgradeError("Unable to migrate locations and resources from OD: %s" % (e,))
+
     docRoot = config.DocumentRoot
 
     versionFilePath = os.path.join(docRoot, ".calendarserver_version")
@@ -873,6 +834,46 @@
         return data, False
 
 
+def migrateFromOD(config):
+    #
+    # Migrates locations and resources from OD
+    #
+    triggerFile = "trigger_resource_migration"
+    triggerPath = os.path.join(config.ServerRoot, triggerFile)
+    if os.path.exists(triggerPath):
+        os.remove(triggerPath)
+
+        log.warn("Migrating locations and resources")
+
+        directory = getDirectory()
+        userService = directory.serviceForRecordType("users")
+        resourceService = directory.serviceForRecordType("resources")
+        if (
+            not isinstance(userService, OpenDirectoryService) or
+            not isinstance(resourceService, XMLDirectoryService)
+        ):
+            # Configuration requires no migration
+            return succeed(None)
+
+        # Fetch the autoSchedule assignments from resourceinfo.sqlite and pass
+        # those to migrateResources
+        autoSchedules = {}
+        dbPath = os.path.join(config.DataRoot, ResourceInfoDatabase.dbFilename)
+        if os.path.exists(dbPath):
+            resourceInfoDatabase = ResourceInfoDatabase(config.DataRoot)
+            results = resourceInfoDatabase._db_execute(
+                "select GUID, AUTOSCHEDULE from RESOURCEINFO"
+            )
+            for guid, autoSchedule in results:
+                autoSchedules[guid] = autoSchedule
+
+        # Create internal copies of resources and locations based on what is
+        # found in OD, overriding the autoSchedule default with existing
+        # assignments from resourceinfo.sqlite
+        return migrateResources(userService, resourceService,
+            autoSchedules=autoSchedules)
+
+
 class UpgradeFileSystemFormatService(Service, object):
     """
     Upgrade filesystem from previous versions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111117/ef23709f/attachment-0001.html>


More information about the calendarserver-changes mailing list