[CalendarServer-changes] [6399] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Oct 5 11:18:11 PDT 2010


Revision: 6399
          http://trac.macosforge.org/projects/calendarserver/changeset/6399
Author:   wsanchez at apple.com
Date:     2010-10-05 11:18:10 -0700 (Tue, 05 Oct 2010)
Log Message:
-----------
Add config tool

Added Paths:
-----------
    CalendarServer/trunk/bin/calendarserver_config
    CalendarServer/trunk/calendarserver/tools/config.py

Added: CalendarServer/trunk/bin/calendarserver_config
===================================================================
--- CalendarServer/trunk/bin/calendarserver_config	                        (rev 0)
+++ CalendarServer/trunk/bin/calendarserver_config	2010-10-05 18:18:10 UTC (rev 6399)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+##
+# Copyright (c) 2006-2007 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import sys
+
+#PYTHONPATH
+
+if __name__ == "__main__":
+    if "PYTHONPATH" in globals():
+        sys.path.insert(0, PYTHONPATH)
+    else:
+        from os.path import dirname, abspath, join
+        from subprocess import Popen, PIPE
+
+        home = dirname(dirname(abspath(__file__)))
+        run = join(home, "run")
+
+        child = Popen((run, "-p"), stdout=PIPE)
+        path, stderr = child.communicate()
+
+        path = path.rstrip("\n")
+
+        if child.wait() == 0:
+            sys.path[0:0] = path.split(":")
+
+        sys.argv[1:1] = ["-f", join(home, "conf", "caldavd-dev.plist")]
+
+    from calendarserver.tools.config import main
+    main()


Property changes on: CalendarServer/trunk/bin/calendarserver_config
___________________________________________________________________
Added: svn:executable
   + *

Added: CalendarServer/trunk/calendarserver/tools/config.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/config.py	                        (rev 0)
+++ CalendarServer/trunk/calendarserver/tools/config.py	2010-10-05 18:18:10 UTC (rev 6399)
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+##
+# Copyright (c) 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+This tool reads the Calendar Server configuration file and emits the
+requested value.
+"""
+
+import sys
+from getopt import getopt, GetoptError
+
+from twistedcaldav import config
+from twistedcaldav.config import ConfigurationError
+from twistedcaldav.stdconfig import DEFAULT_CONFIG_FILE
+
+from calendarserver.tools.util import UsageError
+from calendarserver.tools.util import loadConfig
+
+def usage(e=None):
+    if e:
+        print e
+        print ""
+
+    name = os.path.basename(sys.argv[0])
+    print "usage: %s [options] config_key" % (name,)
+    print ""
+    print "Print the value of the given config key."
+    print "options:"
+    print "  -h --help: print this help and exit"
+    print "  -f --config: Specify caldavd.plist configuration path"
+
+    if e:
+        sys.exit(64)
+    else:
+        sys.exit(0)
+
+def main():
+    try:
+        (optargs, args) = getopt(
+            sys.argv[1:], "hf:", [
+                "help",
+                "config=",
+            ],
+        )
+    except GetoptError, e:
+        usage(e)
+
+    configFileName = DEFAULT_CONFIG_FILE
+
+    for opt, arg in optargs:
+        if opt in ("-h", "--help"):
+            usage()
+
+        elif opt in ("-f", "--config"):
+            configFileName = arg
+
+    try:
+        config = loadConfig(configFileName)
+    except ConfigurationError, e:
+        sys.stdout.write("%s\n" % (e,))
+        sys.exit(1)
+
+    for configKey in args:
+        c = config
+        for subKey in configKey.split("."):
+            c = c.get(subKey, None)
+            if c is None:
+                sys.stderr.write("No such config key: %s\n" % configKey)
+                break
+        else:
+            sys.stdout.write("%s\n" % c)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101005/b4868269/attachment.html>


More information about the calendarserver-changes mailing list