diff options
author | Andy Grover <agrover@redhat.com> | 2013-02-11 16:55:11 -0800 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2014-03-20 07:22:54 -0300 |
commit | a018f55b6d56422e0494ecd8d2a3f9288808b31e (patch) | |
tree | 185dd45dd2c7d783dee689d204d9e4a4575bd795 | |
parent | ae43e3d434383ea8260442eb2c48cd15007793e0 (diff) | |
download | kmod-a018f55b6d56422e0494ecd8d2a3f9288808b31e.tar.gz |
python: Make kmod.modprobe() raise an error if no modules found
Add 'quiet' option to override.
Add docstring.
-rw-r--r-- | libkmod/python/kmod/kmod.pyx | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/libkmod/python/kmod/kmod.pyx b/libkmod/python/kmod/kmod.pyx index 556b0f2..3e73a1c 100644 --- a/libkmod/python/kmod/kmod.pyx +++ b/libkmod/python/kmod/kmod.pyx @@ -102,8 +102,18 @@ 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): |