[gnome-continuous/wip/supybot] supybot: Make @buildstatus show status for all tasks in the correct channel



commit 7ce5bb4ed9bf10d86e89981183a6d0229d177f45
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Sep 28 17:00:23 2013 -0400

    supybot: Make @buildstatus show status for all tasks in the correct channel

 extras/supybot/GNOMEOSTree/plugin.py |   55 +++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 20 deletions(-)
---
diff --git a/extras/supybot/GNOMEOSTree/plugin.py b/extras/supybot/GNOMEOSTree/plugin.py
index 5543dd2..c71ddf6 100644
--- a/extras/supybot/GNOMEOSTree/plugin.py
+++ b/extras/supybot/GNOMEOSTree/plugin.py
@@ -28,6 +28,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 ###
 
+import itertools
 import os
 import json
 
@@ -57,35 +58,25 @@ class GNOMEOSTree(callbacks.Plugin):
         for channel in channels:
             self._irc.queueMsg(ircmsgs.privmsg(channel, msg))
 
-    def _query_new_tasks(self, status=False):
+    def _query_new_tasks(self):
         self._periodic_announce_ticks += 1
         for taskname in self._always_announce_tasks:
-            self._query_new_task(taskname, status=status, announce_success=True)
+            self._query_new_task(taskname, announce_success=True)
         for taskname in self._announce_failed_tasks:
-            self._query_new_task(taskname, status=status)
+            self._query_new_task(taskname)
         for taskname in self._announce_periodic_tasks:
-            self._query_new_task(taskname, status=status, announce_periodic=True)
+            self._query_new_task(taskname, announce_periodic=True)
 
-    def _update_task_state(self, taskname, status=False):
+    def _get_task_state(self, taskname):
         current_task_path = os.path.join(self._workdir, 'tasks/%s/current' % (taskname, ))
         meta_path = os.path.join(current_task_path, 'meta.json')
         if not os.path.exists(meta_path):
-            if status:
-                self._sendTo(self._flood_channels, "No current %s completed" % (taskname, ))
-            return
+            return None, ""
 
         f = open(meta_path)
         metadata = json.load(f)
         f.close()
 
-        taskver = metadata['taskVersion']
-
-        last_state = self._last_task_state.get(taskname)
-        last_version = last_state['taskVersion'] if last_state else None
-        version_unchanged = taskver == last_version
-        if (not status and version_unchanged):
-            return None
-
         status_path = os.path.join(current_task_path, 'status.txt')
         if os.path.exists(status_path):
             f = open(status_path)
@@ -94,11 +85,27 @@ class GNOMEOSTree(callbacks.Plugin):
         else:
             status_msg = ''
 
+        return metadata, status_msg
+
+    def _update_task_state(self, taskname):
+        metadata, status_msg = self._get_task_state(taskname)
+        if metadata is None:
+            return None
+
         self._last_task_state[taskname] = metadata
-        return (last_state, metadata, status_msg)
 
-    def _query_new_task(self, taskname, status=False, announce_success=False, announce_periodic=False):
-        querystate = self._update_task_state(taskname, status=status)
+        taskver = metadata['taskVersion']
+
+        last_state = self._last_task_state.get(taskname)
+        last_version = last_state['taskVersion'] if last_state else None
+        version_unchanged = taskver == last_version
+        if version_unchanged:
+            return None
+        else:
+            return last_state, metadata, status_msg
+
+    def _query_new_task(self, taskname, announce_success=False, announce_periodic=False):
+        querystate = self._update_task_state(taskname)
         if querystate is None:
             return
         (last_state, new_state, status_msg) = querystate
@@ -124,7 +131,15 @@ class GNOMEOSTree(callbacks.Plugin):
             (announce_periodic and self._periodic_announce_ticks == self._periodic_announce_seconds)):
             self._sendTo(self._status_channels, msg)
 
+    def _buildstatus_for_task(self, taskname):
+        metadata, status_msg = self._get_task_state(taskname)
+        if metadata is None:
+            return "No current %s completed" % (taskname, )
+        else:
+            return status_msg
+
     def buildstatus(self, irc, msg, args):
-        self._query_new_tasks(status=True)
+        for taskname in itertools.chain(self._always_announce_tasks, self._announce_failed_tasks, 
self._announce_periodic_tasks):
+            irc.reply(self._buildstatus_for_task(taskname))
 
 Class = GNOMEOSTree


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