2009-08-10 18:20:46 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-10-30 01:26:45 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2009-12-31 12:52:01 +00:00
|
|
|
# Copyright (c) 2008-2010 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
2010-03-21 23:58:01 +00:00
|
|
|
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
|
|
|
|
# Thompson, Jon Tibble, Carsten Tinggaard #
|
2009-10-30 01:26:45 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2009-08-10 18:20:46 +00:00
|
|
|
|
2009-08-12 04:57:24 +00:00
|
|
|
import socket
|
2009-08-12 16:29:00 +00:00
|
|
|
import sys
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
def sendData(options, message):
|
|
|
|
addr = (options.address, options.port)
|
|
|
|
try:
|
|
|
|
UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
|
|
|
UDPSock.sendto(message, addr)
|
2009-09-02 01:44:09 +00:00
|
|
|
print u'message sent ', message, addr
|
2009-08-12 16:29:00 +00:00
|
|
|
except:
|
|
|
|
print u'Errow thrown ', sys.exc_info()[1]
|
|
|
|
|
|
|
|
def format_message(options):
|
2010-04-09 19:15:26 +00:00
|
|
|
return u'%s:%s' % (u'alert', options.message)
|
2009-08-12 16:29:00 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
usage = "usage: %prog [options] arg1 arg2"
|
|
|
|
parser = OptionParser(usage=usage)
|
|
|
|
parser.add_option("-v", "--verbose",
|
|
|
|
action="store_true", dest="verbose", default=True,
|
|
|
|
help="make lots of noise [%default]")
|
2010-02-03 18:53:31 +00:00
|
|
|
parser.add_option("-p", "--port", default=4316,
|
2009-08-12 16:29:00 +00:00
|
|
|
help="IP Port number %default ")
|
|
|
|
parser.add_option("-a", "--address",
|
|
|
|
help="Recipient address ")
|
|
|
|
parser.add_option("-m", "--message",
|
|
|
|
help="Message to be passed for the action")
|
2009-08-10 18:20:46 +00:00
|
|
|
|
2009-08-12 16:29:00 +00:00
|
|
|
(options, args) = parser.parse_args()
|
2010-03-09 19:43:11 +00:00
|
|
|
if args:
|
2009-08-12 16:29:00 +00:00
|
|
|
parser.print_help()
|
|
|
|
parser.error("incorrect number of arguments")
|
|
|
|
elif options.address is None:
|
|
|
|
parser.print_help()
|
|
|
|
parser.error("IP address missing")
|
2010-02-03 18:53:31 +00:00
|
|
|
elif options.message is None:
|
|
|
|
parser.print_help()
|
|
|
|
parser.error("No message passed")
|
2009-08-12 16:29:00 +00:00
|
|
|
else:
|
|
|
|
text = format_message(options)
|
|
|
|
sendData(options, text)
|
2009-08-10 18:20:46 +00:00
|
|
|
|
|
|
|
if __name__ == u'__main__':
|
2009-08-12 16:29:00 +00:00
|
|
|
main()
|