[CalendarServer-changes] [9394] CalendarServer/branches/release/CalendarServer-4.1-dev

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 27 11:42:26 PDT 2012


Revision: 9394
          http://trac.macosforge.org/projects/calendarserver/changeset/9394
Author:   sagen at apple.com
Date:     2012-06-27 11:42:25 -0700 (Wed, 27 Jun 2012)
Log Message:
-----------
Pulling over repromotion fixes from trunk

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarmigrator.py
    CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarpromotion.py
    CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/test/test_migrator.py
    CalendarServer/branches/release/CalendarServer-4.1-dev/support/Makefile.Apple

Added Paths:
-----------
    CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendardemotion.py

Added: CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendardemotion.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendardemotion.py	                        (rev 0)
+++ CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendardemotion.py	2012-06-27 18:42:25 UTC (rev 9394)
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# UninstallExtra script for calendar server.
+#
+# Copyright (c) 2011-2012 Apple Inc.  All Rights Reserved.
+#
+# IMPORTANT NOTE:  This file is licensed only for use on Apple-labeled
+# computers and is subject to the terms and conditions of the Apple
+# Software License Agreement accompanying the package this file is a
+# part of.  You may not port this file to another platform without
+# Apple's written consent.
+
+import os
+from plistlib import readPlist, writePlist
+
+CALENDAR_SERVER_ROOT = "/Library/Server/Calendar and Contacts"
+DEST_CONFIG_DIR = "%s/Config" % (CALENDAR_SERVER_ROOT,)
+CALDAVD_PLIST = "caldavd.plist"
+
+def main():
+
+    plistPath = os.path.join(DEST_CONFIG_DIR, CALDAVD_PLIST)
+
+    if os.path.exists(plistPath):
+        try:
+            # Turn off services
+            plistData = readPlist(plistPath)
+            plistData["EnableCalDAV"] = False
+            plistData["EnableCardDAV"] = False
+            writePlist(plistData, plistPath)
+
+        except Exception, e:
+            print "Unable to disable services in %s: %s" % (plistPath, e)
+
+
+if __name__ == '__main__':
+    main()

Modified: CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarmigrator.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarmigrator.py	2012-06-27 17:19:54 UTC (rev 9393)
+++ CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarmigrator.py	2012-06-27 18:42:25 UTC (rev 9394)
@@ -242,7 +242,8 @@
         log("serveradmin exited with %d" % (ret,))
 
 
-def isServiceDisabled(source, service):
+def isServiceDisabled(source, service, launchdOverrides=LAUNCHD_OVERRIDES,
+    launchdPrefsDir=LAUNCHD_PREFS_DIR):
     """
     Returns whether or not a service is disabled
 
@@ -251,19 +252,28 @@
     @return: True if service is disabled, False if enabled
     """
 
-    overridesPath = os.path.join(source, LAUNCHD_OVERRIDES)
+    overridesPath = os.path.join(source, launchdOverrides)
     if os.path.isfile(overridesPath):
-        overrides = readPlist(overridesPath)
         try:
+            overrides = readPlist(overridesPath)
+        except Exception, e:
+            raise ServiceStateError("Could not parse %s : %s" %
+                (overridesPath, str(e)))
+
+        try:
             return overrides[service]['Disabled']
         except KeyError:
             # Key is not in the overrides.plist, continue on
             pass
 
-    prefsPath = os.path.join(source, LAUNCHD_PREFS_DIR, "%s.plist" % service)
+    prefsPath = os.path.join(source, launchdPrefsDir, "%s.plist" % service)
     if os.path.isfile(prefsPath):
-        prefs = readPlist(prefsPath)
         try:
+            prefs = readPlist(prefsPath)
+        except Exception, e:
+            raise ServiceStateError("Could not parse %s : %s" %
+                (prefsPath, str(e)))
+        try:
             return prefs['Disabled']
         except KeyError:
             return False
@@ -685,6 +695,7 @@
                     log("Creating new document root: %s" % (newDocumentRoot,))
                     diskAccessor.mkdir(newDocumentRoot)
 
+
     else: # 10.8 -> 10.8
 
         if oldServerRootValue:

Modified: CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarpromotion.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarpromotion.py	2012-06-27 17:19:54 UTC (rev 9393)
+++ CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/calendarpromotion.py	2012-06-27 18:42:25 UTC (rev 9394)
@@ -46,20 +46,16 @@
         try:
             plistData = readPlist(plistPath)
 
-            # Turn off services in case this is a re-promotion
-            plistData["EnableCalDAV"] = False
-            plistData["EnableCardDAV"] = False
-
             # Disable XMPPNotifier now that we're directly talking to APNS
             try:
                 if plistData["Notifications"]["Services"]["XMPPNotifier"]["Enabled"]:
                     plistData["Notifications"]["Services"]["XMPPNotifier"]["Enabled"] = False
+                writePlist(plistData, plistPath)
             except KeyError:
                 pass
 
-            writePlist(plistData, plistPath)
         except Exception, e:
-            print "Unable to disable services in %s: %s" % (plistPath, e)
+            print "Unable to disable XMPP in %s: %s" % (plistPath, e)
 
     else:
         # Copy configuration

Modified: CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/test/test_migrator.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/test/test_migrator.py	2012-06-27 17:19:54 UTC (rev 9393)
+++ CalendarServer/branches/release/CalendarServer-4.1-dev/contrib/migration/test/test_migrator.py	2012-06-27 18:42:25 UTC (rev 9394)
@@ -16,7 +16,8 @@
 
 import twistedcaldav.test.util
 from contrib.migration.calendarmigrator import (
-    mergePlist, examinePreviousSystem, relocateData, relativize
+    mergePlist, examinePreviousSystem, relocateData, relativize, isServiceDisabled,
+    ServiceStateError
 )
 import contrib.migration.calendarmigrator
 
@@ -1346,6 +1347,7 @@
             ]
         ),
 
+
         (
             "Lion -> Mountain Lion Migration, external ServerRoot",
             {
@@ -1408,7 +1410,8 @@
             ('chown-recursive', '/Volumes/new/Library/Server/Calendar and Contacts', FakeUser.pw_uid, FakeGroup.gr_gid),
             ]
         ),
-(
+
+        (
             "Mountain Lion -> Mountain Lion Migration, all in default locations",
             {
                 "/Library/Server/Previous/private/etc/caldavd/caldavd.plist" : """
@@ -1551,6 +1554,58 @@
         self.assertEquals(da.mkdir(t), None)
 
 
+    def test_isServiceDisabledTrue(self):
+        CONTENTS = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>foo</key>
+        <dict>
+                <key>Disabled</key>
+                <true/>
+        </dict>
+</dict>
+</plist>
+"""
+        t = self.mktemp()
+        f = open(t, "w")
+        f.write(CONTENTS)
+        f.close()
+        self.assertTrue(isServiceDisabled("", "foo", t))
+
+    def test_isServiceDisabledFalse(self):
+        CONTENTS = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+        <key>foo</key>
+        <dict>
+                <key>Disabled</key>
+                <false/>
+        </dict>
+</dict>
+</plist>
+"""
+        t = self.mktemp()
+        f = open(t, "w")
+        f.write(CONTENTS)
+        f.close()
+        self.assertFalse(isServiceDisabled("", "foo", t))
+
+    def test_isServiceDisabledError(self):
+        CONTENTS = """This is not a plist """
+        t = self.mktemp()
+        f = open(t, "w")
+        f.write(CONTENTS)
+        f.close()
+        try:
+            isServiceDisabled("", "foo", t)
+        except ServiceStateError:
+            pass
+        else:
+            self.fail(msg="Didn't raise ServiceStateError")
+
+
 class StubDiskAccessor(object):
     """
     A stub which allows testing without actually having real files

Modified: CalendarServer/branches/release/CalendarServer-4.1-dev/support/Makefile.Apple
===================================================================
--- CalendarServer/branches/release/CalendarServer-4.1-dev/support/Makefile.Apple	2012-06-27 17:19:54 UTC (rev 9393)
+++ CalendarServer/branches/release/CalendarServer-4.1-dev/support/Makefile.Apple	2012-06-27 18:42:25 UTC (rev 9394)
@@ -111,6 +111,10 @@
 	$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/PromotionExtras"
 	$(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/calendarpromotion.py" "$(DSTROOT)$(SERVERSETUP)/PromotionExtras/59_calendarpromotion.py"
 	$(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/PromotionExtras/59_calendarpromotion.py"
+	@echo "Installing server demotion config..."
+	$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/UninstallExtras"
+	$(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/calendardemotion.py" "$(DSTROOT)$(SERVERSETUP)/UninstallExtras/59_calendardemotion.py"
+	$(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/UninstallExtras/59_calendardemotion.py"
 	@echo "Installing database configuration scripts..."
 	$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/CommonExtras/PostgreSQLExtras"
 	$(_v) $(INSTALL_FILE) "$(Sources)/contrib/create_caldavd_db.sh" "$(DSTROOT)$(SERVERSETUP)/CommonExtras/PostgreSQLExtras/create_caldavd_db.sh"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120627/0019ca2c/attachment-0001.html>


More information about the calendarserver-changes mailing list