[CalendarServer-changes] [12353] CalendarServer/branches/release/CalendarServer-5.2-dev/ calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:24:36 PDT 2014


Revision: 12353
          http://trac.calendarserver.org//changeset/12353
Author:   sagen at apple.com
Date:     2014-01-15 14:22:04 -0800 (Wed, 15 Jan 2014)
Log Message:
-----------
have ampnotifications.py and push.py use the WorkerService from cmdline.py

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/ampnotifications.py
    CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/push.py

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/ampnotifications.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/ampnotifications.py	2014-01-15 22:21:35 UTC (rev 12352)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/ampnotifications.py	2014-01-15 22:22:04 UTC (rev 12353)
@@ -17,21 +17,20 @@
 from __future__ import print_function
 
 from calendarserver.push.amppush import subscribeToIDs
-from calendarserver.tools.cmdline import utilityMain
+from calendarserver.tools.cmdline import utilityMain, WorkerService
 
 from getopt import getopt, GetoptError
 
 from twext.python.log import Logger
 
-from twisted.application.service import Service
 from twisted.internet.defer import inlineCallbacks, succeed
-from twistedcaldav.config import ConfigurationError
 
 import os
 import sys
 
 log = Logger()
 
+
 def usage(e=None):
 
     name = os.path.basename(sys.argv[0])
@@ -55,24 +54,6 @@
 
 
 
-class WorkerService(Service):
-
-    def __init__(self, store):
-        self.store = store
-
-
-    @inlineCallbacks
-    def startService(self):
-        try:
-            yield self.doWork()
-        except ConfigurationError, ce:
-            sys.stderr.write("Error: %s\n" % (str(ce),))
-        except Exception, e:
-            sys.stderr.write("Error: %s\n" % (e,))
-            raise
-
-
-
 class MonitorAMPNotifications(WorkerService):
 
     ids = []
@@ -83,7 +64,13 @@
         return monitorAMPNotifications(self.hostname, self.port, self.ids)
 
 
+    def postStartService(self):
+        """
+        Don't quit right away
+        """
+        pass
 
+
 def main():
 
     try:

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/push.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/push.py	2014-01-15 22:21:35 UTC (rev 12352)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/push.py	2014-01-15 22:22:04 UTC (rev 12353)
@@ -16,64 +16,15 @@
 ##
 from __future__ import print_function
 
-from calendarserver.tap.util import getRootResource
-from calendarserver.tools.cmdline import utilityMain
-from errno import ENOENT, EACCES
+from calendarserver.tools.cmdline import utilityMain, WorkerService
 from argparse import ArgumentParser
 from twext.python.log import Logger
-from twisted.application.service import Service
-from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks
-from twistedcaldav.config import config, ConfigurationError
-import sys
 import time
 
 log = Logger()
 
 
-class WorkerService(Service):
-
-    def __init__(self, store):
-        self.store = store
-
-
-    def rootResource(self):
-        try:
-            rootResource = getRootResource(config, self.store)
-        except OSError, e:
-            if e.errno == ENOENT:
-                # Trying to re-write resources.xml but its parent directory does
-                # not exist.  The server's never been started, so we're missing
-                # state required to do any work.  (Plus, what would be the point
-                # of purging stuff from a server that's completely empty?)
-                raise ConfigurationError(
-                    "It appears that the server has never been started.\n"
-                    "Please start it at least once before purging anything.")
-            elif e.errno == EACCES:
-                # Trying to re-write resources.xml but it is not writable by the
-                # current user.  This most likely means we're in a system
-                # configuration and the user doesn't have sufficient privileges
-                # to do the other things the tool might need to do either.
-                raise ConfigurationError("You must run this tool as root.")
-            else:
-                raise
-        return rootResource
-
-
-    @inlineCallbacks
-    def startService(self):
-        try:
-            yield self.doWork()
-        except ConfigurationError, ce:
-            sys.stderr.write("Error: %s\n" % (str(ce),))
-        except Exception, e:
-            sys.stderr.write("Error: %s\n" % (e,))
-            raise
-        finally:
-            reactor.stop()
-
-
-
 class DisplayAPNSubscriptions(WorkerService):
 
     users = []
@@ -82,7 +33,7 @@
         rootResource = self.rootResource()
         directory = rootResource.getDirectory()
         return displayAPNSubscriptions(self.store, directory, rootResource,
-            self.users)
+                                       self.users)
 
 
 
@@ -91,7 +42,7 @@
     parser = ArgumentParser(description='Display Apple Push Notification subscriptions')
     parser.add_argument('-f', '--config', dest='configFileName', metavar='CONFIGFILE', help='caldavd.plist configuration file path')
     parser.add_argument('-d', '--debug', action='store_true', help='show debug logging')
-    parser.add_argument('user', help='one or more users to display', nargs='+') # Required
+    parser.add_argument('user', help='one or more users to display', nargs='+')  # Required
     args = parser.parse_args()
 
     DisplayAPNSubscriptions.users = args.user
@@ -122,8 +73,8 @@
                     print
                     protocol, _ignore_host, path = key.strip("/").split("/", 2)
                     resource = {
-                        "CalDAV" : "calendar",
-                        "CardDAV" : "addressbook",
+                        "CalDAV": "calendar",
+                        "CardDAV": "addressbook",
                     }[protocol]
                     if "/" in path:
                         uid, collection = path.split("/")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/5940b16c/attachment.html>


More information about the calendarserver-changes mailing list