[CalendarServer-changes] [4607] CalendarServer/branches/users/cdaboo/deployment-partition-4593

source_changes at macosforge.org source_changes at macosforge.org
Tue Oct 20 09:02:51 PDT 2009


Revision: 4607
          http://trac.macosforge.org/projects/calendarserver/changeset/4607
Author:   cdaboo at apple.com
Date:     2009-10-20 09:02:48 -0700 (Tue, 20 Oct 2009)
Log Message:
-----------
Trying again to get PYTHONPATH right.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/deployment-partition-4593/bin/caldav_load_augmentdb

Added Paths:
-----------
    CalendarServer/branches/users/cdaboo/deployment-partition-4593/calendarserver/tools/loadaugmentdb.py

Modified: CalendarServer/branches/users/cdaboo/deployment-partition-4593/bin/caldav_load_augmentdb
===================================================================
--- CalendarServer/branches/users/cdaboo/deployment-partition-4593/bin/caldav_load_augmentdb	2009-10-20 15:57:00 UTC (rev 4606)
+++ CalendarServer/branches/users/cdaboo/deployment-partition-4593/bin/caldav_load_augmentdb	2009-10-20 16:02:48 UTC (rev 4607)
@@ -1,7 +1,4 @@
 #!/usr/bin/env python
-from twistedcaldav.directory import augment
-from twistedcaldav.directory.augment import AugmentXMLDB
-
 ##
 # Copyright (c) 2006-2007 Apple Inc. All rights reserved.
 #
@@ -18,147 +15,10 @@
 # limitations under the License.
 ##
 
-
-from getopt import getopt, GetoptError
-from grp import getgrnam
-from pwd import getpwnam
-from sys import stdout, stderr
-from twisted.internet import reactor
-from twisted.python.log import addObserver, removeObserver
-from twisted.python.util import switchUID
-from twistedcaldav.config import config, ConfigurationError
-from twistedcaldav.log import setLogLevelForNamespace
-from twisted.internet.defer import inlineCallbacks
-from calendarserver.tools.util import loadConfig, getDirectory,\
-    autoDisableMemcached
-import os
 import sys
 
-class UsageError (StandardError):
-    pass
+#PYTHONPATH
 
-class StandardIOObserver (object):
-    """
-    Log observer that writes to standard I/O.
-    """
-    def emit(self, eventDict):
-        text = None
-
-        if eventDict["isError"]:
-            output = stderr
-            if "failure" in eventDict:
-                text = eventDict["failure"].getTraceback()
-        else:
-            output = stdout
-
-        if not text:
-            text = " ".join([str(m) for m in eventDict["message"]]) + "\n"
-
-        output.write(text)
-        output.flush()
-
-    def start(self):
-        addObserver(self.emit)
-
-    def stop(self):
-        removeObserver(self.emit)
-
-def usage(e=None):
-    if e:
-        print e
-        print ""
-
-    name = os.path.basename(sys.argv[0])
-    print "usage: %s [options]" % (name,)
-    print ""
-    print "Populate an sqlite or PostgreSQL augments database with values"
-    print "from an XML augments file."
-    print ""
-    print "options:"
-    print "  -h --help: print this help and exit"
-    print "  -f --config: Specify caldavd.plist configuration path"
-    print "  -x --xmlfile: Specify xml augments file path"
-
-    if e:
-        sys.exit(64)
-    else:
-        sys.exit(0)
-
-def main():
-    try:
-        (optargs, args) = getopt(
-            sys.argv[1:], "hf:x:", [
-                "config=",
-                "xmlfile=",
-                "help",
-            ],
-        )
-    except GetoptError, e:
-        usage(e)
-
-    configFileName = None
-    xmlFileName = None
-
-    for opt, arg in optargs:
-        if opt in ("-h", "--help"):
-            usage()
-
-        elif opt in ("-f", "--config"):
-            configFileName = arg
-
-        elif opt in ("-x", "--xmlfile"):
-            xmlFileName = arg
-
-    if args:
-        usage("Too many arguments: %s" % (" ".join(args),))
-
-    observer = StandardIOObserver()
-    observer.start()
-
-    #
-    # Get configuration
-    #
-    try:
-        loadConfig(configFileName)
-        setLogLevelForNamespace(None, "warn")
-
-        # Shed privileges
-        if config.UserName and config.GroupName and os.getuid() == 0:
-            uid = getpwnam(config.UserName).pw_uid
-            gid = getgrnam(config.GroupName).gr_gid
-            switchUID(uid, uid, gid)
-
-        os.umask(config.umask)
-
-        config.directory = getDirectory()
-        autoDisableMemcached(config)
-    except ConfigurationError, e:
-        usage("Unable to start: %s" % (e,))
-
-    try:
-        dbxml = AugmentXMLDB((xmlFileName,))
-    except IOError, e:
-        usage("Could not read XML augment file: %s" % (e,))
-
-    #
-    # Start the reactor
-    #
-    reactor.callLater(0, run, dbxml)
-    reactor.run()
-
- at inlineCallbacks
-def run(dbxml):
-    
-    try:
-        yield augment.AugmentService.clean()
-        for record in dbxml.db.values():
-            yield augment.AugmentService.addAugmentRecord(record)
-    finally:
-        #
-        # Stop the reactor
-        #
-        reactor.stop()
-
 if __name__ == "__main__":
     if "PYTHONPATH" in globals():
         sys.path.insert(0, PYTHONPATH)
@@ -175,4 +35,5 @@
         if child.wait() == 0:
             sys.path[0:0] = path.split(":")
 
+    from calendarserver.tools.loadaugmentdb import main
     main()

Added: CalendarServer/branches/users/cdaboo/deployment-partition-4593/calendarserver/tools/loadaugmentdb.py
===================================================================
--- CalendarServer/branches/users/cdaboo/deployment-partition-4593/calendarserver/tools/loadaugmentdb.py	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/deployment-partition-4593/calendarserver/tools/loadaugmentdb.py	2009-10-20 16:02:48 UTC (rev 4607)
@@ -0,0 +1,160 @@
+#!/usr/bin/env python
+from twistedcaldav.directory import augment
+from twistedcaldav.directory.augment import AugmentXMLDB
+
+##
+# 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.
+##
+
+
+from getopt import getopt, GetoptError
+from grp import getgrnam
+from pwd import getpwnam
+from sys import stdout, stderr
+from twisted.internet import reactor
+from twisted.python.log import addObserver, removeObserver
+from twisted.python.util import switchUID
+from twistedcaldav.config import config, ConfigurationError
+from twistedcaldav.log import setLogLevelForNamespace
+from twisted.internet.defer import inlineCallbacks
+from calendarserver.tools.util import loadConfig, getDirectory,\
+    autoDisableMemcached
+import os
+import sys
+
+class UsageError (StandardError):
+    pass
+
+class StandardIOObserver (object):
+    """
+    Log observer that writes to standard I/O.
+    """
+    def emit(self, eventDict):
+        text = None
+
+        if eventDict["isError"]:
+            output = stderr
+            if "failure" in eventDict:
+                text = eventDict["failure"].getTraceback()
+        else:
+            output = stdout
+
+        if not text:
+            text = " ".join([str(m) for m in eventDict["message"]]) + "\n"
+
+        output.write(text)
+        output.flush()
+
+    def start(self):
+        addObserver(self.emit)
+
+    def stop(self):
+        removeObserver(self.emit)
+
+def usage(e=None):
+    if e:
+        print e
+        print ""
+
+    name = os.path.basename(sys.argv[0])
+    print "usage: %s [options]" % (name,)
+    print ""
+    print "Populate an sqlite or PostgreSQL augments database with values"
+    print "from an XML augments file."
+    print ""
+    print "options:"
+    print "  -h --help: print this help and exit"
+    print "  -f --config: Specify caldavd.plist configuration path"
+    print "  -x --xmlfile: Specify xml augments file path"
+
+    if e:
+        sys.exit(64)
+    else:
+        sys.exit(0)
+
+def main():
+    try:
+        (optargs, args) = getopt(
+            sys.argv[1:], "hf:x:", [
+                "config=",
+                "xmlfile=",
+                "help",
+            ],
+        )
+    except GetoptError, e:
+        usage(e)
+
+    configFileName = None
+    xmlFileName = None
+
+    for opt, arg in optargs:
+        if opt in ("-h", "--help"):
+            usage()
+
+        elif opt in ("-f", "--config"):
+            configFileName = arg
+
+        elif opt in ("-x", "--xmlfile"):
+            xmlFileName = arg
+
+    if args:
+        usage("Too many arguments: %s" % (" ".join(args),))
+
+    observer = StandardIOObserver()
+    observer.start()
+
+    #
+    # Get configuration
+    #
+    try:
+        loadConfig(configFileName)
+        setLogLevelForNamespace(None, "warn")
+
+        # Shed privileges
+        if config.UserName and config.GroupName and os.getuid() == 0:
+            uid = getpwnam(config.UserName).pw_uid
+            gid = getgrnam(config.GroupName).gr_gid
+            switchUID(uid, uid, gid)
+
+        os.umask(config.umask)
+
+        config.directory = getDirectory()
+        autoDisableMemcached(config)
+    except ConfigurationError, e:
+        usage("Unable to start: %s" % (e,))
+
+    try:
+        dbxml = AugmentXMLDB((xmlFileName,))
+    except IOError, e:
+        usage("Could not read XML augment file: %s" % (e,))
+
+    #
+    # Start the reactor
+    #
+    reactor.callLater(0, run, dbxml)
+    reactor.run()
+
+ at inlineCallbacks
+def run(dbxml):
+    
+    try:
+        yield augment.AugmentService.clean()
+        for record in dbxml.db.values():
+            yield augment.AugmentService.addAugmentRecord(record)
+    finally:
+        #
+        # Stop the reactor
+        #
+        reactor.stop()


Property changes on: CalendarServer/branches/users/cdaboo/deployment-partition-4593/calendarserver/tools/loadaugmentdb.py
___________________________________________________________________
Added: svn:executable
   + *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091020/dba9e820/attachment.html>


More information about the calendarserver-changes mailing list