Esempio n. 1
0
def _main():
    """Launch this activity from the command line."""
    from sugar.activity import activityfactory
    from sugar.activity.registry import ActivityInfo
    from sugar.bundle.activitybundle import ActivityBundle
    import os
    ab = ActivityBundle(os.path.dirname(__file__) or '.')
    ai = ActivityInfo(name=ab.get_name(),
                      icon=None,
                      bundle_id=ab.get_bundle_id(),
                      version=ab.get_activity_version(),
                      path=ab.get_path(),
                      show_launcher=ab.get_show_launcher(),
                      command=ab.get_command(),
                      favorite=True,
                      installation_time=ab.get_installation_time(),
                      position_x=0, position_y=0)
    env = activityfactory.get_environment(ai)
    cmd_args = activityfactory.get_command(ai)
    os.execvpe(cmd_args[0], cmd_args, env)
#set up python module search path
sys.path.insert(0,child_path)
bundle_info = ActivityBundle(child_path)
bundle_id = bundle_info.get_bundle_id()

#following two statements eliminate differences between sugar 0.82 and 0.84
bundle_info.path = child_path
bundle_info.bundle_id = bundle_id

bundle_name = bundle_info.get_name()
os.environ['SUGAR_BUNDLE_NAME'] = bundle_name
os.environ['SUGAR_BUNDLE_ID'] = bundle_id

if version and version >= 0.839:
    #do 0.84 stuff
    cmd_args = activityfactory.get_command(bundle_info)
else:
    from sugar.activity.registry import get_registry
    registry = get_registry()
    registry.add_bundle(child_path)
    activity_list = registry.find_activity(bundle_id)
    if len(activity_list) == 0:
        _logger.error('Activity %s not found'%bundle_id)
        print 'Activity %s not found'%bundle_id
        exit(1)
    cmd_args = activityfactory.get_command(activity_list[0])
    myprofile = profile.get_profile()
    myprofile.color = XoColor()
_logger.debug('command args:%r'%cmd_args)
    
go_cmd = 'run -d -b %s %s' % (os.path.join(db.pydebug_path, 'bin',
                                           'start_debug.py'), child_path)
_logger.debug('defining go: %s' % go_cmd)
ip.user_ns['go'] = go_cmd
_logger.debug('pydebug home: %s' % db.debugger_home)
path = child_path
pydebug_home = db.debugger_home
os.environ['PYDEBUG_HOME'] = pydebug_home
os.chdir(path)
os.environ['SUGAR_BUNDLE_PATH'] = path
_logger.debug('sugar_bundle_path set to %s' % path)

#set up module search path
sys.path.insert(0, path)
activity = ActivityBundle(path)
cmd_args = activityfactory.get_command(activity)
_logger.debug('command args:%r' % cmd_args)
bundle_name = activity.get_name()
bundle_id = activity.get_bundle_id()

#need to get activity root, but activity bases off of HOME which some applications need to change
#following will not work if storage system changes with new OS
#required because debugger needs to be able to change home so that foreign apps will work
activity_root = os.path.join('/home/olpc/.sugar/default/', bundle_id)
os.environ['SUGAR_ACTIVITY_ROOT'] = activity_root
_logger.debug('sugar_activity_root set to %s' % activity_root)

#following is useful for its side-effects
info = activityfactory.get_environment(activity)

_logger.debug("Command to execute:%s." % cmd_args[0])