diff --git a/retaliation.py b/retaliation.py index 763c829..3112cab 100755 --- a/retaliation.py +++ b/retaliation.py @@ -79,6 +79,7 @@ import json import urllib2 import base64 +import os import usb.core import usb.util @@ -93,6 +94,14 @@ # is milli-seconds. The number after "fire" denotes the number of rockets # to shoot. # +ALIAS = { + "will.external" : "will", + "will" : "will", + "tom_personal" : "tom", + "tom" : "tom", + "chris" : "chris" +} + COMMAND_SETS = { "will" : ( ("zero", 0), # Zero/Park to know point (bottom-left) @@ -264,16 +273,11 @@ def run_command_set(commands): def jenkins_target_user(user): - match = False - # Not efficient but our user list is probably less than 1k. # Do a case insenstive search for convenience. - for key in COMMAND_SETS: - if key.lower() == user.lower(): + if ALIAS.get(user.lower()) != None: # We have a command set that targets our user so got for it! - run_command_set(COMMAND_SETS[key]) - match = True - break - if not match: + run_command_set(COMMAND_SETS[ALIAS.get(user.lower())]) + else: print "WARNING: No target command set defined for user %s" % user @@ -311,6 +315,14 @@ def jenkins_wait_for_event(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', JENKINS_NOTIFICATION_UDP_PORT)) + #In Ubuntu/Mint you need to install mplayer and chmod u+x speech.sh + speech = os.path.dirname(os.path.realpath(__file__)) + "/speech.sh " + volume = '10 ' # up to 50 + voice = 'en ' #Google's API is not documented however some local codes (i.e. en_GB) seem to work just fine. + message = " you broke the build it's time for retaliation" + #change to True if you want to hear the voice! + skynet_voice = False + while True: data, addr = sock.recvfrom(8 * 1024) try: @@ -321,9 +333,12 @@ def jenkins_wait_for_event(): target = jenkins_get_responsible_user(notification_data["name"]) if target == None: print "WARNING: Could not identify the user who broke the build!" - continue - + continue print "Build Failed! Targeting user: " + target + #printing is nice but an Skynet voice is more menacing! + if skynet_voice: + #TODO: change this to Popen to do it async. + os.system(speech + volume + voice + target + message) jenkins_target_user(target) except: pass @@ -356,4 +371,4 @@ def main(args): if __name__ == '__main__': - main(sys.argv) + main(sys.argv) \ No newline at end of file diff --git a/speech.sh b/speech.sh new file mode 100755 index 0000000..f613b3c --- /dev/null +++ b/speech.sh @@ -0,0 +1,7 @@ +#!/bin/bash +#Taken from http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis) +say() { +SP=${@:3}; +echo $SP +local IFS=+;/usr/bin/mplayer -af volume=$1 -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?tl=$2&q=$SP"; } +say $* \ No newline at end of file