Revision: 6449 http://trac.macosforge.org/projects/calendarserver/changeset/6449 Author: sagen@apple.com Date: 2010-10-20 12:49:14 -0700 (Wed, 20 Oct 2010) Log Message: ----------- Only migration automatically triggers a location/resource import (not a clean install) Modified Paths: -------------- CalendarServer/trunk/contrib/migration/calendarmigrator.py CalendarServer/trunk/twistedcaldav/upgrade.py Modified: CalendarServer/trunk/contrib/migration/calendarmigrator.py =================================================================== --- CalendarServer/trunk/contrib/migration/calendarmigrator.py 2010-10-20 16:52:58 UTC (rev 6448) +++ CalendarServer/trunk/contrib/migration/calendarmigrator.py 2010-10-20 19:49:14 UTC (rev 6449) @@ -40,6 +40,7 @@ CALDAVD_PLIST = "caldavd.plist" CARDDAVD_PLIST = "carddavd.plist" NEW_SERVER_ROOT = "/Library/Server/Calendar and Contacts" +RESOURCE_MIGRATION_TRIGGER = "trigger_resource_migration" verbatimKeys = """ @@ -202,6 +203,7 @@ newServerRootValue = migrateData(options) migrateConfiguration(options, newServerRootValue) migrateRunState(options) + triggerResourceMigration(newServerRootValue) else: log("ERROR: --sourceRoot must be specified") @@ -225,7 +227,22 @@ setServiceStateDisabled(options.targetRoot, LAUNCHD_KEY, disabled) +def triggerResourceMigration(newServerRootValue): + """ + Leave a file in the server root to act as a signal that the server + should migrate locations and resources from OD when it starts up. + """ + triggerPath = os.path.join(newServerRootValue, RESOURCE_MIGRATION_TRIGGER) + if not os.path.exists(newServerRootValue): + log("New server root directory doesn't exist: %s" % (newServerRootValue,)) + return + if not os.path.exists(triggerPath): + # Create an empty trigger file + log("Creating resource migration trigger file: %s" % (triggerPath,)) + open(triggerPath, "w").close() + + def migrateConfiguration(options, newServerRootValue): """ Copy files/directories/symlinks from previous system's /etc/caldavd Modified: CalendarServer/trunk/twistedcaldav/upgrade.py =================================================================== --- CalendarServer/trunk/twistedcaldav/upgrade.py 2010-10-20 16:52:58 UTC (rev 6448) +++ CalendarServer/trunk/twistedcaldav/upgrade.py 2010-10-20 19:49:14 UTC (rev 6449) @@ -478,38 +478,43 @@ # # Migrates locations and resources from OD # + triggerFile = "trigger_resource_migration" + triggerPath = os.path.join(config.ServerRoot, triggerFile) + if os.path.exists(triggerPath): - 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) + log.info("Migrating locations and resources") - # 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 + 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) - # 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) + # 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) + # The on-disk version number (which defaults to zero if .calendarserver_version # doesn't exist), is compared with each of the numbers in the upgradeMethods # array. If it is less than the number, the associated method is called.