[gnome-continuous] bot: Format the task time a bit more human-friendly



commit 434bd7ad57bd9577fa5813cd221a565292157690
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 20 15:31:03 2017 +0100

    bot: Format the task time a bit more human-friendly
    
    Don't use raw seconds, but split it into hours, minutes, and seconds
    where appropriate.

 extras/ircbot/bot.py |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/extras/ircbot/bot.py b/extras/ircbot/bot.py
index 08955ba..76a231e 100644
--- a/extras/ircbot/bot.py
+++ b/extras/ircbot/bot.py
@@ -47,6 +47,14 @@ def mirc_color(code, S):
 GREEN = 3
 RED = 4
 
+def human_time(secs):
+    if secs < 60:
+        return '{}s'.format(secs)
+    elif secs < 3600:
+        return '{}m:{}s'.format(int(secs / 60), secs % 60)
+    else:
+        return '{}h:{}m:{}s'.format(int(secs / 3600), int(secs / 60) % 60, secs % 60)
+
 class BuildGnomeOrg(irc.IRCClient):
     nickname = 'buildgnomeorg'
     username = nickname
@@ -142,8 +150,8 @@ class BuildGnomeOrg(irc.IRCClient):
         success = metadata['success']
         success_str = success and mirc_color(GREEN, 'SUCCESS') or mirc_color(RED, 'FAILED')
 
-        msg = u"continuous:%s[%s]: %s: (%.1f seconds): %s " \
-              % (taskname, build_name, success_str, millis / 1000.0, status_msg)
+        msg = u"continuous:%s[%s]: %s: (%s): %s " \
+              % (taskname, build_name, success_str, human_time(millis / 1000.0), status_msg)
 
         msg += "%s/%s/" % (self._workurl, metadata['path'])
 


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