From: Andy Grover Date: Tue, 12 Feb 2013 00:55:11 +0000 (-0800) Subject: Make kmod.modprobe() raise an error if no modules found X-Git-Tag: v0.9.1~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4402f725136dd8ac8a8d7c643e934797714b08b5;p=python-kmod.git Make kmod.modprobe() raise an error if no modules found Add 'quiet' option to override. Add docstring. Signed-off-by: Andy Grover --- diff --git a/kmod/kmod.pyx b/kmod/kmod.pyx index 556b0f2..3e73a1c 100644 --- a/kmod/kmod.pyx +++ b/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):