[CalendarServer-changes] [15562] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 28 11:30:45 PDT 2016


Revision: 15562
          http://trac.calendarserver.org//changeset/15562
Author:   sagen at apple.com
Date:     2016-04-28 11:30:45 -0700 (Thu, 28 Apr 2016)
Log Message:
-----------
AlertPoster now has a sensible default, and a simpler API, with no need to getAlertPoster()

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/test/test_util.py
    CalendarServer/trunk/calendarserver/tap/util.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/smtpsender.py

Modified: CalendarServer/trunk/calendarserver/tap/test/test_util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/test_util.py	2016-04-28 17:26:17 UTC (rev 15561)
+++ CalendarServer/trunk/calendarserver/tap/test/test_util.py	2016-04-28 18:30:45 UTC (rev 15562)
@@ -350,7 +350,6 @@
 
     def test_protocol(self):
         self.patch(AlertPoster, "postAlert", self.stubPostAlert)
-        AlertPoster.setupForTest()
 
         client = AMP()
         server = AMPAlertProtocol()

Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py	2016-04-28 17:26:17 UTC (rev 15561)
+++ CalendarServer/trunk/calendarserver/tap/util.py	2016-04-28 18:30:45 UTC (rev 15562)
@@ -1322,7 +1322,7 @@
                         cert=config.SSLCertificate
                     )
                 )
-                AlertPoster.getAlertPoster().postAlert("MissingCertificateAlert", 0, ["path", config.SSLCertificate])
+                AlertPoster.postAlert("MissingCertificateAlert", 0, ["path", config.SSLCertificate])
                 return False, message
 
             length = os.stat(config.SSLCertificate).st_size
@@ -1387,7 +1387,7 @@
             try:
                 getAPNTopicFromConfig(protocol, accountName, protoConfig)
             except ValueError as e:
-                AlertPoster.getAlertPoster().postAlert("PushNotificationCertificateAlert", 0, [])
+                AlertPoster.postAlert("PushNotificationCertificateAlert", 0, [])
                 return False, str(e)
 
             # Let OpenSSL try to use the cert
@@ -1422,7 +1422,7 @@
                             reason=str(e)
                         )
                     )
-                AlertPoster.getAlertPoster().postAlert("PushNotificationCertificateAlert", 0, [])
+                AlertPoster.postAlert("PushNotificationCertificateAlert", 0, [])
                 return False, message
 
         return True, "APNS enabled"
@@ -1533,12 +1533,9 @@
 
 
     @classmethod
-    def setupForTest(cls):
-        cls._alertPoster = cls()
-
-
-    @classmethod
-    def getAlertPoster(cls):
+    def _getAlertPoster(cls):
+        if cls._alertPoster is None:
+            cls._alertPoster = cls()
         return cls._alertPoster
 
 
@@ -1550,8 +1547,11 @@
             self.sender = AMPAlertSender(controlSocket)
 
 
-    def postAlert(self, alertType, ignoreWithinSeconds, args):
+    @classmethod
+    def postAlert(cls, alertType, ignoreWithinSeconds, args):
 
+        poster = cls._getAlertPoster()
+
         if not config.AlertPostingProgram:
             return
 
@@ -1559,14 +1559,14 @@
             return
 
         if ignoreWithinSeconds:
-            seconds = self.secondsSinceLastPost(alertType)
+            seconds = cls.secondsSinceLastPost(alertType)
             if seconds < ignoreWithinSeconds:
                 return
 
-        if self.sender is None:
+        if poster.sender is None:
             # Just do it
 
-            self.recordTimeStamp(alertType)
+            cls.recordTimeStamp(alertType)
 
             try:
                 commandLine = [config.AlertPostingProgram, alertType]
@@ -1584,7 +1584,7 @@
 
         else:
             # Send request to master over AMP
-            self.sender.sendAlert(alertType, args)
+            poster.sender.sendAlert(alertType, args)
 
 
     @classmethod
@@ -1694,7 +1694,7 @@
         """
         The "PostAlert" handler in the master
         """
-        AlertPoster.getAlertPoster().postAlert(alertType, 0, args)
+        AlertPoster.postAlert(alertType, 0, args)
         return {
             "status": "OK"
         }

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py	2016-04-28 17:26:17 UTC (rev 15561)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/inbound.py	2016-04-28 18:30:45 UTC (rev 15562)
@@ -640,7 +640,7 @@
 
     def connectionLost(self, reason):
         if reason.type is TLSError:
-            AlertPoster.getAlertPoster().postAlert("MailCertificateAlert", 7 * 24 * 60 * 60, [])
+            AlertPoster.postAlert("MailCertificateAlert", 7 * 24 * 60 * 60, [])
 
 
     def serverGreeting(self, capabilities):

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/smtpsender.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/smtpsender.py	2016-04-28 17:26:17 UTC (rev 15561)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/smtpsender.py	2016-04-28 18:30:45 UTC (rev 15562)
@@ -62,7 +62,7 @@
             from OpenSSL.SSL import Error as TLSError
             if failure.type is TLSError:
                 from calendarserver.tap.util import AlertPoster
-                AlertPoster.getAlertPoster().postAlert("MailCertificateAlert", 7 * 24 * 60 * 60, [])
+                AlertPoster.postAlert("MailCertificateAlert", 7 * 24 * 60 * 60, [])
             return False
 
         deferred = defer.Deferred()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160428/22eeaa35/attachment.html>


More information about the calendarserver-changes mailing list