diff --git a/src/sugar3/activity/activityfactory.py b/src/sugar3/activity/activityfactory.py index 1d1eae267..a59d94e59 100644 --- a/src/sugar3/activity/activityfactory.py +++ b/src/sugar3/activity/activityfactory.py @@ -37,6 +37,8 @@ import os import subprocess + + _SHELL_SERVICE = 'org.laptop.Shell' _SHELL_PATH = '/org/laptop/Shell' _SHELL_IFACE = 'org.laptop.Shell' @@ -217,25 +219,59 @@ def _create_activity(self): self._service_name, self._handle.activity_id, reply_handler=self._no_reply_handler, error_handler=self._notify_launch_error_handler) - + environ = get_environment(self._bundle) (log_path, log_file) = open_log_file(self._bundle) command = get_command(self._bundle, self._handle.activity_id, self._handle.object_id, self._handle.uri, self._handle.invited) - dev_null = open('/dev/null', 'r') - child = subprocess.Popen([str(s) for s in command], - env=environ, - cwd=str(self._bundle.get_path()), - close_fds=True, - stdin=dev_null.fileno(), - stdout=log_file.fileno(), - stderr=log_file.fileno()) - - GLib.child_watch_add(child.pid, - _child_watch_cb, - (log_file, self._handle.activity_id)) + try: + dev_null = open('/dev/null', 'r') + child = subprocess.Popen([str(s) for s in command], + env=environ, + cwd=str(self._bundle.get_path()), + close_fds=True, + stdin=dev_null.fileno(), + stdout=log_file.fileno(), + stderr=log_file.fileno()) + + GLib.child_watch_add(child.pid, + _child_watch_cb, + (log_file, self._handle.activity_id)) + + except FileNotFoundError as e: + if 'sugar-activity' in str(e): + log_file.write('Activity written for Python 2, needs to be ported to Python 3\n') + log_file.close() + + from jarabe.model import shell + shell_model = shell.get_model() + + if not hasattr(shell_model, '_python2_activity_check'): + shell_model._python2_activity_check = set() + shell_model._python2_activity_check.add(self._handle.activity_id) + + bus = dbus.SessionBus() + bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH) + shell = dbus.Interface(bus_object, _SHELL_IFACE) + + shell.NotifyLaunchFailure( + self._handle.activity_id, + reply_handler=self._no_reply_handler, + error_handler=self._notify_launch_failure_error_handler) + + except Exception as e: + logging.error('Activity launch failed with error: %s', str(e)) + + bus = dbus.SessionBus() + bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH) + shell = dbus.Interface(bus_object, _SHELL_IFACE) + + shell.NotifyLaunchFailure( + self._handle.activity_id, + reply_handler=self._no_reply_handler, + error_handler=self._notify_launch_failure_error_handler) def _no_reply_handler(self, *args): pass @@ -345,4 +381,4 @@ def error_handler_cb(error): # main window, see http://bugs.sugarlabs.org/ticket/1447#comment:19 shell.NotifyLaunchFailure(activity_id, reply_handler=reply_handler_cb, - error_handler=error_handler_cb) + error_handler=error_handler_cb) \ No newline at end of file