Untested: properly expand lists of dictionaries
This commit is contained in:
parent
87db1e3478
commit
3a898edd34
1 changed files with 15 additions and 8 deletions
|
|
@ -227,17 +227,24 @@ def IsCurrent( window, buf ):
|
||||||
|
|
||||||
|
|
||||||
def ExpandReferencesInDict( obj, mapping, **kwargs ):
|
def ExpandReferencesInDict( obj, mapping, **kwargs ):
|
||||||
def expand_refs( s ):
|
def expand_refs_in_string( s ):
|
||||||
s = string.Template( s ).safe_substitute( mapping, **kwargs )
|
s = string.Template( s ).safe_substitute( mapping, **kwargs )
|
||||||
s = os.path.expanduser( s )
|
s = os.path.expanduser( s )
|
||||||
s = os.path.expandvars( s )
|
s = os.path.expandvars( s )
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def expand_refs_in_object( obj ):
|
||||||
|
if isinstance( obj, dict ):
|
||||||
|
ExpandReferencesInDict( obj, mapping, **kwargs )
|
||||||
|
elif isinstance( obj, list ):
|
||||||
|
for i, _ in enumerate( obj ):
|
||||||
|
# FIXME: We are assuming that it is a list of string, but could be a
|
||||||
|
# list of list of a list of dict, etc.
|
||||||
|
obj[ i ] = expand_refs_in_object( obj[ i ] )
|
||||||
|
elif isinstance( obj, str ):
|
||||||
|
obj = expand_refs_in_string( obj )
|
||||||
|
|
||||||
|
return obj
|
||||||
|
|
||||||
for k in obj.keys():
|
for k in obj.keys():
|
||||||
if isinstance( obj[ k ], dict ):
|
obj[ k ] = expand_refs_in_object( obj[ k ] )
|
||||||
ExpandReferencesInDict( obj[ k ], mapping, **kwargs )
|
|
||||||
elif isinstance( obj[ k ], list ):
|
|
||||||
for i, _ in enumerate( obj[ k ] ):
|
|
||||||
obj[ k ][ i ] = expand_refs( obj[ k ][ i ] )
|
|
||||||
elif isinstance( obj[ k ], str ):
|
|
||||||
obj[ k ] = expand_refs( obj[ k ] )
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue