#!/usr/bin/python import sys import os import pwd import random def add_to_python_path(path): sys.path.insert(0, path) if os.environ.has_key('PYTHONPATH'): old_path = os.environ['PYTHONPATH'] os.environ['PYTHONPATH'] = path + ':' + old_path else: os.environ['PYTHONPATH'] = path i = 0 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 i += 1 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') 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 + ' ...' add_to_python_path(basedir) add_to_python_path(os.path.join(basedir, 'shell')) else: import sugar.env add_to_python_path(os.path.join(sugar.env.get_data_dir(), 'shell')) print 'Running the installed sugar...' from Emulator import Emulator # FIXE Don't run the emulator on the OLPC emulator = Emulator() emulator.start() print 'Redirecting output to the console, press F3 to open it.' from Session import Session session = Session() session.start()