[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Dakbot] Add britney time query response



Hi all,

I wrote a patch (attached) to add Britney time query response to Dakbot. Can someone please review it, integrate it and deploy it? Eventually, make dak join #debian-release too so that we (the release team) can query it from
there directly.

(Please CC me on replies as I am not subscribed).

Cheers.

--
Mehdi
From 3eef576a82e393c0daf22bb861f429627b35e499 Mon Sep 17 00:00:00 2001
From: Mehdi Dogguy <mehdi@debian.org>
Date: Tue, 26 Aug 2014 16:01:13 -0700
Subject: [PATCH] Add support for Britney

---
 Dak/config.py |    3 +++
 Dak/plugin.py |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/Dak/config.py b/Dak/config.py
index a029e38..8a95861 100644
--- a/Dak/config.py
+++ b/Dak/config.py
@@ -34,4 +34,7 @@ conf.registerGlobalValue(Dak, 'dinstallminute',
 conf.registerGlobalValue(Dak, 'webwmlminute',
                          registry.NonNegativeInteger(24, """At which minute does webwml start?"""))
 
+conf.registerGlobalValue(Dak, 'britneyminute',
+                         registry.NonNegativeInteger(0, """At which minute does britney start?"""))
+
 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/Dak/plugin.py b/Dak/plugin.py
index fa13eb0..6f5c454 100644
--- a/Dak/plugin.py
+++ b/Dak/plugin.py
@@ -2,6 +2,7 @@
 # Copyright (c) 2008, Joerg Jaspert <joerg@debian.org>
 # Copyright (c) 2008, Thomas Viehmann
 # Copyright (c) 2009, Gerfried Fuchs <rhonda@debian.at>
+# Copyright (c) 2014, Mehdi Dogguy <mehdi@debian.org>
 # GPL v2 (not later)
 ###
 
@@ -35,6 +36,8 @@ class Dak(callbacks.Plugin):
         self.dinstallmin = self.registryValue('dinstallminute')
         self.webwmlhour = [3, 7, 11, 15, 19, 23]
         self.webwmlmin = self.registryValue('webwmlminute')
+        self.britneyhour = [10, 22]
+        self.britneymin = self.registryValue('britneyminute')
         self.warntime=10
         self.dinstallduration=4
         self.channel = self.registryValue('channel')
@@ -383,6 +386,66 @@ class Dak(callbacks.Plugin):
         irc.reply("I guess the next webwml run will be in %s" % (difference))
     webwml = wrap(webwml)
 
+    def britney_phases(self):
+        try:
+            status = urlopen('http://release.debian.org/britney/britney.status', timeout=5)
+        except URLError:
+            log.debug("Unable to get britney status")
+        else:
+            data = status.read()
+            if data.endswith(':\n'):
+                return 'Britney is running, %s phase' % data[:-2].lower()
+            elif data.startswith('Finished at: '):
+                return 'Last britney run f%s' % data[1:-1]
+
+    def britney(self, irc, msg, args):
+        """takes no arguments
+
+        Returns the time until next britney run
+        """
+
+        def deltatime(start, stop):
+            def toSeconds(timeString):
+                hour, min, sec = map(int, timeString.split(':'))
+                return (hour * 60 + min) * 60 + sec
+            d_time_min, d_time_sec = divmod(toSeconds(stop) - toSeconds(start), 60)
+            d_time_hr, d_time_min = divmod(d_time_min, 60)
+            return '%dhr %dmin %ssec' % (d_time_hr % 24, d_time_min, d_time_sec)
+
+        (year, month, day, hour, minute, second, undef, undef, undef) = time.gmtime()
+
+        log.debug("The latest run is at %s:%s" % (self.britneyhour[-1], self.britneymin))
+        log.debug("I think we now have %s:%s" % (hour, minute))
+
+        newhour = hour
+        if minute >= self.britneymin and newhour in self.britneyhour:
+            # If we already passed britneyminute, we are running and want the next runtime.
+            log.debug("We are past this hours britney run already")
+            newhour+=1
+
+        if newhour > self.britneyhour[-1]:
+            log.debug("We are also past the last britney run for today")
+            # We are past the last britney today, so next one must be the first tomorrow, start searching at midnight
+            newhour = self.britneyhour[0]
+        else:
+            while newhour not in self.britneyhour:
+                newhour+=1
+                log.debug("Looking at possible hour %s" % (newhour))
+                if newhour > 23:
+                    newhour=0
+
+        log.debug("I found that next britney run will be at %s:%s" % (newhour, self.britneymin))
+
+        start="%s:%s:%s" % (hour, minute, second)
+        stop="%s:%s:00" % (newhour, self.britneymin)
+        difference=deltatime(start, stop)
+
+        britney_phase = self.britney_phases()
+        if britney_phase:
+            irc.reply(britney_phase)
+        else:
+            irc.reply("I guess the next britney run will be in %s" % (difference))
+    britney = wrap(britney)
 
 Class = Dak
 
-- 
1.7.10.4


Reply to: