[CalendarServer-changes] [1390] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 14 15:17:13 PDT 2007
Revision: 1390
http://trac.macosforge.org/projects/calendarserver/changeset/1390
Author: wsanchez at apple.com
Date: 2007-03-14 15:17:13 -0700 (Wed, 14 Mar 2007)
Log Message:
-----------
Change config logic so that DirectoryService options have their own
defaults, which are not merged when you change service types.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/config.py
CalendarServer/trunk/twistedcaldav/test/test_config.py
Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py 2007-03-14 21:42:34 UTC (rev 1389)
+++ CalendarServer/trunk/twistedcaldav/config.py 2007-03-14 22:17:13 UTC (rev 1390)
@@ -63,13 +63,7 @@
# A directory service provides information about principals (eg.
# users, groups, locations and resources) to the server.
#
- "DirectoryService": {
- "type": "twistedcaldav.directory.appleopendirectory.OpenDirectoryService",
- "params": {
- "node": "/Search",
- "requireComputerRecord": True,
- },
- },
+ "DirectoryService": {},
#
# Special principals
@@ -153,34 +147,64 @@
},
}
-def _mergeData(oldData, newData):
- for key, value in newData.iteritems():
- if isinstance(value, (dict,)) and key in ("MultiProcess",):
- assert isinstance(oldData.get(key, {}), (dict,))
- oldData[key] = _mergeData(oldData.get(key, {}), value)
- else:
- oldData[key] = value
+def _dsDefaults(configDict):
+ if configDict is None:
+ return None
- return oldData
+ configDict = copy.deepcopy(configDict)
+ dsDict = configDict.get("DirectoryService", None)
+ if dsDict is None:
+ return configDict
+
+ if "type" in dsDict:
+ dsType = dsDict["type"]
+ else:
+ dsType = "twistedcaldav.directory.xmlfile.XMLDirectoryService"
+ dsDict["type"] = dsType
+
+ if "params" in dsDict:
+ params = dsDict["params"]
+ else:
+ params = {}
+ dsDict["params"] = params
+
+ if dsType == "twistedcaldav.directory.xmlfile.XMLDirectoryService":
+ if "xmlFile" not in params:
+ params["xmlFile"] = "/etc/caldavd/accounts.xml"
+
+ elif dsType == "twistedcaldav.directory.appleopendirectory.OpenDirectoryService":
+ if "node" not in params:
+ params["node"] = "/Search"
+
+ if "requireComputerRecord" not in params:
+ params["requireComputerRecord"] = True
+
+ else:
+ raise AssertionError("Unknown directory service type: %r" % (dsType,))
+
+ return configDict
+
+defaultConfig = _dsDefaults(defaultConfig)
+
class Config (object):
def __init__(self, defaults):
- self._defaults = copy.deepcopy(defaults)
- self._data = copy.deepcopy(defaults)
+ self.setDefaults(defaults)
+ self._data = copy.deepcopy(self._defaults)
self._configFile = None
def __str__(self):
return str(self._data)
def update(self, items):
- self._data = _mergeData(self._data, items)
+ _mergeData(self._data, items)
def updateDefaults(self, items):
- self._defaults = _mergeData(self._defaults, items)
+ _mergeData(self._defaults, items)
self.update(items)
def setDefaults(self, defaults):
- self._defaults = copy.deepcopy(defaults)
+ self._defaults = _dsDefaults(defaults)
def __setattr__(self, attr, value):
if hasattr(self, '_data') and attr in self._data:
@@ -203,88 +227,100 @@
if configFile and os.path.exists(configFile):
configDict = readPlist(configFile)
- configDict = self.cleanup(configDict)
+ configDict = _cleanup(configDict)
self.update(configDict)
- def cleanup(self, configDict):
- cleanDict = copy.deepcopy(configDict)
+def _mergeData(oldData, newData):
+ newData = _dsDefaults(newData)
+ for key, value in newData.iteritems():
+ if isinstance(value, (dict,)) and key in ("MultiProcess",):
+ if key in oldData:
+ assert isinstance(oldData[key], (dict,))
+ else:
+ oldData[key] = {}
+ _mergeData(oldData[key], value)
+ else:
+ oldData[key] = value
- def deprecated(oldKey, newKey):
- log.err("Configuration option %r is deprecated in favor of %r." % (oldKey, newKey))
+def _cleanup(configDict):
+ cleanDict = copy.deepcopy(configDict)
- def renamed(oldKey, newKey):
- deprecated(oldKey, newKey)
- cleanDict[newKey] = configDict[oldKey]
- del cleanDict[oldKey]
+ def deprecated(oldKey, newKey):
+ log.err("Configuration option %r is deprecated in favor of %r." % (oldKey, newKey))
- renamedOptions = {
- "BindAddress" : "BindAddresses",
- "ServerLogFile" : "AccessLogFile",
- "MaximumAttachmentSizeBytes" : "MaximumAttachmentSize",
- "UserQuotaBytes" : "UserQuota",
- "DropBoxEnabled" : "EnableDropBox",
- "NotificationsEnabled" : "EnableNotifications",
- "CalendarUserProxyEnabled" : "EnableProxyPrincipals",
- "SACLEnable" : "EnableSACLs",
- "ServerType" : "ProcessType",
- }
+ def renamed(oldKey, newKey):
+ deprecated(oldKey, newKey)
+ cleanDict[newKey] = configDict[oldKey]
+ del cleanDict[oldKey]
- for key in configDict:
- if key in defaultConfig:
- continue
+ renamedOptions = {
+ "BindAddress" : "BindAddresses",
+ "ServerLogFile" : "AccessLogFile",
+ "MaximumAttachmentSizeBytes" : "MaximumAttachmentSize",
+ "UserQuotaBytes" : "UserQuota",
+ "DropBoxEnabled" : "EnableDropBox",
+ "NotificationsEnabled" : "EnableNotifications",
+ "CalendarUserProxyEnabled" : "EnableProxyPrincipals",
+ "SACLEnable" : "EnableSACLs",
+ "ServerType" : "ProcessType",
+ }
- if key == "SSLOnly":
- deprecated(key, "HTTPPort")
- if configDict["SSLOnly"]:
- cleanDict["HTTPPort"] = None
- del cleanDict["SSLOnly"]
+ for key in configDict:
+ if key in defaultConfig:
+ continue
- elif key == "SSLEnable":
- deprecated(key, "SSLPort")
- if not configDict["SSLEnable"]:
- cleanDict["SSLPort"] = None
- del cleanDict["SSLEnable"]
+ if key == "SSLOnly":
+ deprecated(key, "HTTPPort")
+ if configDict["SSLOnly"]:
+ cleanDict["HTTPPort"] = None
+ del cleanDict["SSLOnly"]
- elif key == "Port":
- deprecated(key, "HTTPPort")
- if not configDict.get("SSLOnly", False):
- cleanDict["HTTPPort"] = cleanDict["Port"]
- del cleanDict["Port"]
+ elif key == "SSLEnable":
+ deprecated(key, "SSLPort")
+ if not configDict["SSLEnable"]:
+ cleanDict["SSLPort"] = None
+ del cleanDict["SSLEnable"]
- elif key == "twistdLocation":
- deprecated(key, "Twisted -> twistd")
- if "Twisted" not in cleanDict:
- cleanDict["Twisted"] = {}
- cleanDict["Twisted"]["twistd"] = cleanDict["twistdLocation"]
- del cleanDict["twistdLocation"]
+ elif key == "Port":
+ deprecated(key, "HTTPPort")
+ if not configDict.get("SSLOnly", False):
+ cleanDict["HTTPPort"] = cleanDict["Port"]
+ del cleanDict["Port"]
- elif key == "pydirLocation":
- deprecated(key, "PythonDirector -> pydir")
- if "PythonDirector" not in cleanDict:
- cleanDict["PythonDirector"] = {}
- cleanDict["PythonDirector"]["pydir"] = cleanDict["pydirLocation"]
- del cleanDict["pydirLocation"]
+ elif key == "twistdLocation":
+ deprecated(key, "Twisted -> twistd")
+ if "Twisted" not in cleanDict:
+ cleanDict["Twisted"] = {}
+ cleanDict["Twisted"]["twistd"] = cleanDict["twistdLocation"]
+ del cleanDict["twistdLocation"]
- elif key == "pydirConfig":
- deprecated(key, "PythonDirector -> pydir")
- if "PythonDirector" not in cleanDict:
- cleanDict["PythonDirector"] = {}
- cleanDict["PythonDirector"]["ConfigFile"] = cleanDict["pydirConfig"]
- del cleanDict["pydirConfig"]
+ elif key == "pydirLocation":
+ deprecated(key, "PythonDirector -> pydir")
+ if "PythonDirector" not in cleanDict:
+ cleanDict["PythonDirector"] = {}
+ cleanDict["PythonDirector"]["pydir"] = cleanDict["pydirLocation"]
+ del cleanDict["pydirLocation"]
- elif key in renamedOptions:
- renamed(key, renamedOptions[key])
+ elif key == "pydirConfig":
+ deprecated(key, "PythonDirector -> pydir")
+ if "PythonDirector" not in cleanDict:
+ cleanDict["PythonDirector"] = {}
+ cleanDict["PythonDirector"]["ConfigFile"] = cleanDict["pydirConfig"]
+ del cleanDict["pydirConfig"]
- elif key == "RunStandalone":
- log.err("Ignoring obsolete configuration option: %s" % (key,))
- del cleanDict[key]
+ elif key in renamedOptions:
+ renamed(key, renamedOptions[key])
- else:
- log.err("Ignoring unknown configuration option: %s" % (key,))
- del cleanDict[key]
+ elif key == "RunStandalone":
+ log.err("Ignoring obsolete configuration option: %s" % (key,))
+ del cleanDict[key]
- return cleanDict
+ else:
+ log.err("Ignoring unknown configuration option: %s" % (key,))
+ del cleanDict[key]
+ return cleanDict
+
class ConfigurationError (RuntimeError):
"""
Invalid server configuration.
Modified: CalendarServer/trunk/twistedcaldav/test/test_config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_config.py 2007-03-14 21:42:34 UTC (rev 1389)
+++ CalendarServer/trunk/twistedcaldav/test/test_config.py 2007-03-14 22:17:13 UTC (rev 1390)
@@ -110,10 +110,35 @@
self.assertEquals(config.SSLPort, 8443)
def testMerge(self):
+ self.assertEquals(config.MultiProcess["LoadBalancer"]["Enabled"], True)
+
config.update({'MultiProcess': {}})
self.assertEquals(config.MultiProcess["LoadBalancer"]["Enabled"], True)
+ def testDirectoryService(self):
+ self.assertEquals(config.DirectoryService["type"], "twistedcaldav.directory.xmlfile.XMLDirectoryService")
+ self.assertEquals(config.DirectoryService["params"]["xmlFile"], "/etc/caldavd/accounts.xml")
+
+ config.update({"DirectoryService": {}})
+
+ self.assertEquals(config.DirectoryService["type"], "twistedcaldav.directory.xmlfile.XMLDirectoryService")
+ self.assertEquals(config.DirectoryService["params"]["xmlFile"], "/etc/caldavd/accounts.xml")
+
+ config.update({"DirectoryService": {"type": "twistedcaldav.directory.appleopendirectory.OpenDirectoryService"}})
+
+ self.assertEquals(config.DirectoryService["type"], "twistedcaldav.directory.appleopendirectory.OpenDirectoryService")
+ self.assertNotIn("xmlFile", config.DirectoryService["params"])
+ self.assertEquals(config.DirectoryService["params"]["node"], "/Search")
+ self.assertEquals(config.DirectoryService["params"]["requireComputerRecord"], True)
+
+ config.update({"DirectoryService": {"params": {"xmlFile": "/tmp/foo"}}})
+
+ self.assertEquals(config.DirectoryService["type"], "twistedcaldav.directory.xmlfile.XMLDirectoryService")
+ self.assertEquals(config.DirectoryService["params"]["xmlFile"], "/tmp/foo")
+ self.assertNotIn("node", config.DirectoryService["params"])
+ self.assertNotIn("requireComputerRecord", config.DirectoryService["params"])
+
def testUpdateDefaults(self):
self.assertEquals(config.SSLPort, -1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070314/d1748f71/attachment.html
More information about the calendarserver-changes
mailing list