Expand references in non-shell variables too
This commit is contained in:
parent
bbaab0ebc1
commit
8a57104a0e
1 changed files with 49 additions and 48 deletions
|
|
@ -323,11 +323,20 @@ def SetBufferContents( buf, lines, modified=False ):
|
|||
def IsCurrent( window, buf ):
|
||||
return vim.current.window == window and vim.current.window.buffer == buf
|
||||
|
||||
def ExpandReferencesInObject( obj, mapping, user_choices ):
|
||||
if isinstance( obj, dict ):
|
||||
ExpandReferencesInDict( obj, mapping, user_choices )
|
||||
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 ] = ExpandReferencesInObject( obj[ i ], mapping, user_choices )
|
||||
elif isinstance( obj, str ):
|
||||
obj = ExpandReferencesInString( obj, mapping, user_choices )
|
||||
|
||||
# TODO: Should we just run the substitution on the whole JSON string instead?
|
||||
# That woul dallow expansion in bool and number values, such as ports etc. ?
|
||||
def ExpandReferencesInDict( obj, mapping, user_choices ):
|
||||
def expand_refs_in_string( orig_s ):
|
||||
return obj
|
||||
|
||||
def ExpandReferencesInString( orig_s, mapping, user_choices):
|
||||
s = os.path.expanduser( orig_s )
|
||||
s = os.path.expandvars( s )
|
||||
|
||||
|
|
@ -360,21 +369,11 @@ def ExpandReferencesInDict( obj, mapping, user_choices ):
|
|||
|
||||
return s
|
||||
|
||||
def expand_refs_in_object( obj ):
|
||||
if isinstance( obj, dict ):
|
||||
ExpandReferencesInDict( obj, mapping, user_choices )
|
||||
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
|
||||
|
||||
# TODO: Should we just run the substitution on the whole JSON string instead?
|
||||
# That woul dallow expansion in bool and number values, such as ports etc. ?
|
||||
def ExpandReferencesInDict( obj, mapping, user_choices ):
|
||||
for k in obj.keys():
|
||||
obj[ k ] = expand_refs_in_object( obj[ k ] )
|
||||
obj[ k ] = ExpandReferencesInObject( obj[ k ], mapping, user_choices )
|
||||
|
||||
|
||||
def ParseVariables( variables_list, mapping, user_choices ):
|
||||
|
|
@ -416,7 +415,9 @@ def ParseVariables( variables_list, mapping, user_choices ):
|
|||
raise ValueError(
|
||||
"Unsupported variable defn {}: Missing 'shell'".format( n ) )
|
||||
else:
|
||||
new_variables[ n ] = v
|
||||
new_variables[ n ] = ExpandReferencesInObject( v,
|
||||
mapping,
|
||||
user_choices )
|
||||
|
||||
return new_variables
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue