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

[dakbot/master] Let bot display current phase when dinstall is running



Signed-off-by: Luca Falavigna <dktrkranz@debian.org>
---
 Dak/plugin.py |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/Dak/plugin.py b/Dak/plugin.py
index 4bd6fed..b11f88c 100644
--- a/Dak/plugin.py
+++ b/Dak/plugin.py
@@ -9,6 +9,7 @@ import time
 import datetime
 import config
 import re
+from urllib2 import urlopen, URLError
 
 import supybot.log as log
 from supybot.commands import *
@@ -122,6 +123,22 @@ class Dak(callbacks.Plugin):
         except KeyError:
             pass
 
+    def dinstall_phases(self):
+        try:
+            dinstall = urlopen('http://ftp-master.debian.org/dinstall.status', timeout=5)
+        except URLError:
+            log.debug("Unable to get dinstall status")
+        else:
+            data = dinstall.read()
+            try:
+                action = re.findall('Current action: (.*)', data)[0]
+            except:
+                log.debug("Unable to get dinstall status")
+            else:
+                if action.startswith('all done'):
+                    pass
+                else:
+                    return 'Dinstall is running, %s phase' % action
 
     def dinstall(self, irc, msg, args):
         """takes no arguments
@@ -139,6 +156,7 @@ class Dak(callbacks.Plugin):
 
         (year, month, day, hour, minute, second, undef, undef, undef) = time.gmtime()
 
+        dinstall_phase = self.dinstall_phases()
         log.debug("The latest run is at %s:%s" % (self.dinstallhour[-1], self.dinstallmin))
         log.debug("I think we now have %s:%s" % (hour, minute))
 
@@ -164,7 +182,10 @@ class Dak(callbacks.Plugin):
         start="%s:%s:%s" % (hour, minute, second)
         stop="%s:%s:00" % (newhour, self.dinstallmin)
         difference=deltatime(start, stop)
-        irc.reply("I guess the next dinstall will be in %s" % (difference))
+        if dinstall_phase:
+            irc.reply(dinstall_phase)
+        else:
+            irc.reply("I guess the next dinstall will be in %s" % (difference))
     dinstall = wrap(dinstall)
 
     def locked(self, irc, msg, args):
-- 
1.7.2.5


Reply to: