Skip to content

Commit

Permalink
[airos] switched to friendlier names in dictionary iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
edoput committed Jul 17, 2017
1 parent aee3953 commit 10a87d8
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions netjsonconfig/backends/airos/airos.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ def intermediate_to_list(configuration):
(index, config) = element
# update the keys to prefix the index
temp = {}
for k, v in config.items():
for key, value in config.items():
# write the new key
temp['{i}.{key}'.format(i=index + 1, key=k)] = v

temp['{i}.{key}'.format(i=index + 1, key=key)] = value
config = temp
# now the keys are updated with the index
# reduce to atoms the new config
Expand All @@ -144,18 +143,17 @@ def intermediate_to_list(configuration):

elif isinstance(element, dict):
temp = {}
for k, v in element.items():
if isinstance(v, string_types) or isinstance(v, int):
for key, value in element.items():
if isinstance(value, string_types) or isinstance(value, int):
pass
else:
# reduce to atom list
# as v could be dict or list
# as value could be dict or list
# enclose it in a flattened list
for son in intermediate_to_list(flatten([v])):

for sk, sv in son.items():
nested_key = '{key}.{subkey}'.format(key=k, subkey=sk)
temp[nested_key] = sv
for child in intermediate_to_list(flatten([value])):
for child_key, child_value in child.items():
nested_key = '{key}.{subkey}'.format(key=child_key, subkey=child_value)
temp[nested_key] = child_value

# now it is atomic, append it to
result.append(temp)
Expand Down

0 comments on commit 10a87d8

Please sign in to comment.