[Sugar-devel] Sugar-devel Digest, Vol 78, Issue 29
Tony Anderson
tony_anderson at usa.net
Tue Apr 21 01:15:33 EDT 2015
Hi, James
The utility sugar-launch can easily be executed in python by subprocess.
I have attached the version I use which enables the -o option to allow
specification of the Activity and the resume (can be by uri or by
Journal object).
This is a general utility and should work with any launchable activity
or resumable data file.
Tony
On 04/20/2015 06:00 PM, sugar-devel-request at lists.sugarlabs.org wrote:
> Message: 1
> Date: Mon, 20 Apr 2015 16:47:57 +1000
> From: James Cameron<quozl at laptop.org>
> To: "Sam P."<sam.parkinson3 at gmail.com>
> Cc:sugar-devel at lists.sugarlabs.org
> Subject: Re: [Sugar-devel] [Feature] Start an activity from another
> activity
> Message-ID:<20150420064757.GJ1099 at us.netrek.org>
> Content-Type: text/plain; charset=iso-8859-1
>
> Thanks.
>
> What you describe sounds like activating a journal entry, which causes
> the default activity to be started.
>
> I think I'd like to hear from activity authors who would use the
> feature.
>
> For example, download completion in Browse; at the moment it offers
> "show in journal", but could be "open".
>
> Dependencies are still a concern though; how should Sugar react if
> there is no activity capable of opening an object of an unusual mime
> type?
-------------- next part --------------
#!/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
import dbus
from optparse import OptionParser
from sugar.activity import activityfactory
from sugar.bundle.activitybundle import ActivityBundle
usage = "usage: %prog [options] activity"
parser = OptionParser(usage)
parser.add_option("-d", "--debug", action="store_true", dest="debug",
help="launch activity inside gdb")
parser.add_option("-o","--object_id",action="store_true",dest="object_id",
help="resume activity with object")
parser.add_option("-u","--object_uri",action="store_true",dest="object_uri",
help="path to file")
(options, args) = parser.parse_args()
if len(args) == 0:
print 'You need to specify the activity bundle_id.'
sys.exit(1)
bus = dbus.SessionBus()
proxy = bus.get_object('org.laptop.Shell', '/org/laptop/Shell')
path = dbus.Interface(proxy, 'org.laptop.Shell').GetBundlePath(args[0])
if not path:
print 'Cannot find %s bundle.' % args[0]
sys.exit(1)
activity = ActivityBundle(path)
cmd_args = activityfactory.get_command(activity)
def _which(exec_file):
if 'PATH' in os.environ:
envpath = os.environ['PATH']
else:
return None
for path in envpath.split(os.pathsep):
fullname = os.path.join(path, exec_file)
if os.path.exists(fullname):
return fullname
return None
def _get_interpreter(exec_file):
if os.path.exists(exec_file):
abs_path = exec_file
else:
abs_path = _which(exec_file)
if not abs_path:
return exec_file
f = open(abs_path)
line = f.readline(100)
if line.startswith('#!'):
cmds = line[2:].strip().split(' ')
cmds.append(abs_path)
if '/usr/bin/env' in cmds:
cmds.remove('/usr/bin/env')
return cmds
return exec_file
if options.debug:
act_args = cmd_args
cmd_args = ['gdb', '--args']
cmd_args.extend(_get_interpreter(act_args.pop(0)))
cmd_args.extend(act_args)
if options.object_id:
cmd_args.append("-o")
cmd_args.append(args[1])
if options.object_uri:
cmd_args.append("-u")
cmd_args.append(args[1])
os.chdir(str(activity.get_path()))
os.execvpe(cmd_args[0], cmd_args, activityfactory.get_environment(activity))
More information about the Sugar-devel
mailing list