From 83575cdb58a39d35ce3806d0ed9ed11d315a9258 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 9 Sep 2007 21:49:33 +0000 Subject: [PATCH] add format_size wrapper --- bindings/python/_sigar.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bindings/python/_sigar.c b/bindings/python/_sigar.c index a54def65..96e468be 100644 --- a/bindings/python/_sigar.c +++ b/bindings/python/_sigar.c @@ -96,6 +96,31 @@ static PyObject *pysigar_close(PyObject *self, PyObject *args) return Py_None; } +static int pysigar_parse_uint64(PyObject *args, sigar_uint64_t *val) +{ + PyObject *obj; + + if (!PyArg_ParseTuple(args, "O", &obj)) { + return !SIGAR_OK; + } + + *val = PyInt_AsUnsignedLongLongMask(obj); + return SIGAR_OK; +} + +static PyObject *pysigar_format_size(PyObject *self, PyObject *args) +{ + char buffer[56]; + sigar_uint64_t size; + + if (pysigar_parse_uint64(args, &size) == SIGAR_OK) { + return PyString_FromString(sigar_format_size(size, buffer)); + } + else { + return NULL; + } +} + static PyMethodDef pysigar_methods[] = { { "close", pysigar_close, METH_NOARGS, NULL }, PY_SIGAR_METHODS @@ -146,6 +171,7 @@ static PyTypeObject pysigar_PySigarType = { static PyMethodDef pysigar_module_methods[] = { { "open", pysigar_open, METH_NOARGS, NULL }, + { "format_size", pysigar_format_size, METH_VARARGS, NULL }, {NULL} };