From: W. Trevor King Date: Fri, 19 Oct 2012 05:07:42 +0000 (-0400) Subject: Add Module.info attribute. X-Git-Tag: v0.9~1^2~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e9461fd71260ac8d43b5a4e2f88713a2c3f3b87e;p=python-kmod.git Add Module.info attribute. Signed-off-by: W. Trevor King --- diff --git a/kmod/_libkmod_h.pxd b/kmod/_libkmod_h.pxd index 0153ac0..a616a26 100644 --- a/kmod/_libkmod_h.pxd +++ b/kmod/_libkmod_h.pxd @@ -97,6 +97,11 @@ cdef extern from 'libkmod.h': long kmod_module_get_size(const_kmod_module_ptr mod) # Information retrieved from ELF headers and section + int kmod_module_get_info(const_kmod_module_ptr mod, kmod_list **list) + const_char_ptr kmod_module_info_get_key(const_kmod_list_ptr entry) + const_char_ptr kmod_module_info_get_value(const_kmod_list_ptr entry) + void kmod_module_info_free_list(kmod_list *list) + int kmod_module_get_versions(const_kmod_module_ptr mod, kmod_list **list) const_char_ptr kmod_module_version_get_symbol(const_kmod_list_ptr entry) _stdint.uint64_t kmod_module_version_get_crc(const_kmod_list_ptr entry) diff --git a/kmod/module.pyx b/kmod/module.pyx index 7c84eb8..b25f24f 100644 --- a/kmod/module.pyx +++ b/kmod/module.pyx @@ -69,6 +69,27 @@ cdef class Module (object): return _libkmod_h.kmod_module_get_size(self.module) size = property(fget=_size_get) + def _info_get(self): + cdef _list.ModList ml = _list.ModList() + cdef _list.ModListItem mli + err = _libkmod_h.kmod_module_get_info(self.module, &ml.list) + if err < 0: + raise _KmodError('Could not get versions') + info = {} + try: + for item in ml: + mli = <_list.ModListItem> item + key = _util.char_ptr_to_str( + _libkmod_h.kmod_module_info_get_key(mli.list)) + value = _util.char_ptr_to_str( + _libkmod_h.kmod_module_info_get_value(mli.list)) + info[key] = value + finally: + _libkmod_h.kmod_module_info_free_list(ml.list) + ml.list = NULL + return info + info = property(fget=_info_get) + def _versions_get(self): cdef _list.ModList ml = _list.ModList() cdef _list.ModListItem mli