summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2017-04-21 06:50:18 +0200
committerKefu Chai <kchai@redhat.com>2017-04-21 08:39:44 +0200
commitcef433eccb012d05fb1bd4d04478c61d6c9c02e0 (patch)
tree30da6376317cbee946ddbcb5ff57c7805d67c35f
parentmgr/MgrPyModule::handle_command: order stringstreams to match intent (diff)
downloadceph-cef433eccb012d05fb1bd4d04478c61d6c9c02e0.tar.xz
ceph-cef433eccb012d05fb1bd4d04478c61d6c9c02e0.zip
mgr: move handle_pyerror() from MgrPyModules to MgrPyModule
so we can reuse it in a more sane way. Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to '')
-rw-r--r--src/mgr/MgrPyModule.cc27
-rw-r--r--src/mgr/MgrPyModule.h2
-rw-r--r--src/mgr/PyModules.cc25
3 files changed, 27 insertions, 27 deletions
diff --git a/src/mgr/MgrPyModule.cc b/src/mgr/MgrPyModule.cc
index 35b28f73310..033825855c9 100644
--- a/src/mgr/MgrPyModule.cc
+++ b/src/mgr/MgrPyModule.cc
@@ -18,8 +18,31 @@
#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
diff --git a/src/mgr/MgrPyModule.h b/src/mgr/MgrPyModule.h
index 9d50a1b4410..b466d1ac20f 100644
--- a/src/mgr/MgrPyModule.h
+++ b/src/mgr/MgrPyModule.h
@@ -77,5 +77,7 @@ public:
std::stringstream *ss);
};
+std::string handle_pyerror();
+
#endif
diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc
index 247e6b3fcd3..0926757844a 100644
--- a/src/mgr/PyModules.cc
+++ b/src/mgr/PyModules.cc
@@ -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;