1 # Copyright (C) 2012 Red Hat, Inc. All rights reserved.
4 # This copyrighted material is made available to anyone wishing to use,
5 # modify, copy, or redistribute it subject to the terms and conditions
6 # of the GNU Lesser General Public License v.2.1.
8 # You should have received a copy of the GNU Lesser General Public License
9 # along with this program; if not, write to the Free Software Foundation,
10 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 from error import KmodError as _KmodError
20 cdef class Module (object):
21 "Wrap a struct kmod_module* item"
25 def __dealloc__(self):
29 if self.module is not NULL:
30 _libkmod_h.kmod_module_unref(self.module)
33 cpdef from_mod_list_item(self, _list.ModListItem item):
35 self.module = _libkmod_h.kmod_module_get_module(item.list)
38 return _util.char_ptr_to_str(
39 _libkmod_h.kmod_module_get_name(self.module))
40 name = property(fget=_name_get)
43 return _util.char_ptr_to_str(
44 _libkmod_h.kmod_module_get_path(self.module))
45 path = property(fget=_path_get)
47 def _options_get(self):
48 return _util.char_ptr_to_str(
49 _libkmod_h.kmod_module_get_options(self.module))
50 options = property(fget=_options_get)
52 def _install_commands_get(self):
53 return _util.char_ptr_to_str(
54 _libkmod_h.kmod_module_get_install_commands(self.module))
55 install_commands = property(fget=_install_commands_get)
57 def _remove_commands_get(self):
58 return _util.char_ptr_to_str(
59 _libkmod_h.kmod_module_get_remove_commands(self.module))
60 remove_commands = property(fget=_remove_commands_get)
62 def _refcnt_get(self):
63 return _libkmod_h.kmod_module_get_refcnt(self.module)
64 refcnt = property(fget=_refcnt_get)
67 return _libkmod_h.kmod_module_get_size(self.module)
68 size = property(fget=_size_get)
70 def _versions_get(self):
71 cdef _list.ModList ml = _list.ModList()
72 cdef _list.ModListItem mli
73 err = _libkmod_h.kmod_module_get_versions(self.module, &ml.list)
75 raise _KmodError('Could not get versions')
78 mli = <_list.ModListItem> item
79 symbol = _util.char_ptr_to_str(
80 _libkmod_h.kmod_module_version_get_symbol(mli.list))
81 crc = _libkmod_h.kmod_module_version_get_crc(mli.list)
82 yield {'symbol': symbol, 'crc': crc}
84 _libkmod_h.kmod_module_versions_free_list(ml.list)
86 versions = property(fget=_versions_get)
88 def insert(self, flags=0, extra_options=None, install_callback=None,
89 data=None, print_action_callback=None):
91 #cdef _libkmod_h.install_callback_t install = NULL
93 _libkmod_h.kmod_module *, _libkmod_h.const_char_ptr, void *)
96 #cdef _libkmod_h.print_action_callback_t print_action = NULL
97 cdef void (*print_action)(
98 _libkmod_h.kmod_module *, _libkmod_h.bool,
99 _libkmod_h.const_char_ptr)
103 # TODO: convert callbacks and data from Python object to C types
104 err = _libkmod_h.kmod_module_probe_insert_module(
105 self.module, flags, opt, install, d, print_action)
106 if err == -_libkmod_h.EEXIST:
107 raise _KmodError('Module already loaded')
109 raise _KmodError('Could not load module')
111 def remove(self, flags=0):
112 err = _libkmod_h.kmod_module_remove_module(self.module, flags)
114 raise _KmodError('Could not remove module')