get_formatted_data optimization

The property previously used multiple loops and nested
conditions for making a dictionary copy with formatted keys.

Now it uses just one.
Could be reduced further assuming substitution of 'Id' for 'ID'.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I6ef708b6d39ac56354881b89421ff4c0771c6ab5
This commit is contained in:
Jiri Podivin 2021-06-17 15:01:24 +02:00
parent 4d1df7b0e7
commit a9515a3182
1 changed files with 7 additions and 11 deletions

View File

@ -265,7 +265,7 @@ class Validation(object):
>>> pl = '/foo/bar/val.yaml'
>>> val = Validation(pl)
>>> print(val.get_data)
>>> print(val.get_formated_data)
{'Description': 'description of val',
'Groups': ['group1', 'group2'],
'ID': 'val',
@ -273,15 +273,11 @@ class Validation(object):
"""
data = {}
metadata = self.get_metadata
if metadata:
for key in metadata.keys():
if key in map(str.lower, self._col_keys):
for k in self._col_keys:
if key == k.lower():
output_key = k
data[output_key] = self.get_metadata.get(key)
else:
# Get all other values:
data[key] = self.get_metadata.get(key)
for key in metadata:
if key == 'id':
data[key.upper()] = metadata.get(key)
else:
data[key.capitalize()] = metadata.get(key)
return data