<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import fnmatch <EOL> import yaml <EOL> import os <EOL> import copy <EOL> import salt . utils <EOL> from distutils . version import LooseVersion <EOL> log = logging . getLogger ( __name__ ) <EOL> def __virtual__ ( ) : <EOL> if salt . utils . is_windows ( ) : <EOL> return False , '<STR_LIT>' <EOL> return True <EOL> def audit ( data_list , tags , verbose = False ) : <EOL> '''<STR_LIT>''' <EOL> __data__ = { } <EOL> for data in data_list : <EOL> _merge_yaml ( __data__ , data ) <EOL> __tags__ = _get_tags ( __data__ ) <EOL> log . trace ( '<STR_LIT>' ) <EOL> log . trace ( __data__ ) <EOL> log . trace ( '<STR_LIT>' ) <EOL> log . trace ( __tags__ ) <EOL> ret = { '<STR_LIT>' : [ ] , '<STR_LIT>' : [ ] } <EOL> for tag in __tags__ : <EOL> if fnmatch . fnmatch ( tag , tags ) : <EOL> for tag_data in __tags__ [ tag ] : <EOL> name = tag_data [ '<STR_LIT:name>' ] <EOL> audittype = tag_data [ '<STR_LIT:type>' ] <EOL> if audittype == '<STR_LIT>' : <EOL> if __salt__ [ '<STR_LIT>' ] ( name ) : <EOL> ret [ '<STR_LIT>' ] . append ( tag_data ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] . append ( tag_data ) <EOL> elif audittype == '<STR_LIT>' : <EOL> if __salt__ [ '<STR_LIT>' ] ( name ) : <EOL> ret [ '<STR_LIT>' ] . append ( tag_data ) <EOL> else : <EOL> ret [ '<STR_LIT>' ] . append ( tag_data ) <EOL> if not verbose : <EOL> failure = [ ] <EOL> success = [ ] <EOL> tags_descriptions = set ( ) <EOL> for tag_data in ret [ '<STR_LIT>' ] : <EOL> tag = tag_data [ '<STR_LIT>' ] <EOL> description = tag_data . get ( '<STR_LIT:description>' ) <EOL> if ( tag , description ) not in tags_descriptions : <EOL> failure . append ( { tag : description } ) <EOL> tags_descriptions . add ( ( tag , description ) ) <EOL> tags_descriptions = set ( ) <EOL> for tag_data in ret [ '<STR_LIT>' ] : <EOL> tag = tag_data [ '<STR_LIT>' ] <EOL> description = tag_data . get ( '<STR_LIT:description>' ) <EOL> if ( tag , description ) not in tags_descriptions : <EOL> success . append ( { tag : description } ) <EOL> tags_descriptions . add ( ( tag , description ) ) <EOL> ret [ '<STR_LIT>' ] = success <EOL> ret [ '<STR_LIT>' ] = failure <EOL> return ret <EOL> def _merge_yaml ( ret , data ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' not in ret : <EOL> ret [ '<STR_LIT>' ] = { } <EOL> for topkey in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if topkey in data . get ( '<STR_LIT>' , { } ) : <EOL> if topkey not in ret [ '<STR_LIT>' ] : <EOL> ret [ '<STR_LIT>' ] [ topkey ] = [ ] <EOL> for key , val in data [ '<STR_LIT>' ] [ topkey ] . iteritems ( ) : <EOL> ret [ '<STR_LIT>' ] [ topkey ] . append ( { key : val } ) <EOL> return ret <EOL> def _get_tags ( data ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> distro = __grains__ . get ( '<STR_LIT>' ) <EOL> for toplist , toplevel in data . get ( '<STR_LIT>' , { } ) . iteritems ( ) : <EOL> for audit_dict in toplevel : <EOL> for audit_id , audit_data in audit_dict . iteritems ( ) : <EOL> tags_dict = audit_data . get ( '<STR_LIT:data>' , { } ) <EOL> tags = tags_dict . get ( distro , tags_dict . get ( '<STR_LIT:*>' , [ ] ) ) <EOL> if isinstance ( tags , dict ) : <EOL> tmp = [ ] <EOL> for name , tag in tags . iteritems ( ) : <EOL> tmp . append ( { name : tag } ) <EOL> tags = tmp <EOL> for item in tags : <EOL> for name , tag in item . iteritems ( ) : <EOL> if tag not in ret : <EOL> ret [ tag ] = [ ] <EOL> formatted_data = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : tag , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : toplist } <EOL> formatted_data . update ( audit_data ) <EOL> formatted_data . pop ( '<STR_LIT:data>' ) <EOL> ret [ tag ] . append ( formatted_data ) <EOL> return ret </s>
