<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import difflib <EOL> import logging <EOL> import salt . utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def __virtual__ ( ) : <EOL> return '<STR_LIT>' if '<STR_LIT>' in __salt__ else False <EOL> def task_present ( name , <EOL> tick_script , <EOL> task_type = '<STR_LIT>' , <EOL> database = None , <EOL> retention_policy = '<STR_LIT:default>' , <EOL> enable = True ) : <EOL> '''<STR_LIT>''' <EOL> comments = [ ] <EOL> changes = [ ] <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT>' : { } , '<STR_LIT:result>' : True , '<STR_LIT>' : '<STR_LIT>' } <EOL> task = __salt__ [ '<STR_LIT>' ] ( name ) <EOL> old_script = task [ '<STR_LIT>' ] if task else '<STR_LIT>' <EOL> if tick_script . startswith ( '<STR_LIT>' ) : <EOL> script_path = __salt__ [ '<STR_LIT>' ] ( tick_script , __env__ ) <EOL> else : <EOL> script_path = tick_script <EOL> with salt . utils . fopen ( script_path , '<STR_LIT:r>' ) as file : <EOL> new_script = file . read ( ) <EOL> if old_script == new_script : <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> result = __salt__ [ '<STR_LIT>' ] ( name , script_path , <EOL> task_type = task_type , database = database , <EOL> retention_policy = retention_policy ) <EOL> ret [ '<STR_LIT:result>' ] = result [ '<STR_LIT:success>' ] <EOL> if not ret [ '<STR_LIT:result>' ] : <EOL> comments . append ( '<STR_LIT>' ) <EOL> if result . get ( '<STR_LIT>' ) : <EOL> comments . append ( result [ '<STR_LIT>' ] ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( comments ) <EOL> return ret <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( difflib . unified_diff ( <EOL> old_script . splitlines ( ) , <EOL> new_script . splitlines ( ) , <EOL> ) ) <EOL> comments . append ( '<STR_LIT>' ) <EOL> if enable : <EOL> if task and task [ '<STR_LIT>' ] : <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> result = __salt__ [ '<STR_LIT>' ] ( name ) <EOL> ret [ '<STR_LIT:result>' ] = result [ '<STR_LIT:success>' ] <EOL> if not ret [ '<STR_LIT:result>' ] : <EOL> comments . append ( '<STR_LIT>' ) <EOL> if result . get ( '<STR_LIT>' ) : <EOL> comments . append ( result [ '<STR_LIT>' ] ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( comments ) <EOL> return ret <EOL> comments . append ( '<STR_LIT>' ) <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { '<STR_LIT>' : False , '<STR_LIT>' : True } <EOL> else : <EOL> if task and not task [ '<STR_LIT>' ] : <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> result = __salt__ [ '<STR_LIT>' ] ( name ) <EOL> ret [ '<STR_LIT:result>' ] = result [ '<STR_LIT:success>' ] <EOL> if not ret [ '<STR_LIT:result>' ] : <EOL> comments . append ( '<STR_LIT>' ) <EOL> if result . get ( '<STR_LIT>' ) : <EOL> comments . append ( result [ '<STR_LIT>' ] ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( comments ) <EOL> return ret <EOL> comments . append ( '<STR_LIT>' ) <EOL> ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { '<STR_LIT>' : True , '<STR_LIT>' : False } <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( comments ) <EOL> return ret <EOL> def task_absent ( name ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , '<STR_LIT>' : { } , '<STR_LIT:result>' : True , '<STR_LIT>' : '<STR_LIT>' } <EOL> task = __salt__ [ '<STR_LIT>' ] ( name ) <EOL> if task : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT:result>' ] = None <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> result = __salt__ [ '<STR_LIT>' ] ( name ) <EOL> ret [ '<STR_LIT:result>' ] = result [ '<STR_LIT:success>' ] <EOL> if not ret [ '<STR_LIT:result>' ] : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if result . get ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT>' ] += '<STR_LIT:\n>' + result [ '<STR_LIT>' ] <EOL> return ret <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ret [ '<STR_LIT>' ] [ name ] = '<STR_LIT>' <EOL> else : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return ret </s>
