Get usernmae form getlogin, $LOGNAME, $USER, $LNAME and $USERNAME.
[platform/upstream/ibus.git] / ibus / common.py
1 # vim:set et sts=4 sw=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
11 #
12 # This library 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 Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA  02111-1307  USA
21
22 __all__ = (
23         "IBUS_ADDR",
24         "IBUS_IFACE",
25         "IBUS_NAME",
26         "IBUS_PATH",
27         "IBUS_CONFIG_IFACE",
28         "IBUS_ENGINE_FACTORY_IFACE",
29         "IBUS_ENGINE_IFACE",
30         "IBUS_PANEL_IFACE",
31         "default_reply_handler",
32         "default_error_handler",
33         "DEFAULT_ASYNC_HANDLERS"
34     )
35
36 import os
37 import sys
38
39 display = os.environ["DISPLAY"]
40 if "." not in display:
41     display += ".0" 
42
43 __username = os.getlogin()
44 if not __username:
45     __username = os.getenv ("LOGNAME")
46 if not __username:
47     __username = os.getenv ("USER")
48 if not __username:
49     __username = os.getenv ("LNAME")
50 if not __username:
51     __username = os.getenv ("USERNAME")
52 IBUS_ADDR = "unix:path=/tmp/ibus-%s/ibus-%s" % (__username, display.replace(":", "-"))
53 # IBUS_ADDR  = "tcp:host=localhost,port=7799"
54
55 IBUS_IFACE = "org.freedesktop.IBus"
56 IBUS_PATH  = "/org/freedesktop/IBus"
57 IBUS_NAME  = "org.freedesktop.IBus"
58
59 IBUS_CONFIG_IFACE = "org.freedesktop.IBus.Config"
60 IBUS_ENGINE_FACTORY_IFACE = "org.freedesktop.IBus.EngineFactory"
61 IBUS_ENGINE_IFACE = "org.freedesktop.IBus.Engine"
62 IBUS_PANEL_IFACE = "org.freedesktop.IBus.Panel"
63
64 def default_reply_handler( *args):
65     pass
66
67 def default_error_handler(e):
68     print >> sys.stderr, e
69
70 DEFAULT_ASYNC_HANDLERS = {
71     "reply_handler" : default_reply_handler,
72     "error_handler" : default_error_handler
73 }