[CalendarServer-changes] [5626] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Wed May 19 14:09:44 PDT 2010
Revision: 5626
http://trac.macosforge.org/projects/calendarserver/changeset/5626
Author: glyph at apple.com
Date: 2010-05-19 14:09:41 -0700 (Wed, 19 May 2010)
Log Message:
-----------
Correct configuration system to interpret relative paths present in twistedcaldav/stdconfig.py as relative to the roots provided in caldavd.plist, even if the relative paths themselves are not specified in caldavd.plist.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2010-05-19 20:41:08 UTC (rev 5625)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2010-05-19 21:09:41 UTC (rev 5626)
@@ -22,7 +22,7 @@
from twext.web2.dav import davxml
from twext.web2.dav.resource import TwistedACLInheritable
-from twext.python.plistlib import PlistParser
+from twext.python.plistlib import PlistParser #@UnresolvedImport
from twext.python.log import Logger, InvalidLogLevelError
from twext.python.log import clearLogLevels, setLogLevelForNamespace
@@ -593,20 +593,18 @@
configDict = {}
if self._configFileName:
configDict = self._parseConfigFromFile(self._configFileName)
-
# Now check for Includes and parse and add each of those
if "Includes" in configDict:
configRoot = os.path.join(configDict.ServerRoot, configDict.ConfigRoot)
for include in configDict.Includes:
-
+
additionalDict = self._parseConfigFromFile(fullServerPath(configRoot, include))
if additionalDict:
log.info("Adding configuration from file: '%s'" % (include,))
configDict.update(additionalDict)
-
- _updateDataStore(configDict)
return configDict
+
def _parseConfigFromFile(self, filename):
parser = NoUnicodePlistParser()
configDict = None
@@ -617,39 +615,50 @@
raise ConfigurationError("Configuration file does not exist or is inaccessible: %s" % (filename, ))
else:
configDict = _cleanup(configDict, self._defaults)
-
return configDict
+
def _updateDataStore(configDict):
-
- # Base paths
- if hasattr(configDict, "ServerRoot"):
- configDict.DataRoot = fullServerPath(configDict.ServerRoot, configDict.DataRoot)
- configDict.DocumentRoot = fullServerPath(configDict.ServerRoot, configDict.DocumentRoot)
- configDict.ConfigRoot = fullServerPath(configDict.ServerRoot, configDict.ConfigRoot)
- configDict.LogRoot = fullServerPath(configDict.ServerRoot, configDict.LogRoot)
- configDict.RunRoot = fullServerPath(configDict.ServerRoot, configDict.RunRoot)
+ """
+ Post-update configuration hook for making all configured paths relative to
+ their respective root directories rather than the current working directory.
+ """
+ for root, relativePath in [("ServerRoot", "DataRoot"),
+ ("ServerRoot", "DocumentRoot"),
+ ("ServerRoot", "ConfigRoot"),
+ ("ServerRoot", "LogRoot"),
+ ("ServerRoot", "RunRoot"),
+ ("ConfigRoot", "SudoersFile"),
+ ("LogRoot", "AccessLogFile"),
+ ("LogRoot", "ErrorLogFile"),
+ ("LogRoot", "AccountingLogRoot"),
+ ("RunRoot", "PIDFile"),
+ ("RunRoot", "GlobalStatsSocket"),
+ ("RunRoot", "ControlSocket")]:
+ if root in configDict and relativePath in configDict:
+ previousAbsoluteName = ".absolute." + relativePath
+ previousRelativeName = ".relative." + relativePath
- # Config paths
- if hasattr(configDict, "SudoersFile"):
- configDict.SudoersFile = fullServerPath(configDict.ConfigRoot, configDict.SudoersFile)
+ # If we previously made the name absolute, and the name in the
+ # config is still the same absolute name that we made it, let's
+ # change it to be the relative name again. (This is necessary
+ # because the config data is actually updated several times before
+ # the config *file* has been read, so these keys will be made
+ # absolute based on default values, and need to be made relative to
+ # non-default values later.) -glyph
+ if previousAbsoluteName in configDict and (
+ configDict[previousAbsoluteName] == configDict[relativePath]
+ ):
+ userSpecifiedPath = configDict[previousRelativeName]
+ else:
+ userSpecifiedPath = configDict[relativePath]
+ configDict[previousRelativeName] = configDict[relativePath]
+ newAbsolutePath = fullServerPath(configDict[root],
+ userSpecifiedPath)
+ configDict[relativePath] = newAbsolutePath
+ configDict[previousAbsoluteName] = newAbsolutePath
- # Log paths
- if hasattr(configDict, "AccessLogFile"):
- configDict.AccessLogFile = fullServerPath(configDict.LogRoot, configDict.AccessLogFile)
- if hasattr(configDict, "ErrorLogFile"):
- configDict.ErrorLogFile = fullServerPath(configDict.LogRoot, configDict.ErrorLogFile)
- if hasattr(configDict, "AccountingLogRoot"):
- configDict.AccountingLogRoot = fullServerPath(configDict.LogRoot, configDict.AccountingLogRoot)
- # Run paths
- if hasattr(configDict, "PIDFile"):
- configDict.PIDFile = fullServerPath(configDict.RunRoot, configDict.PIDFile)
- if hasattr(configDict, "GlobalStatsSocket"):
- configDict.GlobalStatsSocket = fullServerPath(configDict.RunRoot, configDict.GlobalStatsSocket)
- if hasattr(configDict, "ControlSocket"):
- configDict.ControlSocket = fullServerPath(configDict.RunRoot, configDict.ControlSocket)
-
def _updateHostName(configDict):
if not configDict.ServerHostName:
from socket import getfqdn
@@ -953,6 +962,7 @@
_preUpdateDirectoryAddressBookBackingDirectoryService,
)
POST_UPDATE_HOOKS = (
+ _updateDataStore,
_updateHostName,
_postUpdateDirectoryService,
_postUpdateAugmentService,
Modified: CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py 2010-05-19 20:41:08 UTC (rev 5625)
+++ CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py 2010-05-19 21:09:41 UTC (rev 5626)
@@ -21,7 +21,8 @@
from twisted.trial.unittest import TestCase
from twistedcaldav.config import Config
-from twistedcaldav.stdconfig import NoUnicodePlistParser, PListConfigProvider
+from twistedcaldav.stdconfig import NoUnicodePlistParser, PListConfigProvider,\
+ _updateDataStore
nonASCIIValue = "→←"
nonASCIIPlist = "<plist version='1.0'><string>%s</string></plist>" % (
@@ -66,6 +67,28 @@
self.assertEquals(cfg.DataRoot, nonASCIIValue)
+ def test_relativeDefaultPaths(self):
+ """
+ The paths specified in the default configuration should be interpreted
+ as relative to the paths specified in the configuration file.
+ """
+ cfg = Config(PListConfigProvider(
+ {"AccountingLogRoot": "some-path",
+ "LogRoot": "should-be-ignored"}))
+ cfg.addPostUpdateHooks([_updateDataStore])
+ tempfile = FilePath(self.mktemp())
+ tempfile.setContent("<plist version='1.0'><dict>"
+ "<key>LogRoot</key><string>/some/root</string>"
+ "</dict></plist>")
+ cfg.load(tempfile.path)
+ self.assertEquals(cfg.AccountingLogRoot, "/some/root/some-path")
+ tempfile.setContent("<plist version='1.0'><dict>"
+ "<key>LogRoot</key><string>/other/root</string>"
+ "</dict></plist>")
+ cfg.load(tempfile.path)
+ self.assertEquals(cfg.AccountingLogRoot, "/other/root/some-path")
+
+
def test_includes(self):
plist1 = """
@@ -115,6 +138,7 @@
"RunRoot": "",
"Includes": [],
}))
+ cfg.addPostUpdateHooks([_updateDataStore])
cfg.load(tempfile1.path)
self.assertEquals(cfg.DocumentRoot, "/root/defaultdoc")
self.assertEquals(cfg.DataRoot, "/root/overridedata")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100519/47e83d00/attachment.html>
More information about the calendarserver-changes
mailing list