Add isys.traceback(), which generates a traceback with no exception.
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 | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
+#include "frameobject.h"
+
+static PyObject *
+doTraceback(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ char *kwlist[] = {"frame", NULL};
+ PyFrameObject *frame = NULL;
+ PyThreadState *tstate;
+ PyTracebackObject *oldtb;
+ PyTracebackObject *tb;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:traceback",
+ kwlist, &frame))
+ 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. */
+ tb->tb_next = NULL;
+ return (PyObject *)tb;
+}
+
/* vim:set shiftwidth=4 softtabstop=4: */
--
1.6.0.1
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
12-04-2008, 02:48 PM
"pjones"
Add isys.traceback(), which generates a traceback with no exception.
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(-)
+#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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list