From: Frank Brehm Date: Thu, 6 Sep 2018 10:31:47 +0000 (+0200) Subject: Adding method merge to class ModuleInfoDict X-Git-Tag: 0.11.4^2~2 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=7ae8328899d6c9e6b01b630319c5a2422292878e;p=pixelpark%2Fpuppetmaster-webhooks.git Adding method merge to class ModuleInfoDict --- diff --git a/lib/webhooks/module_list.py b/lib/webhooks/module_list.py index b07d236..499e015 100644 --- a/lib/webhooks/module_list.py +++ b/lib/webhooks/module_list.py @@ -32,7 +32,7 @@ from .obj import BaseObject from .module_info import ModuleInfo -__version__ = '0.1.2' +__version__ = '0.1.3' LOG = logging.getLogger(__name__) @@ -131,6 +131,22 @@ class ModuleInfoDict(MutableMapping, BaseObject): del self._map[full_name] + # ------------------------------------------------------------------------- + def merge(self, item): + + if not isinstance(item, ModuleInfo): + raise TypeError(self.msg_invalid_modinfo_type.format(item.__class__.__name__)) + + full_name = item.full_name + if full_name in self._map.keys(): + if self.verbose > 2: + LOG.debug("Merging module {!r}.".format(full_name)) + self._map[full_name].merge_in(item) + else: + if self.verbose > 2: + LOG.debug("New module {!r}.".format(full_name)) + self._set_item(full_name, item) + # ------------------------------------------------------------------------- # The next five methods are requirements of the ABC. def __setitem__(self, key, value): @@ -169,6 +185,9 @@ class ModuleInfoDict(MutableMapping, BaseObject): if full_name == '': raise ValueError(self.msg_empty_key_error.format(key)) + if self.verbose > 4: + LOG.debug("Searching for key {!r} ...".format(key)) + return full_name in self._map # -------------------------------------------------------------------------