Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/Makefile.am3
-rwxr-xr-xbin/sugar-activity-factory29
-rw-r--r--bin/sugar-launch41
-rw-r--r--sugar/activity/activityfactory.py44
4 files changed, 72 insertions, 45 deletions
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 69efe43..94d7cc0 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -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) \
diff --git a/bin/sugar-activity-factory b/bin/sugar-activity-factory
deleted file mode 100755
index a144f34..0000000
--- a/bin/sugar-activity-factory
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (C) 2006, 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
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-import sys
-
-import pygtk
-pygtk.require('2.0')
-import gtk
-
-from sugar.activity import activityfactoryservice
-
-activityfactoryservice.run_with_args(sys.argv)
-
-gtk.main()
diff --git a/bin/sugar-launch b/bin/sugar-launch
new file mode 100644
index 0000000..6cb53e1
--- /dev/null
+++ b/bin/sugar-launch
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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
+
+from sugar.activity import activityfactory
+from sugar.activity.registry import get_registry
+
+usage = "usage: %prog [options] activity"
+parser = OptionParser(usage)
+(options, args) = parser.parse_args()
+
+if len(args) == 0:
+ print 'You need to specify the activity name or part of it.'
+ sys.exit(1)
+
+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))
diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py
index d5936e9..addaf95 100644
--- a/sugar/activity/activityfactory.py
+++ b/sugar/activity/activityfactory.py
@@ -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: