94 строки
2.1 KiB
Python
94 строки
2.1 KiB
Python
#!/usr/bin/env python
|
|
#
|
|
# ibus - The Input Bus
|
|
#
|
|
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
|
|
#
|
|
# This library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2 of the License, or (at your option) any later version.
|
|
#
|
|
# This library 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 Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser 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
|
|
|
|
import os
|
|
import os.path
|
|
import sys
|
|
import time
|
|
import ibus
|
|
|
|
daemon = "@prefix@/libexec/ibus-daemon"
|
|
x11 = "@prefix@/libexec/ibus-x11"
|
|
panel = "@prefix@/libexec/ibus-panel"
|
|
conf = "@prefix@/libexec/ibus-gconf"
|
|
|
|
daemon_pid = 0
|
|
|
|
# logname = os.path.expanduser("~/.ibus-error")
|
|
# os.close(0)
|
|
# os.close(1)
|
|
# os.close(2)
|
|
# try:
|
|
# os.unlink(logname)
|
|
# except:
|
|
# pass
|
|
# fd = os.open(logname, os.O_CREAT | os.O_WRONLY)
|
|
# os.dup2(fd, 1)
|
|
# os.dup2(fd, 2)
|
|
bus = None
|
|
|
|
try:
|
|
bus = ibus.Bus()
|
|
except:
|
|
pass
|
|
if bus:
|
|
print >> sys.stderr, "Found an ibus-daemon has been started!"
|
|
sys.exit(1)
|
|
|
|
try:
|
|
print "start ibus-daemon"
|
|
daemon_pid = os.spawnv (os.P_NOWAIT, daemon, [daemon])
|
|
except:
|
|
print >> sys.stderr, "start ibus-daemon failed"
|
|
sys.exit (1)
|
|
|
|
time.sleep (1)
|
|
|
|
try:
|
|
print "start ibus-x11"
|
|
os.spawnv (os.P_NOWAIT, x11, [x11, "--kill-daemon"])
|
|
except:
|
|
print >> sys.stderr, "start ibus-x11 failed"
|
|
sys.exit (1)
|
|
|
|
try:
|
|
print "start ibus-panel"
|
|
os.spawnv (os.P_NOWAIT, panel, [panel])
|
|
except:
|
|
print >> sys.stderr, "start ibus-panel failed"
|
|
sys.exit (1)
|
|
|
|
# try:
|
|
# print "start ibus-conf"
|
|
# os.spawnv (os.P_NOWAIT, conf, [conf])
|
|
# except:
|
|
# print >> sys.stderr, "start ibus-conf failed"
|
|
# sys.exit (1)
|
|
|
|
try:
|
|
os.kill (daemon_pid, 0)
|
|
except:
|
|
sys.exit (1)
|
|
|
|
os.waitpid (daemon_pid, 0)
|
|
|
|
os.wait ()
|