[kupfer: 38/53] Remove CommandMissingError as superfluous



commit 062ad2a0a569d659b4514186e27b5167e1856173
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Mar 24 17:22:39 2011 +0100

    Remove CommandMissingError as superfluous
    
    (We should re-use the OS error message from glib when failing to spawn
    commands. The message is localized.)

 kupfer/obj/exceptions.py  |    7 -------
 kupfer/plugin/sendkeys.py |   22 ++++++++++++++--------
 kupfer/utils.py           |   20 ++++++++++++++++----
 3 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/kupfer/obj/exceptions.py b/kupfer/obj/exceptions.py
index e0bddfb..bf74acf 100644
--- a/kupfer/obj/exceptions.py
+++ b/kupfer/obj/exceptions.py
@@ -9,13 +9,6 @@ class LocaleOperationError (OperationError):
 	def __init__(self, s):
 		OperationError.__init__(self, kupferstring.fromlocale(s))
 
-class CommandMissingError (OperationError):
-	"""
-	User-visible error message for missing executable
-	"""
-	def __init__(self, cmd):
-		OperationError.__init__(self, _("Command '%s' not found") % (cmd, ))
-
 class NotAvailableError (OperationError):
 	"""
 	User-visible error message when an external
diff --git a/kupfer/plugin/sendkeys.py b/kupfer/plugin/sendkeys.py
index 32cbf23..80f4ab5 100644
--- a/kupfer/plugin/sendkeys.py
+++ b/kupfer/plugin/sendkeys.py
@@ -15,7 +15,7 @@ import string
 import gtk
 
 from kupfer.objects import Leaf, Action, Source, TextLeaf
-from kupfer.objects import OperationError, CommandMissingError
+from kupfer.objects import OperationError
 from kupfer import pretty
 from kupfer import utils
 from kupfer import interface
@@ -31,8 +31,10 @@ class CopyAndPaste (Action):
 		interface.copy_to_clipboard(leaf, clip)
 		xte_paste_argv = ['xte', 'usleep 300000', 'keydown Control_L',
 		                  'key v', 'keyup Control_L']
-		if not utils.spawn_async(xte_paste_argv):
-			raise CommandMissingError('xte')
+		try:
+			utils.spawn_async_raise(xte_paste_argv)
+		except utils.SpawnError as exc:
+			raise OperationError(exc)
 	def item_types(self):
 		yield Leaf
 	def valid_for_item(self, leaf):
@@ -64,7 +66,7 @@ class SendKeys (Action):
 				mod_names.append(m[mod])
 				mods &= ~mod
 		if mods != 0:
-			raise OperationError(_("Keys not yet implemented: %s") %
+			raise OperationError("Keys not yet implemented: %s" %
 					gtk.accelerator_get_label(keys, orig_mods))
 		key_arg = 'key %s' % (gtk.gdk.keyval_name(keys), )
 		mods_down = ['keydown ' + n for n in mod_names]
@@ -72,8 +74,10 @@ class SendKeys (Action):
 
 		xte_paste_argv = ['xte', 'usleep 300000'] + \
 				mods_down + [key_arg] + mods_up
-		if not utils.spawn_async(xte_paste_argv):
-			raise CommandMissingError('xte')
+		try:
+			utils.spawn_async_raise(xte_paste_argv)
+		except utils.SpawnError as exc:
+			raise OperationError(exc)
 	def item_types(self):
 		yield TextLeaf
 	def valid_for_item(self, leaf):
@@ -95,8 +99,10 @@ class TypeText (Action):
 			xte_paste_argv.append("str " + line.rstrip("\r\n"))
 			if line.endswith("\n"):
 				xte_paste_argv.append("key Return")
-		if not utils.spawn_async(xte_paste_argv):
-			raise CommandMissingError('xte')
+		try:
+			utils.spawn_async_raise(xte_paste_argv)
+		except utils.SpawnError as exc:
+			raise OperationError(exc)
 	def item_types(self):
 		yield Leaf
 	def valid_for_item(self, leaf):
diff --git a/kupfer/utils.py b/kupfer/utils.py
index 8ccb7e9..7c5203a 100644
--- a/kupfer/utils.py
+++ b/kupfer/utils.py
@@ -217,13 +217,25 @@ def spawn_async(argv, in_dir="."):
 
 	Returns False on failure
 	"""
-	pretty.print_debug(__name__, "Spawn commandline", argv, in_dir)
+	try:
+		return spawn_async_raise(argv, in_dir)
+	except SpawnError as exc:
+		pretty.print_debug(__name__, "spawn_async", argv, exc)
+		return False
+
+def spawn_async_raise(argv, workdir="."):
+	"""
+	A version of spawn_async that raises on error.
+
+	raises SpawnError
+	"""
+	pretty.print_debug(__name__, "Spawn Async", argv, workdir)
 	argv = _argv_to_locale(argv)
 	try:
-		return gobject.spawn_async (argv, working_directory=in_dir,
+		return gobject.spawn_async (argv, working_directory=workdir,
 				flags=gobject.SPAWN_SEARCH_PATH)
-	except gobject.GError, exc:
-		pretty.print_debug(__name__, "spawn_async", argv, exc)
+	except gobject.GError as exc:
+		raise SpawnError(exc)
 
 def argv_for_commandline(cli):
 	return desktop_parse.parse_argv(cli)



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