From fe45f2a342a35c4b9684a1e1d76acd4ac96253a5 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 11 Mar 2015 19:56:12 +0100 Subject: [PATCH] prscript: add notification system If Python pynotify is installed, prscript can now send notification via the -n flag. --- qa/prscript.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/qa/prscript.py b/qa/prscript.py index 76b8b4f5bf..e7c5118261 100755 --- a/qa/prscript.py +++ b/qa/prscript.py @@ -31,6 +31,12 @@ import sys import os import copy +GOT_NOTIFY = True +try: + import pynotify +except: + GOT_NOTIFY = False + GOT_DOCKER = True try: from docker import Client @@ -53,6 +59,8 @@ parser.add_argument('--norebase', action='store_const', const=True, help='do not parser.add_argument('-r', '--repository', dest='repository', default='suricata', help='name of suricata repository on github') parser.add_argument('-d', '--docker', action='store_const', const=True, help='use docker based testing', default=False) parser.add_argument('-l', '--local', action='store_const', const=True, help='local testing before github push', default=False) +if GOT_NOTIFY: + parser.add_argument('-n', '--notify', action='store_const', const=True, help='send desktop notification', default=False) if GOT_DOCKER: parser.add_argument('-C', '--create', action='store_const', const=True, help='create docker container', default=False) parser.add_argument('-s', '--start', action='store_const', const=True, help='start docker container', default=False) @@ -73,6 +81,18 @@ else: BUILDERS_URI=BASE_URI+"builders/" JSON_BUILDERS_URI=BASE_URI+"json/builders/" +if GOT_NOTIFY: + if args.notify: + pynotify.init("PRscript") + +def SendNotification(title, text): + if not GOT_NOTIFY: + return + if not args.notify: + return + n = pynotify.Notification(title, text) + n.show() + def TestRepoSync(branch): request = urllib2.Request(GITHUB_MASTER_URI) page = urllib2.urlopen(request) @@ -272,15 +292,26 @@ if args.docker: if ret == -1: res = -1 up_buildids.pop(build, None) - print "Build failure for " + build + ": " + BUILDERS_URI + build + '/builds/' + str(buildids[build]) + " (remaining builds: " + ', '.join(up_buildids.keys()) + ")" + if len(up_buildids): + remains = " (remaining builds: " + ', '.join(up_buildids.keys()) + ")" + else: + remains = "" + print "Build failure for " + build + ": " + BUILDERS_URI + build + '/builds/' + str(buildids[build]) + remains elif ret == 0: up_buildids.pop(build, None) - print "Build successful for " + build + " (remaining builds: " + ', '.join(up_buildids.keys()) + ")" + if len(up_buildids): + remains = " (remaining builds: " + ', '.join(up_buildids.keys()) + ")" + else: + remains = "" + print "Build successful for " + build + remains time.sleep(5) buildids = up_buildids if res == -1: + SendNotification("PRscript failure", "Some builds have failed. Check waterfall for results.") sys.exit(-1) else: + print "PRscript completed successfully" + SendNotification("PRscript success", "Congrats! All builds have passed.") sys.exit(0) else: for build in buildids: @@ -291,6 +322,8 @@ if res == 0: print "You can copy/paste following lines into github PR" for build in buildids: print "- PR " + build + ": " + BUILDERS_URI + build + "/builds/" + str(buildids[build]) + SendNotification("OISF PRscript success", "Congrats! All builds have passed.") sys.exit(0) else: + SendNotification("OISF PRscript failure", "Some builds have failed. Check waterfall for results.") sys.exit(-1)