Skip to content

Commit

Permalink
Merge pull request #312 from NASA-AMMOS/issue-306
Browse files Browse the repository at this point in the history
Issue #306 - Support lists in config directory expansion
  • Loading branch information
MJJoyce authored Dec 16, 2020
2 parents 71b22db + 07e0510 commit 2554ee2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ait/core/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ def expandConfigPaths (config, prefix=None, datetime=None, pathvars=None, parame

config[name] = cleaned[0] if len(cleaned) == 1 else cleaned

elif type(value) is dict:
elif isinstance(value, dict):
param_key = name if parameter_key == '' else parameter_key + '.' + name
expandConfigPaths(value, prefix, datetime, pathvars, param_key, *keys)

elif isinstance(value, list):
for item in value:
if isinstance(item, dict):
param_key = name if parameter_key == '' else parameter_key + '.' + name
expandConfigPaths(item, prefix, datetime, pathvars, param_key, *keys)


def replaceVariables(path, datetime=None, pathvars=None):
"""Return absolute path with path variables replaced as applicable"""
Expand Down
24 changes: 22 additions & 2 deletions ait/core/test/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ def test_expandConfigPaths ():
'desc' : 'Test expansion of nested dictionaries too',
'file' : os.path.join('bin', 'ait-cmd-send'),
'filename': os.path.join('bin', 'ait-cmd-send'),
}
},
'a list': [
{
'file' : os.path.join('bin', 'ait-orbits-in-a-list'),
'filename': os.path.join('bin', 'ait-orbits-in-a-list'),
},
{
'file' : os.path.join('bin', 'ait-cmd-send-in-a-list'),
'filename': os.path.join('bin', 'ait-cmd-send-in-a-list'),
}
]
}
expected = {
'desc' : 'Test cfg.expandConfigPaths()',
Expand All @@ -85,7 +95,17 @@ def test_expandConfigPaths ():
'desc' : 'Test expansion of nested dictionaries too',
'file' : os.path.join(prefix, 'bin', 'ait-cmd-send'),
'filename': os.path.join(prefix, 'bin', 'ait-cmd-send'),
}
},
'a list': [
{
'file' : os.path.join(prefix, 'bin', 'ait-orbits-in-a-list'),
'filename': os.path.join(prefix, 'bin', 'ait-orbits-in-a-list'),
},
{
'file' : os.path.join(prefix, 'bin', 'ait-cmd-send-in-a-list'),
'filename': os.path.join(prefix, 'bin', 'ait-cmd-send-in-a-list'),
}
]
}

cfg.expandConfigPaths(actual, prefix, None, None, '', 'file', 'filename')
Expand Down

0 comments on commit 2554ee2

Please sign in to comment.