sugar-toolkit-gtk3/sugar/sugar
2006-06-14 15:01:17 -04:00

81 lines
1.9 KiB
Python
Executable File

#!/usr/bin/python
import sys
import os
import pygtk
pygtk.require('2.0')
import gobject
def add_to_python_path(path):
sys.path.insert(0, path)
if os.environ.has_key('PYTHONPATH'):
os.environ['PYTHONPATH'] += ':' + path
else:
os.environ['PYTHONPATH'] = path
def start_dbus():
curdir = os.path.dirname(__file__)
args = "/bin/dbus-daemon --session --print-address".split()
(dbus_pid, ign1, dbus_stdout, ign3) = gobject.spawn_async(args, flags=gobject.SPAWN_STDERR_TO_DEV_NULL, standard_output=True)
dbus_file = os.fdopen(dbus_stdout)
addr = dbus_file.readline()
addr = addr.strip()
print "dbus-daemon pid is %d, session bus address is %s" % (dbus_pid, addr)
dbus_file.close()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
return dbus_pid
def stop_dbus(dbus_pid):
try:
print 'Closing dbus-daemon, pid %d' % (dbus_pid)
os.kill(dbus_pid, 9)
except OSError:
pass
i = 0
dbus_daemon_pid = None
for arg in sys.argv:
if arg == '--test-user':
user = sys.argv[i + 1]
user_dir = os.path.expanduser('~/.sugar-' + user)
os.environ['SUGAR_NICK_NAME'] = user
os.environ['SUGAR_USER_DIR'] = user_dir
dbus_daemon_pid = start_dbus()
started_dbus = True
i += 1
curdir = os.path.dirname(__file__)
if curdir == '.':
basedir = os.path.dirname(os.getcwd())
else:
basedir = os.path.dirname(curdir)
console = False
if os.path.isfile(os.path.join(curdir, '__uninstalled__.py')):
if basedir == '':
print 'Running sugar from current directory...'
else:
print 'Running sugar from ' + basedir + ' ...'
add_to_python_path(basedir)
add_to_python_path(os.path.join(basedir, 'cut-n-paste'))
console = True
else:
print 'Running the installed sugar...'
add_to_python_path(os.path.expanduser('~/.sugar/activities'))
if console:
os.environ['SUGAR_USE_CONSOLE'] = 'yes'
print 'Redirecting output to the console, press ctrl+d to open it.'
from sugar.session import session
session.start()
if dbus_daemon_pid:
stop_dbus(dbus_daemon_pid)