Skip to content

Commit

Permalink
expose sigar_version to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Jun 20, 2011
1 parent 73b0850 commit 5619873
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions bindings/python/_sigar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 15 additions & 1 deletion bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -69,6 +71,18 @@ def sargs(cmd):
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(
Expand Down

0 comments on commit 5619873

Please sign in to comment.