Revert "Merge commit 'tomv_w/master'"
authorJoerg Jaspert <joerg@debian.org>
Tue, 30 Dec 2008 16:17:52 +0000 (17:17 +0100)
committerJoerg Jaspert <joerg@debian.org>
Tue, 30 Dec 2008 16:17:52 +0000 (17:17 +0100)
This reverts commit ec3837dcf11833fe7b10a843cfd0ccf7685cab74.

Signed-off-by: Joerg Jaspert <joerg@debian.org>
Dak/plugin.py

index 555710d..1d6465b 100644 (file)
@@ -1,11 +1,9 @@
 ###
 # Copyright (c) 2008, Joerg Jaspert <joerg@debian.org>
-# Copyright (c) 2008, Thomas Viehmann
 # GPL v2 (not later)
 ###
 
 import time
-import datetime
 import config
 import re
 
@@ -31,36 +29,21 @@ class Dak(callbacks.Plugin):
         self.fname = "dinstallcheck"
         self.dinstallhour = [1, 7, 13, 19]
         self.dinstallmin = self.registryValue('dinstallminute')
-        self.warntime=10
-        self.dinstallduration=4
+        warntime=10
+        self.warnframe = [i%60 for i in range(self.dinstallmin-warntime, self.dinstallmin+warntime+1, 1)]
+        self.dinstallframe = [i%60 for i in range(self.dinstallmin, self.dinstallmin+5, 1)]
         self.channel = self.registryValue('channel')
         self.locks = {}
 
         def checktime():
+            (undef, undef, undef, hour, minute, undef, undef, undef, undef) = time.gmtime()
             log.debug("DAK: Regular dinstall time check")
-
-            now = datetime.datetime.now()
-            # figure out time (in minutes) to next and from last dinstall
-            nextdinstall = None
-            lastdinstall = None
-            for h in self.dinstallhour:
-                ndt = now.replace(hour=h, minute=self.dinstallmin)
-                ldt = ndt
-                if ndt < now:
-                    ndt += datetime.timedelta(1)
-                if ldt > now:
-                    ldt -= datetime.timedelta(1)
-                ndt = int((ldt-now).seconds/60)
-                ldt = int((now-ldt).seconds/60)
-                if nextdinstall == None or ndt < nextdinstall:
-                    nextdinstall = ndt
-                if lastdinstall == None or ldt < lastdinstall:
-                    lastdinstall = ldt
-
-            if pdt <= self.warntime or ndt <= self.wantime:
+            if hour in self.dinstallhour:
+                log.debug("DAK: It is DINSTALL hour")
+                if minute in self.warnframe:
                     log.debug("DAK: In Dinstall Warnframe")
                     msgMaker = ircmsgs.privmsg
-                    if pdt <= self.dinstallduration:
+                    if minute in self.dinstallframe:
                         log.debug("DAK: In Dinstall timeframe")
                         # No longer time to warn only, now is time to act, if we haven't already
                         if self.registryValue('dinstall') == True:
@@ -93,6 +76,12 @@ class Dak(callbacks.Plugin):
                                 irc.queueMsg(msgMaker(self.channel, "%s: DINSTALL soon, hurry up" % (self.locks[key]) ))
                                 if key == "ALL":
                                     irc.queueMsg(msgMaker(self.channel, "%s: ALL locked. If you want to keep that, remember turning off cron" % (self.locks[key]) ))
+                else: # if minute in self.warnframe
+                    # Outside our warnframe.
+                    log.debug("DAK: Not in warnframe")
+                    conf.supybot.plugins.Dak.get('dinstall').setValue(False)
+                    conf.supybot.plugins.Dak.get('warned').setValue(False)
+
             else: # if hour in self.dinstallhour
                 # We are far outside a dinstall start
                 log.debug("DAK: Not even dinstall hour")
@@ -186,8 +175,8 @@ class Dak(callbacks.Plugin):
         text.append("Dinstall hour: %s, minute: %s" % (self.dinstallhour, self.dinstallmin))
         if len(self.locks) > 1:
             text.append("Current locks: %d (%s)" % (len(self.locks), self.locks))
-        text.append("Warnframe: dinstall-%d to dinstall+%d" % (self.warntime,self.warntime))
-        text.append("Dinstallframe: dinstall to dinstall+%d" % (self.dinstallduration,))
+        text.append("Warnframe: %s" % (self.warnframe))
+        text.append("Dinstallframe: %s" % (self.dinstallframe))
         text.append("Dinstall flag: %s, Warnflag: %s" % (conf.supybot.plugins.Dak.get('dinstall'), conf.supybot.plugins.Dak.get('warned')))
         for key in text:
             irc.reply(key)