]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: move handle_pyerror() from MgrPyModules to MgrPyModule 14189/head
authorKefu Chai <kchai@redhat.com>
Fri, 21 Apr 2017 04:50:18 +0000 (12:50 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 21 Apr 2017 06:39:44 +0000 (14:39 +0800)
so we can reuse it in a more sane way.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/MgrPyModule.cc
src/mgr/MgrPyModule.h
src/mgr/PyModules.cc

index 35b28f733108fd9445d3d7fa789371738543670a..033825855c948838bfe1f7032b4dda71c4d8a129 100644 (file)
 
 #include "MgrPyModule.h"
 
-// FIXME: import sanely
-extern std::string handle_pyerror(void);
+//XXX courtesy of http://stackoverflow.com/questions/1418015/how-to-get-python-exception-text
+#include <boost/python.hpp>
+#include "include/assert.h"  // boost clobbers this
+
+// decode a Python exception into a string
+std::string handle_pyerror()
+{
+    using namespace boost::python;
+    using namespace boost;
+
+    PyObject *exc, *val, *tb;
+    object formatted_list, formatted;
+    PyErr_Fetch(&exc, &val, &tb);
+    handle<> hexc(exc), hval(allow_null(val)), htb(allow_null(tb));
+    object traceback(import("traceback"));
+    if (!tb) {
+        object format_exception_only(traceback.attr("format_exception_only"));
+        formatted_list = format_exception_only(hexc, hval);
+    } else {
+        object format_exception(traceback.attr("format_exception"));
+        formatted_list = format_exception(hexc,hval, htb);
+    }
+    formatted = str("").join(formatted_list);
+    return extract<std::string>(formatted);
+}
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_mgr
index 9d50a1b44105c0085d3f5308fb0f8e5f5bf48252..b466d1ac20f4824da4357d59949df2fe8ef94c28 100644 (file)
@@ -77,5 +77,7 @@ public:
     std::stringstream *ss);
 };
 
+std::string handle_pyerror();
+
 #endif
 
index 247e6b3fcd32b0399aa9c08153ce723fa7a53cb0..0926757844aa8daa68b9a9c9819d407eca7abc53 100644 (file)
@@ -286,31 +286,6 @@ PyObject *PyModules::get_python(const std::string &what)
   }
 }
 
-//XXX courtesy of http://stackoverflow.com/questions/1418015/how-to-get-python-exception-text
-#include <boost/python.hpp>
-// decode a Python exception into a string
-std::string handle_pyerror()
-{
-    using namespace boost::python;
-    using namespace boost;
-
-    PyObject *exc,*val,*tb;
-    object formatted_list, formatted;
-    PyErr_Fetch(&exc,&val,&tb);
-    handle<> hexc(exc),hval(allow_null(val)),htb(allow_null(tb)); 
-    object traceback(import("traceback"));
-    if (!tb) {
-        object format_exception_only(traceback.attr("format_exception_only"));
-        formatted_list = format_exception_only(hexc,hval);
-    } else {
-        object format_exception(traceback.attr("format_exception"));
-        formatted_list = format_exception(hexc,hval,htb);
-    }
-    formatted = str("").join(formatted_list);
-    return extract<std::string>(formatted);
-}
-
-
 std::string PyModules::get_site_packages()
 {
   std::stringstream site_packages;