[CalendarServer-changes] [8105] CalendarServer/trunk/calendarserver/tools/cmdline.py

source_changes at macosforge.org source_changes at macosforge.org
Fri Sep 16 14:08:24 PDT 2011


Revision: 8105
          http://trac.macosforge.org/projects/calendarserver/changeset/8105
Author:   sagen at apple.com
Date:     2011-09-16 14:08:24 -0700 (Fri, 16 Sep 2011)
Log Message:
-----------
Command line utilities should not print a traceback when not run as root.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/cmdline.py

Modified: CalendarServer/trunk/calendarserver/tools/cmdline.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/cmdline.py	2011-09-15 17:55:32 UTC (rev 8104)
+++ CalendarServer/trunk/calendarserver/tools/cmdline.py	2011-09-16 21:08:24 UTC (rev 8105)
@@ -18,7 +18,7 @@
 Shared main-point between utilities.
 """
 
-import sys
+import os, sys
 
 from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions
 from calendarserver.tools.util import loadConfig, autoDisableMemcached
@@ -57,6 +57,11 @@
     try:
         config = loadConfig(configFileName)
 
+        # 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)
+
         config.ProcessType = "Utility"
         config.UtilityServiceClass = serviceClass
 
@@ -73,5 +78,9 @@
         sys.stderr.write("Error: %s\n" % (e,))
         return
 
+    except OSError: # Permission
+        sys.stderr.write("Please run as root\n")
+        return
+
     reactor.run()
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110916/5c524d57/attachment.html>


More information about the calendarserver-changes mailing list