Implement a sugar-launch command. Works like the old sugar-activity
but should deal fine with native activities too.
This commit is contained in:
parent
6073a396b3
commit
c2982f2774
@ -4,7 +4,8 @@ sugar_SCRIPTS = sugar-activity-factory
|
|||||||
bin_SCRIPTS = \
|
bin_SCRIPTS = \
|
||||||
sugar \
|
sugar \
|
||||||
sugar-activity \
|
sugar-activity \
|
||||||
sugar-install-bundle
|
sugar-install-bundle \
|
||||||
|
sugar-launch
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
$(bin_SCRIPTS) \
|
$(bin_SCRIPTS) \
|
||||||
|
26
bin/sugar-activity-factory → bin/sugar-launch
Executable file → Normal file
26
bin/sugar-activity-factory → bin/sugar-launch
Executable file → Normal file
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/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
|
# 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
|
# 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
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
import pygtk
|
from sugar.activity import activityfactory
|
||||||
pygtk.require('2.0')
|
from sugar.activity.registry import get_registry
|
||||||
import gtk
|
|
||||||
|
|
||||||
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
|
return act_id
|
||||||
raise RuntimeError("Cannot generate unique activity 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):
|
class ActivityCreationHandler(gobject.GObject):
|
||||||
"""Sugar-side activity creation interface
|
"""Sugar-side activity creation interface
|
||||||
|
|
||||||
@ -151,21 +175,11 @@ class ActivityCreationHandler(gobject.GObject):
|
|||||||
activity_registry = registry.get_registry()
|
activity_registry = registry.get_registry()
|
||||||
activity = activity_registry.get_activity(self._service_name)
|
activity = activity_registry.get_activity(self._service_name)
|
||||||
if activity:
|
if activity:
|
||||||
bin_path = os.path.join(activity.path, 'bin')
|
env = get_environment(activity)
|
||||||
|
command = get_command(activity,
|
||||||
env = os.environ.copy()
|
self._handle.activity_id,
|
||||||
env['SUGAR_BUNDLE_PATH'] = activity.path
|
self._handle.object_id,
|
||||||
env['PATH'] = bin_path + ':' + env['PATH']
|
self._handle.uri)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
process = subprocess.Popen(command, env=env, shell=True,
|
process = subprocess.Popen(command, env=env, shell=True,
|
||||||
cwd=activity.path)
|
cwd=activity.path)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user