openlp/openlp/plugins/remotes/remoteclient-cli.py

84 lines
3.6 KiB
Python
Raw Normal View History

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 #
# Gorven, Scott Guerrieri, 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
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)
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):
2009-09-21 17:56:36 +00:00
return u'%s:%s' % (options.event, 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]")
parser.add_option("-p", "--port",
default=4316,
help="IP Port number %default ")
parser.add_option("-a", "--address",
help="Recipient address ")
parser.add_option("-e", "--event",
default=u'Alert',
help="Action to be undertaken")
parser.add_option("-m", "--message",
help="Message to be passed for the action")
2009-08-24 05:10:04 +00:00
parser.add_option("-n", "--slidenext",
help="Trigger the next slide")
2009-08-10 18:20:46 +00:00
2009-08-12 16:29:00 +00:00
(options, args) = parser.parse_args()
if len(args) > 0:
parser.print_help()
parser.error("incorrect number of arguments")
elif options.message is None:
parser.print_help()
parser.error("No message passed")
elif options.address is None:
parser.print_help()
parser.error("IP address missing")
2009-11-03 19:01:53 +00:00
elif options.slidenext:
2009-08-24 05:10:04 +00:00
options.event = u'next_slide'
options.message = u''
text = format_message(options)
sendData(options, text)
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()