[CalendarServer-changes] [7447] CalendarServer/branches/users/glyph/new-export/calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Mon May 16 07:40:34 PDT 2011


Revision: 7447
          http://trac.macosforge.org/projects/calendarserver/changeset/7447
Author:   glyph at apple.com
Date:     2011-05-16 07:40:33 -0700 (Mon, 16 May 2011)
Log Message:
-----------
Oops, doing it that way establishes a circular reference.  Create a new module for utilityMain instead.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/new-export/calendarserver/tools/purge.py
    CalendarServer/branches/users/glyph/new-export/calendarserver/tools/util.py

Added Paths:
-----------
    CalendarServer/branches/users/glyph/new-export/calendarserver/tools/cmdline.py

Added: CalendarServer/branches/users/glyph/new-export/calendarserver/tools/cmdline.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/calendarserver/tools/cmdline.py	                        (rev 0)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/cmdline.py	2011-05-16 14:40:33 UTC (rev 7447)
@@ -0,0 +1,74 @@
+##
+# Copyright (c) 2005-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.
+##
+
+"""
+Shared main-point between utilities.
+"""
+
+import sys
+
+from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions
+from calendarserver.tools.util import loadConfig
+
+from twistedcaldav.config import ConfigurationError, config
+
+def utilityMain(configFileName, serviceClass, reactor=None):
+    """
+    Shared main-point for utilities.
+
+    This function will:
+
+        - Load the configuration file named by C{configFileName},
+        - launch a L{CalDAVServiceMaker}'s with the C{ProcessType} of
+          C{"Utility"}
+        - run the reactor, with start/stop events hooked up to the service's
+          C{startService}/C{stopService} methods.
+
+    It is C{serviceClass}'s responsibility to stop the reactor when it's
+    complete.
+
+    @param configFileName: the name of the configuration file to load.
+    @type configuration: C{str}
+
+    @param serviceClass: a 1-argument callable which takes an object that
+        provides L{ICalendarStore} and/or L{IAddressbookStore} and returns an
+        L{IService}.
+
+    @param reactor: if specified, the L{IReactorTime} / L{IReactorThreads} /
+        L{IReactorTCP} (etc) provider to use.  If C{None}, the default reactor
+        will be imported and used.
+    """
+    if reactor is None:
+        from twisted.internet import reactor
+    try:
+        loadConfig(configFileName)
+
+        config.ProcessType = "Utility"
+        config.UtilityServiceClass = serviceClass
+
+        maker = CalDAVServiceMaker()
+        options = CalDAVOptions
+        service = maker.makeService(options)
+
+        reactor.addSystemEventTrigger("during", "startup", service.startService)
+        reactor.addSystemEventTrigger("before", "shutdown", service.stopService)
+
+    except ConfigurationError, e:
+        sys.stderr.write("Error: %s\n" % (e,))
+        return
+
+    reactor.run()
+

Modified: CalendarServer/branches/users/glyph/new-export/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/calendarserver/tools/purge.py	2011-05-16 14:40:22 UTC (rev 7446)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/purge.py	2011-05-16 14:40:33 UTC (rev 7447)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-
+# -*- test-case-name: calendarserver.tools.test.test_purge -*-
 ##
 # Copyright (c) 2006-2010 Apple Inc. All rights reserved.
 #
@@ -22,9 +22,16 @@
 
 from getopt import getopt, GetoptError
 
+from pycalendar.datetime import PyCalendarDateTime
+
 from twisted.application.service import Service
 from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks, returnValue
+
+from twext.python.log import Logger
+from twext.web2.dav import davxml
+from twext.web2.responsecode import NO_CONTENT
+
 from twistedcaldav import caldavxml
 from twistedcaldav.caldavxml import TimeRange
 from twistedcaldav.config import config, ConfigurationError
@@ -33,14 +40,11 @@
 from twistedcaldav.method.put_common import StoreCalendarObjectResource
 from twistedcaldav.query import calendarqueryfilter
 
-from twext.python.log import Logger
-from twext.web2.dav import davxml
-from twext.web2.responsecode import NO_CONTENT
+from calendarserver.tap.util import FakeRequest
+from calendarserver.tap.util import getRootResource
 
-from calendarserver.tap.util import FakeRequest, utilityMain
-from calendarserver.tap.util import getRootResource
+from calendarserver.tools.cmdline import utilityMain
 from calendarserver.tools.principals import removeProxy
-from pycalendar.datetime import PyCalendarDateTime
 
 log = Logger()
 

Modified: CalendarServer/branches/users/glyph/new-export/calendarserver/tools/util.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/calendarserver/tools/util.py	2011-05-16 14:40:22 UTC (rev 7446)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/util.py	2011-05-16 14:40:33 UTC (rev 7447)
@@ -15,7 +15,7 @@
 ##
 
 """
-Utility functionality shared between calendarserver command-line tools.
+Utility functionality shared between calendarserver tools.
 """
 
 __all__ = [
@@ -26,7 +26,6 @@
     "booleanArgument",
 ]
 
-import sys
 import os
 from time import sleep
 import socket
@@ -39,7 +38,6 @@
 
 
 from calendarserver.provision.root import RootResource
-from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions
 
 from twistedcaldav import memcachepool
 from twistedcaldav.config import config, ConfigurationError
@@ -279,50 +277,3 @@
 
 
 
-def utilityMain(configFileName, serviceClass, reactor=None):
-    """
-    Shared main-point for utilities.
-
-    This function will:
-
-        - Load the configuration file named by C{configFileName},
-        - launch a L{CalDAVServiceMaker}'s with the C{ProcessType} of
-          C{"Utility"}
-        - run the reactor, with start/stop events hooked up to the service's
-          C{startService}/C{stopService} methods.
-
-    It is C{serviceClass}'s responsibility to stop the reactor when it's
-    complete.
-
-    @param configFileName: the name of the configuration file to load.
-    @type configuration: C{str}
-
-    @param serviceClass: a 1-argument callable which takes an object that
-        provides L{ICalendarStore} and/or L{IAddressbookStore} and returns an
-        L{IService}.
-
-    @param reactor: if specified, the L{IReactorTime} / L{IReactorThreads} /
-        L{IReactorTCP} (etc) provider to use.  If C{None}, the default reactor
-        will be imported and used.
-    """
-    if reactor is None:
-        from twisted.internet import reactor
-    try:
-        loadConfig(configFileName)
-
-        config.ProcessType = "Utility"
-        config.UtilityServiceClass = serviceClass
-
-        maker = CalDAVServiceMaker()
-        options = CalDAVOptions
-        service = maker.makeService(options)
-
-        reactor.addSystemEventTrigger("during", "startup", service.startService)
-        reactor.addSystemEventTrigger("before", "shutdown", service.stopService)
-
-    except ConfigurationError, e:
-        sys.stderr.write("Error: %s\n" % (e,))
-        return
-
-    reactor.run()
-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110516/b461bd80/attachment-0001.html>


More information about the calendarserver-changes mailing list