From 5619873f02a34e29c6366be69306df44fd04cb68 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 20 Jun 2011 16:53:17 -0700 Subject: [PATCH] expose sigar_version to Python --- bindings/python/_sigar.c | 14 ++++++++++++++ bindings/python/setup.py | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bindings/python/_sigar.c b/bindings/python/_sigar.c index b1db5458..3d3cf77f 100644 --- a/bindings/python/_sigar.c +++ b/bindings/python/_sigar.c @@ -697,10 +697,24 @@ static PyMethodDef pysigar_module_methods[] = { #define PY_SIGAR_CONST_STR(name) \ PyDict_SetItemString(dict, #name, o=PyString_FromString(SIGAR_##name)); Py_DECREF(o) +#define PY_SIGAR_DEFINE_CONST_STR(name, value) \ + PyDict_SetItemString(dict, name, o=PyString_FromString(value)); Py_DECREF(o) + +static void init_pysigar_version(PyObject *dict) +{ + PyObject *o; + sigar_version_t *sv = sigar_version_get(); + PY_SIGAR_DEFINE_CONST_STR("BUILD_DATE", sv->build_date); + PY_SIGAR_DEFINE_CONST_STR("SCM_REVISION", sv->scm_revision); + PY_SIGAR_DEFINE_CONST_STR("VERSION", sv->version); +} + static void init_pysigar_constants(PyObject *dict) { PyObject *o; + init_pysigar_version(dict); + PY_SIGAR_CONST_INT(FIELD_NOTIMPL); PY_SIGAR_CONST_INT(IFF_UP); diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 1123d526..ae724674 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -17,7 +17,9 @@ # from distutils.core import setup, Extension -from os import system, mkdir, path, popen +from distutils.util import get_platform +from distutils.sysconfig import get_config_var, get_python_version +from os import system, mkdir, path, popen, rename import sys build = 'build' @@ -69,6 +71,18 @@ else : print "Inlining libsigar sources" src = sargs('inline_src -- ' + build) src.append('_sigar.c') + + version_file = "sigar_version.c" + build_version_file = build + "/" + version_file + libname = "_sigar" + get_config_var("SO") + filters = \ + 'ARCHNAME=' + get_platform() + '-' + get_python_version() + ' ' + \ + 'ARCHLIB=' + libname + ' ' + \ + 'BINNAME=' + libname + system(options['perl'] + ' -Mlib=.. -MSigarBuild -e version_file ' + filters) + rename(version_file, build_version_file) + src.append(build_version_file) + cppflags = sargs('cppflags') cppflags.append('-Wall') _sigar = Extension(