<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import logging <EOL> import salt . utils <EOL> log = logging . getLogger ( __name__ ) <EOL> default_conf = '<STR_LIT>' <EOL> __func_alias__ = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if salt . utils . is_windows ( ) : <EOL> return ( False , '<STR_LIT>' ) <EOL> return True <EOL> def _parse_conf ( conf_file = default_conf ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> mode = '<STR_LIT>' <EOL> multi_names = [ ] <EOL> multi = { } <EOL> prev_comps = None <EOL> with salt . utils . fopen ( conf_file , '<STR_LIT:r>' ) as ifile : <EOL> for line in ifile : <EOL> line = line . strip ( ) <EOL> if not line : <EOL> continue <EOL> if line . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> comps = line . split ( ) <EOL> if '<STR_LIT:{>' in line and '<STR_LIT:}>' not in line : <EOL> mode = '<STR_LIT>' <EOL> if len ( comps ) == <NUM_LIT:1> and prev_comps : <EOL> multi_names = prev_comps <EOL> else : <EOL> multi_names = comps <EOL> multi_names . pop ( ) <EOL> continue <EOL> if '<STR_LIT:}>' in line : <EOL> mode = '<STR_LIT>' <EOL> for multi_name in multi_names : <EOL> ret [ multi_name ] = multi <EOL> multi_names = [ ] <EOL> multi = { } <EOL> continue <EOL> if mode == '<STR_LIT>' : <EOL> key = ret <EOL> else : <EOL> key = multi <EOL> if comps [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if '<STR_LIT>' not in ret : <EOL> ret [ '<STR_LIT>' ] = { } <EOL> for include in os . listdir ( comps [ <NUM_LIT:1> ] ) : <EOL> if include not in ret [ '<STR_LIT>' ] : <EOL> ret [ '<STR_LIT>' ] [ include ] = [ ] <EOL> include_path = '<STR_LIT>' . format ( comps [ <NUM_LIT:1> ] , include ) <EOL> include_conf = _parse_conf ( include_path ) <EOL> for file_key in include_conf : <EOL> ret [ file_key ] = include_conf [ file_key ] <EOL> ret [ '<STR_LIT>' ] [ include ] . append ( file_key ) <EOL> prev_comps = comps <EOL> if len ( comps ) > <NUM_LIT:1> : <EOL> key [ comps [ <NUM_LIT:0> ] ] = '<STR_LIT:U+0020>' . join ( comps [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> key [ comps [ <NUM_LIT:0> ] ] = True <EOL> return ret <EOL> def show_conf ( conf_file = default_conf ) : <EOL> '''<STR_LIT>''' <EOL> return _parse_conf ( conf_file ) <EOL> def set_ ( key , value , setting = None , conf_file = default_conf ) : <EOL> '''<STR_LIT>''' <EOL> conf = _parse_conf ( conf_file ) <EOL> for include in conf [ '<STR_LIT>' ] : <EOL> if key in conf [ '<STR_LIT>' ] [ include ] : <EOL> conf_file = os . path . join ( conf [ '<STR_LIT>' ] , include ) <EOL> if isinstance ( conf [ key ] , dict ) and not setting : <EOL> return ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( key ) <EOL> ) <EOL> if setting : <EOL> if isinstance ( conf [ key ] , str ) : <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> stanza = conf [ key ] <EOL> if value == '<STR_LIT:False>' : <EOL> del stanza [ value ] <EOL> else : <EOL> stanza [ value ] = setting <EOL> new_line = _dict_to_stanza ( key , stanza ) <EOL> log . debug ( stanza ) <EOL> log . debug ( new_line ) <EOL> log . debug ( key ) <EOL> __salt__ [ '<STR_LIT>' ] ( conf_file , <EOL> '<STR_LIT>' . format ( key ) , <EOL> new_line , <EOL> flags = <NUM_LIT> , <EOL> backup = False ) <EOL> else : <EOL> if value == '<STR_LIT:True>' : <EOL> new_line = key <EOL> elif value == '<STR_LIT:False>' : <EOL> new_line = '<STR_LIT>' <EOL> else : <EOL> new_line = '<STR_LIT>' . format ( key , value ) <EOL> log . debug ( conf_file ) <EOL> log . debug ( key ) <EOL> log . debug ( new_line ) <EOL> __salt__ [ '<STR_LIT>' ] ( conf_file , <EOL> '<STR_LIT>' . format ( key ) , <EOL> new_line , <EOL> flags = <NUM_LIT:8> , <EOL> backup = False ) <EOL> def _dict_to_stanza ( key , stanza ) : <EOL> '''<STR_LIT>''' <EOL> ret = '<STR_LIT>' <EOL> for skey in stanza : <EOL> if stanza [ skey ] is True : <EOL> stanza [ skey ] = '<STR_LIT>' <EOL> ret += '<STR_LIT>' . format ( skey , stanza [ skey ] ) <EOL> return '<STR_LIT>' . format ( key , ret ) </s>
