Chris asked for this to help with his traceback handling fixups. It generates a traceback object at the current location, but doesn't raise an exception. --- isys/isys.c | 39 +++++++++++++++++++++++++++++++++++++++ isys/isys.py | 18 ++++++++++++++++++ 2 files changed, 57 insertions(+), 0 deletions(-) diff --git a/isys/isys.c b/isys/isys.c index b3466ab..3b17b6f 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -132,6 +132,7 @@ static PyObject * doGetBlkidData(PyObject * s, PyObject * args); static PyObject * doGetDeviceByToken(PyObject *s, PyObject *args); static PyObject * doIsCapsLockEnabled(PyObject * s, PyObject * args); static PyObject * doGetLinkStatus(PyObject * s, PyObject * args); +static PyObject * doTraceback(PyObject *self, PyObject *args, PyObject *kwds); static PyMethodDef isysModuleMethods[] = { { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL }, @@ -179,6 +180,7 @@ static PyMethodDef isysModuleMethods[] = { { "getdevicebytoken", (PyCFunction) doGetDeviceByToken, METH_VARARGS, NULL }, { "isCapsLockEnabled", (PyCFunction) doIsCapsLockEnabled, METH_VARARGS, NULL }, { "getLinkStatus", (PyCFunction) doGetLinkStatus, METH_VARARGS, NULL }, + { "traceback", (PyCFunction) doTraceback, METH_VARARGS|METH_KEYWORDS, NULL }, { NULL, NULL, 0, NULL } } ; @@ -932,4 +934,41 @@ static PyObject * doGetLinkStatus(PyObject * s, PyObject * args) { return PyBool_FromLong(0); } +#include "frameobject.h" + +static PyObject * +doTraceback(PyObject *self, PyObject *args, PyObject *kwds) +{ + char *kwlist[] = {"frame", "previous", NULL}; + PyFrameObject *frame = NULL; + PyThreadState *tstate; + PyTracebackObject *intb = NULL; + PyTracebackObject *oldtb = NULL; + PyTracebackObject *tb; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:traceback", + kwlist, &frame, &intb)) + return NULL; + + tstate = PyThreadState_GET(); + oldtb = (PyTracebackObject *)tstate->curexc_traceback; + + /* this has side effects we have to undo afterwards. */ + if (PyTraceBack_Here(frame) < 0) + return NULL; + + tb = (PyTracebackObject *)tstate->curexc_traceback; + + /* PyTraceBack_Here makes the new traceback be the "current" + * traceback, which isn't really desired */ + tstate->curexc_traceback = (PyObject *)oldtb; + + /* PyTraceBack_Here adds the "current" traceback as this traceback's + * "next" traceback, which we really don't want. */ + Py_XINCREF(intb); + tb->tb_next = intb; + + return (PyObject *)tb; +} + /* vim:set shiftwidth=4 softtabstop=4: */ diff --git a/isys/isys.py b/isys/isys.py index 05e0806..db2aa4e 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -946,6 +946,24 @@ def getMacAddress(dev): device_macaddr = device_props_iface.Get(NM_MANAGER_IFACE, "HwAddress") return device_macaddr.upper() +def traceback(skipframes=0): + frames = [] + n = skipframes + 1 + while True: + try: + frames.append(sys._getframe(n)) + n += 1 + except ValueError: + break + + tb = None + for frame in frames: + if tb is None: + tb = _isys.traceback(frame) + else: + tb = _isys.traceback(frame, tb) + return tb + # Determine if a network device is a wireless device. def isWireless(dev): if dev == '' or dev is None: -- 1.6.0.1 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list