<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import salt . utils <EOL> import salt . utils . decorators as decorators <EOL> from salt . exceptions import CommandExecutionError <EOL> __virtualname__ = '<STR_LIT>' <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if os . path . exists ( _detect_conf ( ) ) : <EOL> return __virtualname__ <EOL> return ( False , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ decorators . memoize <EOL> def _detect_conf ( ) : <EOL> '''<STR_LIT>''' <EOL> if __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def version ( ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' <EOL> out = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> return out <EOL> def conf ( ) : <EOL> '''<STR_LIT>''' <EOL> stanza = '<STR_LIT>' <EOL> stanzas = [ ] <EOL> in_stanza = False <EOL> ret = { } <EOL> pos = <NUM_LIT:0> <EOL> try : <EOL> with salt . utils . fopen ( _detect_conf ( ) , '<STR_LIT:r>' ) as _fp : <EOL> for line in _fp : <EOL> if line . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> if line . startswith ( '<STR_LIT:\n>' ) : <EOL> in_stanza = False <EOL> if '<STR_LIT:title>' in stanza : <EOL> stanza += '<STR_LIT>' . format ( pos ) <EOL> pos += <NUM_LIT:1> <EOL> stanzas . append ( stanza ) <EOL> stanza = '<STR_LIT>' <EOL> continue <EOL> if line . strip ( ) . startswith ( '<STR_LIT:title>' ) : <EOL> if in_stanza : <EOL> stanza += '<STR_LIT>' . format ( pos ) <EOL> pos += <NUM_LIT:1> <EOL> stanzas . append ( stanza ) <EOL> stanza = '<STR_LIT>' <EOL> else : <EOL> in_stanza = True <EOL> if in_stanza : <EOL> stanza += line <EOL> if not in_stanza : <EOL> key , value = _parse_line ( line ) <EOL> ret [ key ] = value <EOL> if in_stanza : <EOL> if not line . endswith ( '<STR_LIT:\n>' ) : <EOL> line += '<STR_LIT:\n>' <EOL> stanza += line <EOL> stanza += '<STR_LIT>' . format ( pos ) <EOL> pos += <NUM_LIT:1> <EOL> stanzas . append ( stanza ) <EOL> except ( IOError , OSError ) as exc : <EOL> msg = "<STR_LIT>" <EOL> raise CommandExecutionError ( msg . format ( str ( exc ) ) ) <EOL> ret [ '<STR_LIT>' ] = [ ] <EOL> for stanza in stanzas : <EOL> mydict = { } <EOL> for line in stanza . strip ( ) . splitlines ( ) : <EOL> key , value = _parse_line ( line ) <EOL> mydict [ key ] = value <EOL> ret [ '<STR_LIT>' ] . append ( mydict ) <EOL> return ret <EOL> def _parse_line ( line = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> parts = line . split ( ) <EOL> key = parts . pop ( <NUM_LIT:0> ) <EOL> value = '<STR_LIT:U+0020>' . join ( parts ) <EOL> return key , value </s>
