[CalendarServer-changes] [11023] CalendarServer/trunk/calendarserver
source_changes at macosforge.org
source_changes at macosforge.org
Tue Apr 9 20:14:09 PDT 2013
Revision: 11023
http://trac.calendarserver.org//changeset/11023
Author: sagen at apple.com
Date: 2013-04-09 20:14:09 -0700 (Tue, 09 Apr 2013)
Log Message:
-----------
Share directory-creation code between server and command line utilities
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
CalendarServer/trunk/calendarserver/tap/util.py
CalendarServer/trunk/calendarserver/tools/cmdline.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2013-04-10 03:13:10 UTC (rev 11022)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2013-04-10 03:14:09 UTC (rev 11023)
@@ -78,7 +78,7 @@
from twistedcaldav.upgrade import UpgradeFileSystemFormatService, PostDBImportService
from calendarserver.tap.util import pgServiceFromConfig, getDBPool, MemoryLimitService
-from calendarserver.tap.util import directoryFromConfig
+from calendarserver.tap.util import directoryFromConfig, checkDirectories
from twext.enterprise.ienterprise import POSTGRES_DIALECT
from twext.enterprise.ienterprise import ORACLE_DIALECT
@@ -108,7 +108,6 @@
from calendarserver.tap.util import pgConnectorFromConfig
from calendarserver.tap.util import oracleConnectorFromConfig
from calendarserver.tap.cfgchild import ConfiguredChildSpawner
-from calendarserver.tools.util import checkDirectory
from calendarserver.push.notifier import PushDistributor
from calendarserver.push.amppush import AMPPushMaster, AMPPushForwarder
from calendarserver.push.applepush import ApplePushNotifierService
@@ -387,8 +386,8 @@
config.updateDefaults(self.overrides)
- def checkDirectory(self, dirpath, description, access=None, create=None, wait=False):
- checkDirectory(dirpath, description, access=access, create=create, wait=wait)
+ def checkDirectories(self, config):
+ checkDirectories(config)
def checkConfiguration(self):
@@ -418,59 +417,9 @@
self.parent["pidfile"] = config.PIDFile
- #
- # Verify that server root actually exists
- #
- self.checkDirectory(
- config.ServerRoot,
- "Server root",
- # Require write access because one might not allow editing on /
- access=os.W_OK,
- wait=True # Wait in a loop until ServerRoot exists
- )
+ self.checkDirectories(config)
- #
- # Verify that other root paths are OK
- #
- if config.DataRoot.startswith(config.ServerRoot + os.sep):
- self.checkDirectory(
- config.DataRoot,
- "Data root",
- access=os.W_OK,
- create=(0750, config.UserName, config.GroupName),
- )
- if config.DocumentRoot.startswith(config.DataRoot + os.sep):
- self.checkDirectory(
- config.DocumentRoot,
- "Document root",
- # Don't require write access because one might not allow editing on /
- access=os.R_OK,
- create=(0750, config.UserName, config.GroupName),
- )
- if config.ConfigRoot.startswith(config.ServerRoot + os.sep):
- self.checkDirectory(
- config.ConfigRoot,
- "Config root",
- access=os.W_OK,
- create=(0750, config.UserName, config.GroupName),
- )
- if config.LogRoot.startswith(config.ServerRoot + os.sep):
- self.checkDirectory(
- config.LogRoot,
- "Log root",
- access=os.W_OK,
- create=(0750, config.UserName, config.GroupName),
- )
-
- # Always create RunRoot (for pid files, socket files) if it does not exist
- self.checkDirectory(
- config.RunRoot,
- "Run root",
- access=os.W_OK,
- create=(0770, config.UserName, config.GroupName),
- )
-
#
# Nuke the file log observer's time format.
#
Modified: CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2013-04-10 03:13:10 UTC (rev 11022)
+++ CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2013-04-10 03:14:09 UTC (rev 11023)
@@ -152,6 +152,8 @@
def checkFile(self, *args, **kwargs):
pass
+ def checkDirectories(self, *args, **kwargs):
+ pass
def loadConfiguration(self):
"""
Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py 2013-04-10 03:13:10 UTC (rev 11022)
+++ CalendarServer/trunk/calendarserver/tap/util.py 2013-04-10 03:14:09 UTC (rev 11023)
@@ -86,6 +86,7 @@
from calendarserver.accesslog import DirectoryLogWrapperResource
from calendarserver.provision.root import RootResource
+from calendarserver.tools.util import checkDirectory
from calendarserver.webadmin.resource import WebAdminResource
from calendarserver.webcal.resource import WebCalendarResource
@@ -960,3 +961,60 @@
self._processMonitor.stopProcess(name)
finally:
self._delayedCall = self._reactor.callLater(self._seconds, self.checkMemory)
+
+
+def checkDirectories(config):
+ """
+ Make sure that various key directories exist (and create if needed)
+ """
+
+ #
+ # Verify that server root actually exists
+ #
+ checkDirectory(
+ config.ServerRoot,
+ "Server root",
+ # Require write access because one might not allow editing on /
+ access=os.W_OK,
+ wait=True # Wait in a loop until ServerRoot exists
+ )
+
+ #
+ # Verify that other root paths are OK
+ #
+ if config.DataRoot.startswith(config.ServerRoot + os.sep):
+ checkDirectory(
+ config.DataRoot,
+ "Data root",
+ access=os.W_OK,
+ create=(0750, config.UserName, config.GroupName),
+ )
+ if config.DocumentRoot.startswith(config.DataRoot + os.sep):
+ checkDirectory(
+ config.DocumentRoot,
+ "Document root",
+ # Don't require write access because one might not allow editing on /
+ access=os.R_OK,
+ create=(0750, config.UserName, config.GroupName),
+ )
+ if config.ConfigRoot.startswith(config.ServerRoot + os.sep):
+ checkDirectory(
+ config.ConfigRoot,
+ "Config root",
+ access=os.W_OK,
+ create=(0750, config.UserName, config.GroupName),
+ )
+ if config.LogRoot.startswith(config.ServerRoot + os.sep):
+ checkDirectory(
+ config.LogRoot,
+ "Log root",
+ access=os.W_OK,
+ create=(0750, config.UserName, config.GroupName),
+ )
+ if config.RunRoot.startswith(config.ServerRoot + os.sep):
+ checkDirectory(
+ config.RunRoot,
+ "Run root",
+ access=os.W_OK,
+ create=(0770, config.UserName, config.GroupName),
+ )
Modified: CalendarServer/trunk/calendarserver/tools/cmdline.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/cmdline.py 2013-04-10 03:13:10 UTC (rev 11022)
+++ CalendarServer/trunk/calendarserver/tools/cmdline.py 2013-04-10 03:14:09 UTC (rev 11023)
@@ -19,6 +19,7 @@
"""
from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions
+from calendarserver.tap.util import checkDirectories
from calendarserver.tools.util import loadConfig, autoDisableMemcached
from twext.python.log import StandardIOObserver
@@ -26,7 +27,6 @@
from twistedcaldav.config import ConfigurationError
from twisted.internet.defer import inlineCallbacks
-import os
import sys
from calendarserver.tap.util import getRootResource
from twisted.application.service import Service
@@ -79,10 +79,7 @@
if patchConfig is not None:
patchConfig(config)
- # If we don't have permission to access the DataRoot directory, we
- # can't proceed. If this fails it should raise OSError which we
- # catch below.
- os.listdir(config.DataRoot)
+ checkDirectories(config)
config.ProcessType = "Utility"
config.UtilityServiceClass = serviceClass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130409/494b3dbf/attachment-0001.html>
More information about the calendarserver-changes
mailing list