[kupfer] launch: Use SpawnError in all modules



commit 90125ee0f968cdbfa0b61f02c2469b7778c29059
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 21 15:22:38 2011 +0100

    launch: Use SpawnError in all modules
    
    Use desktop_launch-derived launching exceptions across utils, launch
    etc.
    
    Also add a proper OperationError exception in the Open Terminal Here
    action.

 kupfer/launch.py          |   11 +++++------
 kupfer/obj/fileactions.py |    5 ++++-
 kupfer/obj/objects.py     |    4 ++--
 kupfer/utils.py           |   18 +++++++++++++++---
 4 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/kupfer/launch.py b/kupfer/launch.py
index f7679a2..82a90d1 100644
--- a/kupfer/launch.py
+++ b/kupfer/launch.py
@@ -11,15 +11,14 @@ from kupfer import desktop_launch
 from kupfer.ui import keybindings
 from kupfer import terminal
 
+from kupfer.desktop_launch import SpawnError
+
 try:
 	import wnck
 except ImportError, e:
 	pretty.print_info(__name__, "Disabling window tracking:", e)
 	wnck = None
 
-class LaunchError (Exception):
-	"Error launching application"
-
 
 default_associations = {
 	"evince" : "Document Viewer",
@@ -71,7 +70,7 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True,
 
 	@app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple
 
-	Raises LaunchError on failed program start.
+	Raises SpawnError on failed program start.
 	"""
 	assert app_info
 
@@ -107,8 +106,8 @@ def launch_application(app_info, files=(), uris=(), paths=(), track=True,
 		desktop_launch.launch_app_info(app_info, files,
 			   timestamp=_current_event_time(), desktop_file=desktop_file,
 			   launch_cb=launch_callback)
-	except desktop_launch.SpawnError as exc:
-		raise LaunchError(unicode(exc))
+	except SpawnError:
+		raise
 	return True
 
 def application_is_running(app_id):
diff --git a/kupfer/obj/fileactions.py b/kupfer/obj/fileactions.py
index 5bcde3f..fa1ad52 100644
--- a/kupfer/obj/fileactions.py
+++ b/kupfer/obj/fileactions.py
@@ -82,7 +82,10 @@ class OpenTerminal (Action):
 		super(OpenTerminal, self).__init__(name)
 	
 	def activate(self, leaf):
-		utils.spawn_terminal(leaf.object)
+		try:
+			utils.spawn_terminal(leaf.object)
+		except utils.SpawnError as exc:
+			raise OperationError(exc)
 
 	def get_description(self):
 		return _("Open this location in a terminal")
diff --git a/kupfer/obj/objects.py b/kupfer/obj/objects.py
index 2184a57..8f3b66f 100644
--- a/kupfer/obj/objects.py
+++ b/kupfer/obj/objects.py
@@ -231,8 +231,8 @@ class AppLeaf (Leaf):
 			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))
+		except launch.SpawnError as exc:
+			raise OperationError(exc)
 
 	def get_id(self):
 		"""Return the unique ID for this app.
diff --git a/kupfer/utils.py b/kupfer/utils.py
index 6dba507..64262be 100644
--- a/kupfer/utils.py
+++ b/kupfer/utils.py
@@ -11,9 +11,13 @@ import glib
 from kupfer import pretty
 from kupfer import kupferstring
 from kupfer import desktop_launch
+from kupfer import launch
 from kupfer import desktop_parse
 from kupfer import terminal
 
+from kupfer.desktop_launch import SpawnError
+
+
 def get_dirlist(folder, depth=0, include=None, exclude=None):
 	"""
 	Return a list of absolute paths in folder
@@ -181,6 +185,7 @@ class AsyncCommand (object):
 
 
 def spawn_terminal(workdir=None):
+	" Raises SpawnError "
 	term = terminal.get_configured_terminal()
 	notify = term["startup_notify"]
 	app_id = term["desktopid"]
@@ -188,6 +193,7 @@ def spawn_terminal(workdir=None):
 	desktop_launch.spawn_app_id(app_id, argv, workdir, notify)
 
 def spawn_in_terminal(argv, workdir=None):
+	" Raises SpawnError "
 	term = terminal.get_configured_terminal()
 	notify = term["startup_notify"]
 	_argv = list(term["argv"])
@@ -200,11 +206,17 @@ def spawn_async_notify_as(app_id, argv):
 	"""
 	Spawn argument list @argv and startup-notify as
 	if application @app_id is starting (if possible)
+
+	raises SpawnError
 	"""
 	desktop_launch.spawn_app_id(app_id, argv , None, True)
 
 def spawn_async(argv, in_dir="."):
-	"Silently spawn @argv in the background"
+	"""
+	Silently spawn @argv in the background
+
+	Returns False on failure
+	"""
 	pretty.print_debug(__name__, "Spawn commandline", argv, in_dir)
 	argv = _argv_to_locale(argv)
 	try:
@@ -217,7 +229,7 @@ def argv_for_commandline(cli):
 	return desktop_parse.parse_argv(cli)
 
 def launch_commandline(cli, name=None, in_terminal=False):
-	from kupfer import launch
+	" Raises SpawnError "
 	argv = desktop_parse.parse_argv(cli)
 	pretty.print_error(__name__, "Launch commandline is deprecated ")
 	pretty.print_debug(__name__, "Launch commandline (in_terminal=", in_terminal, "):", argv, sep="")
@@ -226,7 +238,7 @@ def launch_commandline(cli, name=None, in_terminal=False):
 	return spawn_async(argv)
 
 def launch_app(app_info, files=(), uris=(), paths=()):
-	from kupfer import launch
+	" Raises SpawnError "
 
 	# With files we should use activate=False
 	return launch.launch_application(app_info, files, uris, paths,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]