summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSebastien Estienne <sebastien.estienne@gmail.com>2006-08-06 23:52:31 +0000
committerSebastien Estienne <sebastien.estienne@gmail.com>2006-08-06 23:52:31 +0000
commit27c6fade238336c61a5a01d22fe767bf664ca010 (patch)
treeab199c4381c7753a23c89289a698f15351764e96 /tools
parentd9313c80245a75e3b023a729eacec454e580b7a8 (diff)
display error messages when something goes wrong in plugins
git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@115 3be567f1-68ff-0310-b24a-ad7cc433fd2f
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am14
-rw-r--r--tools/exec_wrapper.in58
2 files changed, 72 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644
index 0000000..3cd6b4e
--- /dev/null
+++ b/tools/Makefile.am
@@ -0,0 +1,14 @@
+toolsdir = $(TOOLSDIR)
+
+tools_SCRIPTS = \
+ exec_wrapper
+
+exec_wrapper: exec_wrapper.in
+ sed \
+ -e 's,@PYTHON\@,$(PYTHON),g' \
+ $< > $@
+ chmod +x $@
+
+EXTRA_DIST = exec_wrapper.in
+
+CLEANFILES = exec_wrapper
diff --git a/tools/exec_wrapper.in b/tools/exec_wrapper.in
new file mode 100644
index 0000000..c9d85ac
--- /dev/null
+++ b/tools/exec_wrapper.in
@@ -0,0 +1,58 @@
+#!@PYTHON@
+# -*- coding: UTF-8 -*-
+# -*- python -*-
+# Copyright (C) 2006 by Sebastien Estienne
+#
+# This file may be distributed and/or modified under the terms of
+# the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+# This file is distributed without any warranty; without even the implied
+# warranty of merchantability or fitness for a particular purpose.
+# See "COPYING" in the source distribution for more information.
+#
+# $Id$
+#
+
+import sys
+import os
+import pygtk
+import gtk
+
+
+from subprocess import *
+from string import join, replace
+
+pygtk.require('2.0')
+
+def error_msg(msg):
+ d = gtk.MessageDialog(parent=None, flags=gtk.DIALOG_MODAL,
+ type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
+ d.set_markup(msg)
+ d.show_all()
+ d.run()
+ d.destroy()
+
+def remove_markup(msg):
+ msg = replace(msg, "&" , "&amp;")
+ msg = replace(msg, "<" , "&lt;")
+ msg = replace(msg, ">" , "&gt;")
+ return msg
+
+def main(argv):
+ if len(argv) < 2:
+ print "Not enought arguments."
+ sys.exit(1)
+
+ argv.pop(0)
+
+ try:
+ p = Popen(argv, close_fds=True, stderr = PIPE)
+ except OSError, e:
+ error_msg("<b>An error has occured!</b>\n\nCommand: %s\nError: %s" % (join(argv, " "), e))
+ else:
+ status = os.waitpid(p.pid, 0)
+ if status[1] != 0:
+ error_msg(remove_markup(p.stderr.read()))
+
+if __name__ == "__main__":
+ main(sys.argv)