2006-05-12 08:34:20 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
2006-06-16 21:48:44 +02:00
|
|
|
import pwd
|
|
|
|
import random
|
2006-05-12 08:34:20 +02:00
|
|
|
|
2006-05-23 04:40:49 +02:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gobject
|
2006-05-16 22:52:54 +02:00
|
|
|
|
2006-06-21 22:35:57 +02:00
|
|
|
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
|
|
|
|
|
2006-05-23 04:40:49 +02:00
|
|
|
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
|
|
|
|
|
2006-06-16 21:48:44 +02:00
|
|
|
if not os.environ.has_key("SUGAR_NICK_NAME"):
|
|
|
|
nick = pwd.getpwuid(os.getuid())[0]
|
|
|
|
if not nick or not len(nick):
|
|
|
|
nick = "Guest %d" % random.randint(1, 10000)
|
|
|
|
os.environ['SUGAR_NICK_NAME'] = nick
|
|
|
|
os.environ['SUGAR_USER_DIR'] = os.path.expanduser('~/.sugar')
|
|
|
|
|
2006-05-17 06:12:01 +02:00
|
|
|
|
2006-06-21 20:23:18 +02:00
|
|
|
curdir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
basedir = os.path.dirname(curdir)
|
|
|
|
|
|
|
|
if os.path.isfile(os.path.join(basedir, 'sugar/__uninstalled__.py')):
|
|
|
|
print 'Running sugar from ' + basedir + ' ...'
|
2006-06-21 22:35:57 +02:00
|
|
|
add_to_python_path(basedir)
|
|
|
|
add_to_python_path(os.path.join(basedir, 'shell'))
|
2006-05-12 08:34:20 +02:00
|
|
|
else:
|
2006-06-21 22:35:57 +02:00
|
|
|
import sugar.env
|
|
|
|
add_to_python_path(os.path.join(sugar.env.get_data_dir(), 'shell'))
|
2006-05-17 06:12:01 +02:00
|
|
|
print 'Running the installed sugar...'
|
2006-05-18 07:17:40 +02:00
|
|
|
|
2006-06-23 19:09:58 +02:00
|
|
|
print 'Redirecting output to the console, press Ctrl+Down to open it.'
|
2006-05-16 22:32:08 +02:00
|
|
|
|
2006-06-21 20:23:18 +02:00
|
|
|
from session.session import Session
|
2006-05-16 22:32:08 +02:00
|
|
|
|
2006-06-20 04:39:57 +02:00
|
|
|
session = Session()
|
2006-05-23 22:02:13 +02:00
|
|
|
session.start()
|
2006-05-23 04:40:49 +02:00
|
|
|
|
|
|
|
if dbus_daemon_pid:
|
|
|
|
stop_dbus(dbus_daemon_pid)
|