#NEWLINE# def present( name , value = None , contains = None , excludes = None ) : #NEWLINE# #INDENT# '\n    Verify that the variable is in the ``make.conf`` and has the provided\n    settings. If value is set, contains and excludes will be ignored.\n\n    name\n        The variable name. This will automatically be converted to upper\n        case since variables in ``make.conf`` are in upper case\n\n    value\n        Enforce that the value of the variable is set to the provided value\n\n    contains\n        Enforce that the value of the variable contains the provided value\n\n    excludes\n        Enforce that the value of the variable does not contain the provided\n        value.\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'comment' : '' , #NEWLINE# 'name' : name , #NEWLINE# 'result' : True , #NEWLINE# #UNINDENT# } #NEWLINE# upper_name = name . upper ( ) #NEWLINE# old_value = __salt__ [ 'makeconf.get_var' ] ( upper_name ) #NEWLINE# if ( ( value is None ) and ( contains is None ) and ( excludes is None ) ) : #NEWLINE# #INDENT# if ( old_value is not None ) : #NEWLINE# #INDENT# msg = 'Variable {0} is already present in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = 'Variable {0} is to be set in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# changes = __salt__ [ 'makeconf.set_var' ] ( upper_name , '' ) #NEWLINE# if ( changes [ upper_name ] [ 'new' ] is None ) : #NEWLINE# #INDENT# msg = 'Variable {0} failed to be set in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# ret [ 'result' ] = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = 'Variable {0} set in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( value is not None ) : #NEWLINE# #INDENT# if ( ( old_value is not None ) and ( old_value == value ) ) : #NEWLINE# #INDENT# msg = 'Variable {0} is already "{1}" in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name , value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = 'Variable {0} is to be set to "{1}" in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name , value ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# changes = __salt__ [ 'makeconf.set_var' ] ( upper_name , value ) #NEWLINE# new_value = __salt__ [ 'makeconf.get_var' ] ( upper_name ) #NEWLINE# if ( ( new_value is None ) or ( new_value != value ) ) : #NEWLINE# #INDENT# msg = 'Variable {0} failed to be set in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# ret [ 'result' ] = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = 'Variable {0} is set in make.conf' #NEWLINE# ret [ 'changes' ] = changes #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( contains is not None ) or ( excludes is not None ) ) : #NEWLINE# #INDENT# contains_set = _make_set ( contains ) #NEWLINE# excludes_set = _make_set ( excludes ) #NEWLINE# old_value_set = _make_set ( old_value ) #NEWLINE# if ( len ( contains_set . intersection ( excludes_set ) ) > 0 ) : #NEWLINE# #INDENT# msg = 'Variable {0} cannot contain and exclude the same value' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# ret [ 'result' ] = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# to_append = set ( ) #NEWLINE# to_trim = set ( ) #NEWLINE# if ( contains is not None ) : #NEWLINE# #INDENT# to_append = contains_set . difference ( old_value_set ) #NEWLINE# #UNINDENT# if ( excludes is not None ) : #NEWLINE# #INDENT# to_trim = excludes_set . intersection ( old_value_set ) #NEWLINE# #UNINDENT# if ( ( len ( to_append ) == 0 ) and ( len ( to_trim ) == 0 ) ) : #NEWLINE# #INDENT# msg = 'Variable {0} is correct in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = 'Variable {0} is set to' . format ( name ) #NEWLINE# if ( len ( to_append ) > 0 ) : #NEWLINE# #INDENT# msg += ' append "{0}"' . format ( list ( to_append ) ) #NEWLINE# #UNINDENT# if ( len ( to_trim ) > 0 ) : #NEWLINE# #INDENT# msg += ' trim "{0}"' . format ( list ( to_trim ) ) #NEWLINE# #UNINDENT# msg += ' in make.conf' #NEWLINE# ret [ 'comment' ] = msg #NEWLINE# ret [ 'result' ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for value in to_append : #NEWLINE# #INDENT# __salt__ [ 'makeconf.append_var' ] ( upper_name , value ) #NEWLINE# #UNINDENT# for value in to_trim : #NEWLINE# #INDENT# __salt__ [ 'makeconf.trim_var' ] ( upper_name , value ) #NEWLINE# #UNINDENT# new_value = __salt__ [ 'makeconf.get_var' ] ( upper_name ) #NEWLINE# ret [ 'changes' ] = { #NEWLINE# #INDENT# upper_name : { #NEWLINE# #INDENT# 'old' : old_value , #NEWLINE# 'new' : new_value , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# msg = 'Variable {0} is correct in make.conf' #NEWLINE# ret [ 'comment' ] = msg . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ret