[kupfer: 24/67] Use OperationError to give real feedback for launch error
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 24/67] Use OperationError to give real feedback for launch error
- Date: Sat, 19 Mar 2011 00:59:45 +0000 (UTC)
commit 46dcee54005b08f18def2662b72c3b10d7adf9cf
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Tue Mar 15 22:52:30 2011 +0100
Use OperationError to give real feedback for launch error
Use OperationError to show a notification on launch error (for example
'Failed to execute child process "testme" (No such file or directory)'
kupfer/desktop_launch.py | 12 ++++++++++--
kupfer/launch.py | 13 ++++++++++---
kupfer/obj/objects.py | 13 ++++++++-----
3 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/kupfer/desktop_launch.py b/kupfer/desktop_launch.py
index 5d4feed..6df1a5b 100644
--- a/kupfer/desktop_launch.py
+++ b/kupfer/desktop_launch.py
@@ -31,6 +31,9 @@ def error_log(*args):
def exc_log():
pretty.print_exc(__name__)
+class SpawnError (Exception):
+ "Error starting application"
+
class ResourceLookupError (Exception):
"Unable to find resource"
@@ -73,6 +76,8 @@ def read_desktop_info(desktop_file):
de = xdg.DesktopEntry.DesktopEntry(desktop_file)
except xdg.Exceptions.Error:
raise ResourceReadError
+ if not de.getExec():
+ raise ResourceReadError("Invalid data: empty Exec key")
return {
"Terminal": de.getTerminal(),
"StartupNotify": de.getStartupNotify(),
@@ -256,6 +261,8 @@ def launch_app_info(app_info, gfiles=[], in_terminal=None, timestamp=None,
@desktop_file: specify location of desktop file
@launch_cb: Called once per launched process,
like ``spawn_app``
+
+ Will pass on exceptions from spawn_app
"""
desktop_file = desktop_file or _file_for_app_info(app_info)
desktop_info = _info_for_desktop_file(desktop_file)
@@ -338,7 +345,8 @@ def spawn_app(app_info, argv, filelist, workdir=None, startup_notify=True,
@launch_cb: Called if successful with
(argv, pid, notify_id, filelist, timestamp)
- return PID on success, else None
+ return pid if successful
+ raise SpawnError on error
"""
notify_id = None
if startup_notify:
@@ -369,7 +377,7 @@ def spawn_app(app_info, argv, filelist, workdir=None, startup_notify=True,
error_log("Error Launching ", argv, unicode(exc))
if notify_id:
gtk.gdk.notify_startup_complete_with_id(notify_id)
- return None
+ raise SpawnError(unicode(exc))
if launch_cb:
launch_cb(argv, pid, notify_id, filelist, timestamp)
return pid
diff --git a/kupfer/launch.py b/kupfer/launch.py
index f2edfa2..bc2b9d1 100644
--- a/kupfer/launch.py
+++ b/kupfer/launch.py
@@ -17,6 +17,10 @@ except ImportError, e:
pretty.print_info(__name__, "Disabling window tracking:", e)
wnck = None
+class LaunchError (Exception):
+ "Error launching application"
+
+
default_associations = {
"evince" : "Document Viewer",
"file-roller" : "File Roller",
@@ -51,6 +55,8 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True,
if @activate, activate rather than start a new version
@app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple
+
+ Raises LaunchError on failed program start.
"""
assert app_info
@@ -82,11 +88,12 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True,
else:
launch_callback = None
- ret = desktop_launch.launch_app_info(app_info, files,
+ try:
+ desktop_launch.launch_app_info(app_info, files,
timestamp=_current_event_time(), desktop_file=desktop_file,
launch_cb=launch_callback)
- if not ret:
- pretty.print_info(__name__, "Error launching", app_info)
+ except desktop_launch.SpawnError as exc:
+ raise LaunchError(unicode(exc))
return True
def application_is_running(app_id):
diff --git a/kupfer/obj/objects.py b/kupfer/obj/objects.py
index 29f53a1..2184a57 100644
--- a/kupfer/obj/objects.py
+++ b/kupfer/obj/objects.py
@@ -15,7 +15,8 @@ import gobject
from kupfer import icons, launch, utils
from kupfer import pretty
-from kupfer.obj.base import Leaf, Action, Source, InvalidDataError
+from kupfer.obj.base import Leaf, Action, Source
+from kupfer.obj.base import InvalidDataError, OperationError
from kupfer.obj import fileactions
from kupfer.interface import TextRepresentation
from kupfer.kupferstring import tounicode
@@ -226,10 +227,12 @@ class AppLeaf (Leaf):
@paths: a seq of bytestring paths
@activate: activate instead of start new
"""
- return launch.launch_application(self.object, files=files, paths=paths,
- activate=activate,
- desktop_file=self.init_path)
-
+ try:
+ return launch.launch_application(self.object, files=files,
+ paths=paths, activate=activate,
+ desktop_file=self.init_path)
+ except launch.LaunchError as exc:
+ raise OperationError(unicode(exc))
def get_id(self):
"""Return the unique ID for this app.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]