2 # -*- coding: utf-8 -*-
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
24 from select import select
28 print >>sys.stderr, 'Please install python-dbus'
37 print "osd_server.py [options]"
39 print " -h --help print this message"
40 print " -H --host host of the osd server (def: " + host + ")"
41 print " -P --port port of the osd server (def: " + str(port) + ")"
42 print " -t --timeout timeout in seconds (def: " + str(timeout) + ")"
43 print " -l --log log file ('-' logs to stdout)"
48 opts, args = getopt.getopt(sys.argv[1:], "hH:P:l:t:", ["help", "host=", "port=", "log=", 'timeout='])
49 except getopt.GetoptError:
54 if opt in ("-h", "--help"):
57 elif opt in ("-H", "--host"):
59 elif opt in ("-P", "--port"):
61 elif opt in ("-l", "--log"):
63 elif opt in ("-p", "--timeout"):
66 l = socket(AF_INET, SOCK_STREAM)
67 l.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
71 logger = logging.getLogger('osd_server')
72 lformatter = logging.Formatter('%(asctime)s %(message)s')
73 if logfile_name not in ('', '-'):
74 lfh = logging.FileHandler(logfile_name)
75 lfh.setFormatter(lformatter)
76 logger.addHandler(lfh)
78 lout = logging.StreamHandler(sys.stdout)
79 lout.setFormatter(lformatter)
80 logger.addHandler(lout)
81 logger.setLevel(logging.INFO)
83 logger.info("osd_server running on [%s] port [%d]" % (host, port))
85 bus = dbus.SessionBus()
86 devobj = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
87 notify = dbus.Interface(devobj, 'org.freedesktop.Notifications')
90 (con, addr) = l.accept()
91 message = con.recv(60).strip()
94 message = message.splitlines()
96 body = ' '.join([m for m in message[1:]])
97 notify.Notify('', 0, '', message[0], body, '', [], timeout*1000)