#NEWLINE# def showconfig( name , default = False , dict_return = False ) : #NEWLINE# #INDENT# "\n    Show the configuration options for a given port.\n\n    default : False\n        Show the default options for a port (not necessarily the same as the\n        current configuration)\n\n    dict_return : False\n        Instead of returning the output of ``make showconfig``, return the data\n        in an dictionary\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' ports.showconfig security/nmap\n        salt '*' ports.showconfig security/nmap default=True\n    " #NEWLINE# portpath = _check_portname ( name ) #NEWLINE# if ( default and _options_file_exists ( name ) ) : #NEWLINE# #INDENT# saved_config = showconfig ( name , default = False , dict_return = True ) #NEWLINE# rmconfig ( name ) #NEWLINE# if _options_file_exists ( name ) : #NEWLINE# #INDENT# raise CommandExecutionError ( 'Unable to get default configuration' ) #NEWLINE# #UNINDENT# default_config = showconfig ( name , default = False , dict_return = dict_return ) #NEWLINE# _write_options ( name , saved_config ) #NEWLINE# return default_config #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# result = __salt__ [ 'cmd.run_all' ] ( [ 'make' , 'showconfig' ] , cwd = portpath , python_shell = False ) #NEWLINE# output = result [ 'stdout' ] . splitlines ( ) #NEWLINE# if ( result [ 'retcode' ] != 0 ) : #NEWLINE# #INDENT# error = result [ 'stderr' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# error = '' #NEWLINE# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# error = result #NEWLINE# #UNINDENT# if error : #NEWLINE# #INDENT# msg = "Error running 'make showconfig' for {0}: {1}" . format ( name , error ) #NEWLINE# log . error ( msg ) #NEWLINE# raise SaltInvocationError ( msg ) #NEWLINE# #UNINDENT# if ( not dict_return ) : #NEWLINE# #INDENT# return '\n' . join ( output ) #NEWLINE# #UNINDENT# if ( ( not output ) or ( 'configuration options' not in output [ 0 ] ) ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# pkg = output [ 0 ] . split ( ) [ ( - 1 ) ] . rstrip ( ':' ) #NEWLINE# #UNINDENT# except ( IndexError , AttributeError , TypeError ) as exc : #NEWLINE# #INDENT# log . error ( 'Unable to get pkg-version string: {0}' . format ( exc ) ) #NEWLINE# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ret = { #NEWLINE# #INDENT# pkg : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# output = output [ 1 : ] #NEWLINE# for line in output : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( opt , val , desc ) = re . match ( '\\s+([^=]+)=(off|on): (.+)' , line ) . groups ( ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ret [ pkg ] [ opt ] = val #NEWLINE# #UNINDENT# if ( not ret [ pkg ] ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# return ret