Implement a sugar-launch command. Works like the old sugar-activity

but should deal fine with native activities too.
master
Marco Pesenti Gritti 17 years ago
parent 6073a396b3
commit c2982f2774

@ -4,7 +4,8 @@ sugar_SCRIPTS = sugar-activity-factory
bin_SCRIPTS = \
sugar \
sugar-activity \
sugar-install-bundle
sugar-install-bundle \
sugar-launch
EXTRA_DIST = \
$(bin_SCRIPTS) \

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (C) 2006, Red Hat, Inc.
# Copyright (C) 2007, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -16,14 +16,26 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
import sys
from optparse import OptionParser
import pygtk
pygtk.require('2.0')
import gtk
from sugar.activity import activityfactory
from sugar.activity.registry import get_registry
from sugar.activity import activityfactoryservice
usage = "usage: %prog [options] activity"
parser = OptionParser(usage)
(options, args) = parser.parse_args()
activityfactoryservice.run_with_args(sys.argv)
if len(args) == 0:
print 'You need to specify the activity name or part of it.'
sys.exit(1)
gtk.main()
registry = get_registry()
activities = registry.find_activity(args[0])
if len(activities) == 0:
print 'Activity not found.'
activity = activities[0]
args = activityfactory.get_command(activity).split(' ')
os.execvpe(args[0], args, activityfactory.get_environment(activity))

@ -77,6 +77,30 @@ def create_activity_id():
return act_id
raise RuntimeError("Cannot generate unique activity id.")
def get_environment(activity):
environ = os.environ.copy()
bin_path = os.path.join(activity.path, 'bin')
environ['SUGAR_BUNDLE_PATH'] = activity.path
environ['PATH'] = bin_path + ':' + environ['PATH']
return environ
def get_command(activity, activity_id=None, object_id=None, uri=None):
if not activity_id:
activity_id = create_activity_id()
command = activity.command
command += ' -b %s' % activity.bundle_id
command += ' -a %s' % activity_id
if object_id is not None:
command += ' -o %s' % object_id
if uri is not None:
command += ' -u %s' % uri
return command
class ActivityCreationHandler(gobject.GObject):
"""Sugar-side activity creation interface
@ -151,21 +175,11 @@ class ActivityCreationHandler(gobject.GObject):
activity_registry = registry.get_registry()
activity = activity_registry.get_activity(self._service_name)
if activity:
bin_path = os.path.join(activity.path, 'bin')
env = os.environ.copy()
env['SUGAR_BUNDLE_PATH'] = activity.path
env['PATH'] = bin_path + ':' + env['PATH']
command = activity.command
command += ' -b %s' % activity.bundle_id
if self._handle.activity_id is not None:
command += ' -a %s' % self._handle.activity_id
if self._handle.object_id is not None:
command += ' -o %s' % self._handle.object_id
if self._handle.uri is not None:
command += ' -u %s' % self._handle.uri
env = get_environment(activity)
command = get_command(activity,
self._handle.activity_id,
self._handle.object_id,
self._handle.uri)
process = subprocess.Popen(command, env=env, shell=True,
cwd=activity.path)
else:

Loading…
Cancel
Save