[CalendarServer-changes] [4967] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jan 26 21:02:57 PST 2010
Revision: 4967
http://trac.macosforge.org/projects/calendarserver/changeset/4967
Author: cdaboo at apple.com
Date: 2010-01-26 21:02:55 -0800 (Tue, 26 Jan 2010)
Log Message:
-----------
Add .plist #include type behavior so one .plist file can override properties in another file.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py
Modified: CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2010-01-27 03:57:17 UTC (rev 4966)
+++ CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2010-01-27 05:02:55 UTC (rev 4967)
@@ -89,8 +89,12 @@
Test that values on the command line's -o and --option options
overide the config file
"""
+ myConfig = ConfigDict(DEFAULT_CONFIG)
+ myConfigFile = self.mktemp()
+ writePlist(myConfig, myConfigFile)
+
argv = [
- "-f", "No-Such-File",
+ "-f", myConfigFile,
"-o", "EnableSACLs",
"-o", "HTTPPort=80",
"-o", "BindAddresses=127.0.0.1,127.0.0.2,127.0.0.3",
@@ -118,8 +122,12 @@
Test that certain values are set on the parent (i.e. twistd's
Option's object)
"""
+ myConfig = ConfigDict(DEFAULT_CONFIG)
+ myConfigFile = self.mktemp()
+ writePlist(myConfig, myConfigFile)
+
argv = [
- "-f", "No-Such-File",
+ "-f", myConfigFile,
"-o", "ErrorLogFile=/dev/null",
"-o", "PIDFile=/dev/null",
]
@@ -159,9 +167,13 @@
Test that we can specify command line overrides to leafs using
a "/" seperated path. Such as "-o MultiProcess/ProcessCount=1"
"""
+ myConfig = ConfigDict(DEFAULT_CONFIG)
+ myConfigFile = self.mktemp()
+ writePlist(myConfig, myConfigFile)
+
argv = [
"-o", "MultiProcess/ProcessCount=102",
- "-f", "conf/caldavd.plist",
+ "-f", myConfigFile,
]
self.config.parseOptions(argv)
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2010-01-27 03:57:17 UTC (rev 4966)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2010-01-27 05:02:55 UTC (rev 4967)
@@ -460,6 +460,8 @@
"EnableKeepAlive": True,
"ResponseCacheTimeout": 30, # Minutes
+
+ "Includes": [], # Other plists to parse after this one
}
@@ -486,16 +488,31 @@
def loadConfig(self):
configDict = {}
if self._configFileName:
- parser = NoUnicodePlistParser()
- try:
- configDict = parser.parse(open(self._configFileName))
- except (IOError, OSError):
- log.error("Configuration file does not exist or is inaccessible: %s" %
- (self._configFileName,))
- else:
- configDict = _cleanup(configDict, self._defaults)
+ configDict = self._parseConfigFromFile(self._configFileName)
+
+ # Now check for Includes and parse and add each of those
+ if "Includes" in configDict:
+ for include in configDict.Includes:
+
+ additionalDict = self._parseConfigFromFile(include)
+ if additionalDict:
+ log.info("Adding configuration from file: '%s'" % (include,))
+ configDict.update(additionalDict)
+
return configDict
+ def _parseConfigFromFile(self, filename):
+ parser = NoUnicodePlistParser()
+ configDict = None
+ try:
+ configDict = parser.parse(open(filename))
+ except (IOError, OSError):
+ log.err("Configuration file does not exist or is inaccessible: %s" % (filename, ))
+ raise ConfigurationError("Configuration file does not exist or is inaccessible: %s" % (filename, ))
+ else:
+ configDict = _cleanup(configDict, self._defaults)
+
+ return configDict
def _updateHostName(configDict):
if not configDict.ServerHostName:
Modified: CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py 2010-01-27 03:57:17 UTC (rev 4966)
+++ CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py 2010-01-27 05:02:55 UTC (rev 4967)
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##
-# Copyright (c) 2005-2009 Apple Inc. All rights reserved.
+# Copyright (c) 2005-2010 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -66,4 +66,43 @@
self.assertEquals(cfg.DataRoot, nonASCIIValue)
+ def test_includes(self):
+ plist1 = """
+<plist version="1.0">
+ <dict>
+ <key>DocumentRoot</key>
+ <string>defaultdoc</string>
+ <key>DataRoot</key>
+ <string>defaultdata</string>
+ <key>Includes</key>
+ <array>
+ <string>%s</string>
+ </array>
+ </dict>
+</plist>
+"""
+
+ plist2 = """
+<plist version="1.0">
+ <dict>
+ <key>DataRoot</key>
+ <string>overridedata</string>
+ </dict>
+</plist>
+"""
+
+ tempfile2 = FilePath(self.mktemp())
+ tempfile2.setContent(plist2)
+
+ tempfile1 = FilePath(self.mktemp())
+ tempfile1.setContent(plist1 % (tempfile2.path,))
+
+ cfg = Config(PListConfigProvider({
+ "DocumentRoot": "",
+ "DataRoot": "",
+ "Includes": [],
+ }))
+ cfg.load(tempfile1.path)
+ self.assertEquals(cfg.DocumentRoot, "defaultdoc")
+ self.assertEquals(cfg.DataRoot, "overridedata")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100126/73c0c9f4/attachment-0001.html>
More information about the calendarserver-changes
mailing list