diff options
author | Brian Dolbec <dolsen@gentoo.org> | 2016-04-16 16:29:20 -0700 |
---|---|---|
committer | Brian Dolbec <dolsen@gentoo.org> | 2016-04-25 08:28:53 -0700 |
commit | edd6f6cd73839dad09ce7c65c09ac38c30e6b5eb (patch) | |
tree | 1a7c25be19cb5d7a09e91f20060b2c41b478d61e | |
parent | repoman/modules/scan.py: Add docstrings (diff) | |
download | portage-edd6f6cd.tar.gz portage-edd6f6cd.tar.bz2 portage-edd6f6cd.zip |
repoman: Limit the kwargs passed to the module's __init__()
This has the benefit of forcing the module to declare what data it requires.
Rather than possibly silently fail.
-rw-r--r-- | pym/repoman/scanner.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py index e9a8e2061..5ac519ee2 100644 --- a/pym/repoman/scanner.py +++ b/pym/repoman/scanner.py @@ -202,7 +202,18 @@ class Scanner(object): 'fetches', 'pkgmetadata']: mod_class = MODULE_CONTROLLER.get_class(mod) logging.debug("Initializing class name: %s", mod_class.__name__) - self.modules[mod_class.__name__] = mod_class(**self.kwargs) + self.modules[mod_class.__name__] = mod_class(**self.set_kwargs(mod)) + + def set_kwargs(self, mod): + '''Creates a limited set of kwargs to pass to the module's __init__() + + @param mod: module name string + @returns: dictionary + ''' + kwargs = {} + for key in MODULE_CONTROLLER.modules[mod]['mod_kwargs']: + kwargs[key] = self.kwargs[key] + return kwargs def scan_pkgs(self, can_force): for xpkg in self.effective_scanlist: @@ -295,7 +306,7 @@ class Scanner(object): if mod[0]: mod_class = MODULE_CONTROLLER.get_class(mod[0]) logging.debug("Initializing class name: %s", mod_class.__name__) - self.modules[mod[1]] = mod_class(**self.kwargs) + self.modules[mod[1]] = mod_class(**self.set_kwargs(mod)) logging.debug("scan_ebuilds: module: %s", mod[1]) do_it, functions = self.modules[mod[1]].runInEbuilds logging.debug("do_it: %s, functions: %s", do_it, [x.__name__ for x in functions]) @@ -329,7 +340,7 @@ class Scanner(object): if mod[0]: mod_class = MODULE_CONTROLLER.get_class(mod[0]) logging.debug("Initializing class name: %s", mod_class.__name__) - self.modules[mod[1]] = mod_class(**self.kwargs) + self.modules[mod[1]] = mod_class(**self.set_kwargs(mod)) logging.debug("scan_ebuilds final checks: module: %s", mod[1]) do_it, functions = self.modules[mod[1]].runInFinal logging.debug("do_it: %s, functions: %s", do_it, [x.__name__ for x in functions]) |