From 19167ca3be601695db408d04edf1177c01ddde0f Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Thu, 1 Dec 2016 20:46:33 +0200 Subject: [PATCH] Don't fail the build if sending the IRC notification fails --- utils/appveyor/irc-notify.py | 63 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/utils/appveyor/irc-notify.py b/utils/appveyor/irc-notify.py index 417aaa383539..309d55482530 100644 --- a/utils/appveyor/irc-notify.py +++ b/utils/appveyor/irc-notify.py @@ -129,32 +129,37 @@ def appveyor_vars(): irc_username = 'Appveyor' irc_nick = irc_username + str(random.randint(1, 9999)) - # establish connection - irc_sock = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) - irc_sock.connect((socket.gethostbyname('chat.freenode.net'), 6697)) - irc_sock.send('NICK {0}\r\nUSER {0} * 0 :{0}\r\n'.format(irc_username).encode()) - irc_file = irc_sock.makefile() - - while irc_file: - line = irc_file.readline() - print(line.rstrip()) - response = line.split() - - if response[0] == 'PING': - irc_file.send('PONG {}\r\n'.format(reponse[1]).encode()) - - elif response[1] == '433': - irc_sock.send('NICK {}\r\n'.format(irc_nick).encode()) - - elif response[1] == '001': - time.sleep(5) - # join the channel - irc_sock.send('JOIN #{}\r\n'.format(channel).encode()) - # send messages - for msg in messages: - print('PRIVMSG #{} :{}'.format(channel, msg)) - irc_sock.send('PRIVMSG #{} :{}\r\n'.format(channel, msg).encode()) - time.sleep(5) - # leave the channel - irc_sock.send('PART #{}\r\n'.format(channel).encode()) - sys.exit() + try: + # establish connection + irc_sock = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) + irc_sock.connect((socket.gethostbyname('chat.freenode.net'), 6697)) + irc_sock.send('NICK {0}\r\nUSER {0} * 0 :{0}\r\n'.format(irc_username).encode()) + irc_file = irc_sock.makefile() + + while irc_file: + line = irc_file.readline() + print(line.rstrip()) + response = line.split() + + if response[0] == 'PING': + irc_file.send('PONG {}\r\n'.format(reponse[1]).encode()) + + elif response[1] == '433': + irc_sock.send('NICK {}\r\n'.format(irc_nick).encode()) + + elif response[1] == '001': + time.sleep(5) + # join the channel + irc_sock.send('JOIN #{}\r\n'.format(channel).encode()) + # send messages + for msg in messages: + print('PRIVMSG #{} :{}'.format(channel, msg)) + irc_sock.send('PRIVMSG #{} :{}\r\n'.format(channel, msg).encode()) + time.sleep(5) + # leave the channel + irc_sock.send('PART #{}\r\n'.format(channel).encode()) + sys.exit() + except: + e = sys.exc_info()[0] + print(e) + sys.exit()