Skip to content

Commit

Permalink
Add support for +* operation
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell committed Nov 7, 2024
1 parent f4fb82e commit e496cd3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,25 @@ def _initialize(self, path):
except ValueError:
raise utils.FormatError("Invalid version format")

def _merge_plus(self, data, key, value, prepend=False):
def _merge_plus(self, data, key, value, prepend=False, process_list=False):
""" Handle extending attributes using the '+' suffix """
# Nothing to do if key not in parent
if process_list:
if not isinstance(data[key], list):
raise utils.MergeError(
"MergeError: Key '{0}' in {1} must be a list.".format(
key, self.name))
if not isinstance(value, dict):
raise utils.MergeError(
"MergeError: Value '{0}' in {1} must be a dictionary.".format(
value, self.name))
for list_item in data[key]:
if not isinstance(list_item, dict):
"MergeError: Item '{0}' in {1} must be a dictionary.".format(
list_item, self.name)
self._merge_special(list_item, value)
return

if key not in data:
data[key] = value
return
Expand Down Expand Up @@ -268,6 +284,8 @@ def _merge_special(self, data, source):
self._merge_plus(data, key.rstrip('+'), value)
elif key.endswith('+<'):
self._merge_plus(data, key.rstrip('+<'), value, prepend=True)
elif key.endswith('+*'):
self._merge_plus(data, key.rstrip('+*'), value, process_list=True)
elif key.endswith('-~'):
self._merge_minus_regexp(data, key.rstrip('-~'), value)
elif key.endswith('-'):
Expand Down

0 comments on commit e496cd3

Please sign in to comment.