]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding method merge to class ModuleInfoDict
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 10:31:47 +0000 (12:31 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 6 Sep 2018 10:31:47 +0000 (12:31 +0200)
lib/webhooks/module_list.py

index b07d236c9f07439877cbd6da34e0c9c5cafe6368..499e0157be939713d5fdb39069781d06aecd2853 100644 (file)
@@ -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
 
     # -------------------------------------------------------------------------