From f56ccc1643965ca0e4e0e7cd9e2a89ae803b2340 Mon Sep 17 00:00:00 2001 From: Marc Lagrange Date: Fri, 9 Jan 2009 13:29:18 +0100 Subject: [PATCH 1/2] python: Add exception for wmfs.init() if wmfs is not running, an exception is called like: In [2]: wmfs.init() --------------------------------------------------------------------------- error Traceback (most recent call last) /usr/home/marc/ in () error: WMFS not running? Signed-off-by: Marc Lagrange --- python/libwmfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/libwmfs.c b/python/libwmfs.c index f410cbc..7ccd9ed 100644 --- a/python/libwmfs.c +++ b/python/libwmfs.c @@ -92,9 +92,9 @@ wmfs_init(PyObject *self, PyObject *args) /* Else, exit. */ if(!ret) { - fprintf(stderr, "WMFS is not running.\n"); XFree(ret); - exit(EXIT_FAILURE); + PyErr_SetString(WmfsInitError, "WMFS not running?"); + return NULL; } XFree(ret); From 697e07ad3844f6d7dfec1a087856fbd4685f8bb3 Mon Sep 17 00:00:00 2001 From: Marc Lagrange Date: Fri, 9 Jan 2009 13:34:08 +0100 Subject: [PATCH 2/2] python: The right exception is called, WmfsInitError instead of error. a wmfs.WmfsInitError is available with a wmfs.WmfsInitError.message containing message error. In [2]: wmfs.init() --------------------------------------------------------------------------- WmfsInitError Traceback (most recent call last) /usr/home/marc/ in () WmfsInitError: WMFS not running? In [3]: try: ...: wmfs.init() ...: except wmfs.WmfsInitError, e: ...: print 'Error: '+e.message ...: Error: WMFS not running? Signed-off-by: Marc Lagrange --- python/libwmfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/libwmfs.c b/python/libwmfs.c index 7ccd9ed..bfd79dc 100644 --- a/python/libwmfs.c +++ b/python/libwmfs.c @@ -189,10 +189,10 @@ initwmfs(void) if(m == NULL) return; - WmfsInitError = PyErr_NewException("wmfs.error", NULL, NULL); + WmfsInitError = PyErr_NewException("wmfs.WmfsInitError", NULL, NULL); Py_INCREF(WmfsInitError); - PyModule_AddObject(m, "error", WmfsInitError); + PyModule_AddObject(m, "WmfsInitError", WmfsInitError); } int