]> git.ipfire.org Git - thirdparty/kmod.git/blobdiff - libkmod/python/kmod/kmod.pyx
configure: Check that provided paths are absolute
[thirdparty/kmod.git] / libkmod / python / kmod / kmod.pyx
index fdba4c653af6b4c19ce35ae47ebb06424309da4a..3e73a1ca8fb976351435864126c2103a48a6ca1d 100644 (file)
@@ -1,13 +1,21 @@
-# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
-#               2012 W. Trevor King
+# Copyright (C) 2012 Red Hat, Inc.
+#                    W. Trevor King <wking@tremily.us>
 #
-# This copyrighted material is made available to anyone wishing to use,
-# modify, copy, or redistribute it subject to the terms and conditions
-# of the GNU Lesser General Public License v.2.1.
+# This file is part of python-kmod.
+#
+# python-kmod is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License version 2.1 as published
+# by the Free Software Foundation.
+#
+# python-kmod is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
 # You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# along with python-kmod.  If not, see <http://www.gnu.org/licenses/>.
+
+"Define the Kmod class"
 
 cimport cython as _cython
 cimport _libkmod_h
@@ -19,8 +27,10 @@ import list as _list
 
 
 cdef class Kmod (object):
+    "Wrap a struct kmod_ctx* item"
     def __cinit__(self):
         self._kmod_ctx = NULL
+        self.mod_dir = None
 
     def __dealloc__(self):
         self._cleanup()
@@ -92,10 +102,24 @@ cdef class Kmod (object):
         for mod in self.loaded():
             yield (mod.name, mod.size)
 
-    def modprobe(self, alias_name, *args, **kwargs):
-        for mod in self.lookup(alias_name=alias_name):
+    def modprobe(self, name, quiet=False, *args, **kwargs):
+        """
+        Load a module (or alias) and all modules on which it depends.
+        The 'quiet' option defaults to False; set to True to mimic the behavior
+        of the '--quiet' commandline option.
+        """
+        mods = list(self.lookup(alias_name=name))
+
+        if not mods and not quiet:
+            raise _KmodError('Could not modprobe %s' % name)
+
+        for mod in mods:
             mod.insert(*args, **kwargs)
 
     def rmmod(self, module_name, *args, **kwargs):
+       """
+       remove module from current tree
+       e.g. km.rmmod("thinkpad_acpi")
+       """
        mod = self.module_from_name(name=module_name)
        mod.remove(*args, **kwargs)