<s> import logging <EOL> from vint . linting . level import is_level_enabled <EOL> import vint . linting . policy_registry as policy_registry <EOL> class PolicySet ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _all_policies_map = self . _create_all_policies_map ( ) <EOL> self . enabled_policies = [ ] <EOL> def _create_all_policies_map ( self ) : <EOL> policy_class_map = policy_registry . get_policy_class_map ( ) <EOL> policy_map = { policy_name : PolicyClass ( ) <EOL> for policy_name , PolicyClass <EOL> in policy_class_map . items ( ) } <EOL> return policy_map <EOL> def _is_policy_exists ( self , name ) : <EOL> return name in self . _all_policies_map <EOL> def _get_policy ( self , name ) : <EOL> return self . _all_policies_map [ name ] <EOL> def _warn_unexistent_policy ( self , policy_name ) : <EOL> logging . warning ( '<STR_LIT>' . format ( <EOL> name = policy_name ) ) <EOL> def _log_severity ( self , config_dict ) : <EOL> level_name = config_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . name <EOL> logging . debug ( '<STR_LIT>' . format ( level = level_name ) ) <EOL> def _get_enabling_map ( self , config_dict ) : <EOL> self . _log_severity ( config_dict ) <EOL> severity = config_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> policy_enabling_map = { } <EOL> for policy_name , policy in self . _all_policies_map . items ( ) : <EOL> policy_enabling_map [ policy_name ] = is_level_enabled ( policy . level , severity ) <EOL> prior_policy_enabling_map = config_dict [ '<STR_LIT>' ] <EOL> for policy_name , policy in prior_policy_enabling_map . items ( ) : <EOL> if '<STR_LIT>' in policy : <EOL> policy_enabling_map [ policy_name ] = policy [ '<STR_LIT>' ] <EOL> return policy_enabling_map <EOL> def update_by_config ( self , config_dict ) : <EOL> """<STR_LIT>""" <EOL> policy_enabling_map = self . _get_enabling_map ( config_dict ) <EOL> self . enabled_policies = [ ] <EOL> for policy_name , is_policy_enabled in policy_enabling_map . items ( ) : <EOL> if not self . _is_policy_exists ( policy_name ) : <EOL> self . _warn_unexistent_policy ( policy_name ) <EOL> continue <EOL> if is_policy_enabled : <EOL> enabled_policy = self . _get_policy ( policy_name ) <EOL> self . enabled_policies . append ( enabled_policy ) <EOL> self . _log_policy_status ( policy_name , is_policy_enabled ) <EOL> def get_enabled_policies ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . enabled_policies <EOL> def _log_policy_status ( self , policy_name , enabled ) : <EOL> status = '<STR_LIT>' if enabled else '<STR_LIT>' <EOL> logging . debug ( '<STR_LIT>' . format ( status = status , <EOL> policy_name = policy_name ) ) </s>
