summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorW. Trevor King <wking@tremily.us>2012-10-18 23:57:30 -0400
committerLucas De Marchi <lucas.demarchi@intel.com>2014-03-20 07:22:52 -0300
commit53d087e22fd86160b3119e4cdbf2bfe8591ddf64 (patch)
treeba8388d5876689b5a2a88dc65597ffba84d48731
parent118bb1fcba1358d81f0bb2e79cd046c4a170c883 (diff)
downloadkmod-53d087e22fd86160b3119e4cdbf2bfe8591ddf64.tar.gz
python: Add additional out Module attributes (path, refcnt, ...).
-rw-r--r--libkmod/python/kmod/_libkmod_h.pxd8
-rw-r--r--libkmod/python/kmod/_util.pxd4
-rw-r--r--libkmod/python/kmod/_util.pyx12
-rw-r--r--libkmod/python/kmod/module.pyx36
4 files changed, 52 insertions, 8 deletions
diff --git a/libkmod/python/kmod/_libkmod_h.pxd b/libkmod/python/kmod/_libkmod_h.pxd
index 975dfa3..9282cd2 100644
--- a/libkmod/python/kmod/_libkmod_h.pxd
+++ b/libkmod/python/kmod/_libkmod_h.pxd
@@ -74,4 +74,12 @@ cdef extern from 'libkmod.h':
)
const_char_ptr kmod_module_get_name(const_kmod_module_ptr mod)
+ const_char_ptr kmod_module_get_path(const_kmod_module_ptr mod)
+ const_char_ptr kmod_module_get_options(const_kmod_module_ptr mod)
+ const_char_ptr kmod_module_get_install_commands(const_kmod_module_ptr mod)
+ const_char_ptr kmod_module_get_remove_commands(const_kmod_module_ptr mod)
+
+ # Information regarding "live information" from module's state, as
+ # returned by kernel
+ int kmod_module_get_refcnt(const_kmod_module_ptr mod)
long kmod_module_get_size(const_kmod_module_ptr mod)
diff --git a/libkmod/python/kmod/_util.pxd b/libkmod/python/kmod/_util.pxd
new file mode 100644
index 0000000..3251d93
--- /dev/null
+++ b/libkmod/python/kmod/_util.pxd
@@ -0,0 +1,4 @@
+cimport _libkmod_h
+
+
+cdef object char_ptr_to_str(_libkmod_h.const_char_ptr bytes)
diff --git a/libkmod/python/kmod/_util.pyx b/libkmod/python/kmod/_util.pyx
new file mode 100644
index 0000000..7c527fc
--- /dev/null
+++ b/libkmod/python/kmod/_util.pyx
@@ -0,0 +1,12 @@
+import sys as _sys
+
+cimport _libkmod_h
+
+
+cdef object char_ptr_to_str(_libkmod_h.const_char_ptr char_ptr):
+ if char_ptr is NULL:
+ return None
+ if _sys.version_info >= (3,): # Python 3
+ return str(char_ptr, 'ascii')
+ # Python 2
+ return unicode(char_ptr, 'ascii')
diff --git a/libkmod/python/kmod/module.pyx b/libkmod/python/kmod/module.pyx
index 1e66772..e10c5f3 100644
--- a/libkmod/python/kmod/module.pyx
+++ b/libkmod/python/kmod/module.pyx
@@ -1,9 +1,9 @@
-import sys as _sys
-
cimport _libkmod_h
from error import KmodError as _KmodError
cimport list as _list
import list as _list
+cimport _util
+import _util
cdef class Module (object):
@@ -24,14 +24,34 @@ cdef class Module (object):
self.module = _libkmod_h.kmod_module_get_module(item.list)
def _name_get(self):
- name = _libkmod_h.kmod_module_get_name(self.module)
- if _sys.version_info >= (3,): # Python 3
- name = str(name, 'ascii')
- else: # Python 2
- name = unicode(name, 'ascii')
- return name
+ return _util.char_ptr_to_str(
+ _libkmod_h.kmod_module_get_name(self.module))
name = property(fget=_name_get)
+ def _path_get(self):
+ return _util.char_ptr_to_str(
+ _libkmod_h.kmod_module_get_path(self.module))
+ path = property(fget=_path_get)
+
+ def _options_get(self):
+ return _util.char_ptr_to_str(
+ _libkmod_h.kmod_module_get_options(self.module))
+ options = property(fget=_options_get)
+
+ def _install_commands_get(self):
+ return _util.char_ptr_to_str(
+ _libkmod_h.kmod_module_get_install_commands(self.module))
+ install_commands = property(fget=_install_commands_get)
+
+ def _remove_commands_get(self):
+ return _util.char_ptr_to_str(
+ _libkmod_h.kmod_module_get_remove_commands(self.module))
+ remove_commands = property(fget=_remove_commands_get)
+
+ def _refcnt_get(self):
+ return _libkmod_h.kmod_module_get_refcnt(self.module)
+ refcnt = property(fget=_refcnt_get)
+
def _size_get(self):
return _libkmod_h.kmod_module_get_size(self.module)
size = property(fget=_size_get)