2 # -*- coding: iso-8859-15 -*-
3 # Copyright (C) 2005 2006 Alexander Bernauer <alex@copton.net>
4 # Copyright (C) 2005 2006 Rico Schiekel <fire@donwgra.de>
5 # Copyright (C) 2005 2006 Ulrich Dangel <uli@spamt.net>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation version 2
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA.
22 import sys, getopt, logging
25 from select import select
29 osdcmd = "/usr/bin/osd_cat"
32 print "osd_server.py [options]"
34 print " -h --help print this message"
35 print " -H --host host of the osd server (def: " + host + ")"
36 print " -P --port port of the osd server (def: " + str(port) + ")"
37 print " -o --osd set new osd parameter string"
38 print " -l --log log file ('-' logs to stdout)"
40 def get_osd_paramstr(def_params, user_params):
43 for n, v in def_params.iteritems():
45 ret += n + "=" + v + " "
50 osd_params={ '--pos': 'middle',
55 '\-\*\-helvetica\-\*\-r\-\*\-\*\-34\-\*\-\*\-\*\-\*\-\*\-iso8859\-15',
60 '--outlinecolour': 'black',
69 opts, args = getopt.getopt(sys.argv[1:], "hH:P:o:l:", ["help", "host=", "port=", "osd=", "log="])
70 except getopt.GetoptError:
75 if opt in ("-h", "--help"):
78 elif opt in ("-H", "--host"):
80 elif opt in ("-P", "--port"):
82 elif opt in ("-o", "--osd"):
84 elif opt in ("-l", "--log"):
87 l = socket(AF_INET, SOCK_STREAM)
88 l.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
92 logger = logging.getLogger('osd_server')
93 lformatter = logging.Formatter('%(asctime)s %(message)s')
94 if logfile_name not in ('', '-'):
95 lfh = logging.FileHandler(logfile_name)
96 lfh.setFormatter(lformatter)
97 logger.addHandler(lfh)
99 lout = logging.StreamHandler(sys.stdout)
100 lout.setFormatter(lformatter)
101 logger.addHandler(lout)
102 logger.setLevel(logging.INFO)
104 logger.info("osd_server running on [%s] port [%d]" % (host, port))
105 osdpipe = popen("%s %s" % (osdcmd, get_osd_paramstr(osd_params, user_osd_params)), 'w')
108 r.extend([ord(umlaut) for umlaut in "äöüßÄÖܤ" ])
111 (con, addr) = l.accept()
112 message = con.recv(60).strip()
115 message = message.replace("\n", "")
116 message = ''.join(map(lambda a: not a in r \
119 [ord(c) for c in message]))[:60]
122 osdpipe.write(message)