[CalendarServer-changes] [1286] CalendarServer/trunk/twistedcaldav/config.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 27 16:59:44 PST 2007


Revision: 1286
          http://trac.macosforge.org/projects/calendarserver/changeset/1286
Author:   wsanchez at apple.com
Date:     2007-02-27 16:59:43 -0800 (Tue, 27 Feb 2007)

Log Message:
-----------
Add support for handling old config keys.

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

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2007-02-28 00:28:42 UTC (rev 1285)
+++ CalendarServer/trunk/twistedcaldav/config.py	2007-02-28 00:59:43 UTC (rev 1286)
@@ -19,6 +19,8 @@
 import os
 import copy
 
+from twisted.python import log
+
 from twistedcaldav.py.plistlib import readPlist
 
 defaultConfigFile = "/etc/caldavd/caldavd.plist"
@@ -34,9 +36,11 @@
     #    proxy which forwards connections to the server.
     #
     "ServerHostName": "localhost", # Network host name.
-    "HTTPPort": None,              # HTTP port (None to disable HTTP)
-    "SSLPort" : None,              # SSL port (None to disable HTTPS)
+    "HTTPPort": -1,                # HTTP port (None to disable HTTP)
+    "SSLPort" : -1,                # SSL port (None to disable HTTPS)
 
+    # Note: we'd use None above, but that confuses the command-line parser.
+
     #
     # Network address configuration information
     #
@@ -149,6 +153,9 @@
         self._data = copy.deepcopy(defaults)
         self._configFile = None
 
+    def __str__(self):
+        return str(self._data)
+
     def update(self, items):
         self._data.update(items)
 
@@ -170,10 +177,90 @@
         self._configFile = configFile
 
         if configFile and os.path.exists(configFile):
-            plist = readPlist(configFile)
-            self.update(plist)
+            configDict = readPlist(configFile)
+            configDict = self.cleanup(configDict)
+            configDict = self.cleanup(configDict)
+            self.update(configDict)
 
+    def cleanup(self, configDict):
+        cleanDict = copy.deepcopy(configDict)
 
+        def deprecated(oldKey, newKey):
+            log.err("Configuration option %r is deprecated in favor of %r." % (oldKey, newKey))
+
+        def renamed(oldKey, newKey):
+            deprecated(oldKey, newKey)
+            cleanDict[newKey] = configDict[oldKey]
+            del cleanDict[oldKey]
+
+        renamedOptions = {
+            "BindAddress"                : "BindAddresses",
+            "ServerLogFile"              : "AccessLogFile",
+            "MaximumAttachmentSizeBytes" : "MaximumAttachmentSize",
+            "UserQuotaBytes"             : "UserQuota",
+            "DropBoxEnabled"             : "EnableDropBox",
+            "NotificationsEnabled"       : "EnableNotifications",
+            "CalendarUserProxyEnabled"   : "EnableProxyPrincipals",
+            "SACLEnable"                 : "EnableSACLs",
+            "ServerType"                 : "ProcessType",
+        }
+
+        for key in configDict:
+            if key in defaultConfig:
+                continue
+
+            if key == "SSLOnly":
+                deprecated(key, "HTTPPort")
+                if configDict["SSLOnly"]:
+                    cleanDict["HTTPPort"] = None
+                del cleanDict["SSLOnly"]
+
+            elif key == "SSLEnable":
+                deprecated(key, "SSLPort")
+                if not configDict["SSLEnable"]:
+                    cleanDict["SSLPort"] = None
+                del cleanDict["SSLEnable"]
+
+            elif key == "Port":
+                deprecated(key, "HTTPPort")
+                if not configDict.get("SSLOnly", False):
+                    cleanDict["HTTPPort"] = cleanDict["Port"]
+                del cleanDict["Port"]
+
+            elif key == "twistdLocation":
+                deprecated(key, "Twisted -> twistd")
+                if "Twisted" not in cleanDict:
+                    cleanDict["Twisted"] = {}
+                cleanDict["Twisted"]["twistd"] = cleanDict["twistdLocation"]
+                del cleanDict["twistdLocation"]
+
+            elif key == "pydirLocation":
+                deprecated(key, "PythonDirector -> pydir")
+                if "PythonDirector" not in cleanDict:
+                    cleanDict["PythonDirector"] = {}
+                cleanDict["PythonDirector"]["pydir"] = cleanDict["pydirLocation"]
+                del cleanDict["pydirLocation"]
+
+            elif key == "pydirConfig":
+                deprecated(key, "PythonDirector -> pydir")
+                if "PythonDirector" not in cleanDict:
+                    cleanDict["PythonDirector"] = {}
+                cleanDict["PythonDirector"]["ConfigFile"] = cleanDict["pydirConfig"]
+                del cleanDict["pydirConfig"]
+
+            elif key in renamedOptions:
+                renamed(key, renamedOptions[key])
+
+            elif key == "RunStandalone":
+                log.err("Ignoring obsolete configuration option: %s" % (key,))
+                del cleanDict[key]
+
+            else:
+                log.err("Ignoring unknown configuration option: %s" % (key,))
+                del cleanDict[key]
+
+        return cleanDict
+
 class ConfigurationError (RuntimeError):
     """
     Invalid server configuration.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070227/968f5402/attachment.html


More information about the calendarserver-changes mailing list