<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import logging <EOL> import salt . ext . six as six <EOL> from salt . ext . six . moves import map <EOL> import salt . utils <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> __func_alias__ = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' and os . path . exists ( '<STR_LIT>' ) : <EOL> krel = list ( list ( map ( int , __grains__ [ '<STR_LIT>' ] . split ( '<STR_LIT:.>' ) ) ) ) <EOL> if krel [ <NUM_LIT:0> ] > <NUM_LIT:5> or ( krel [ <NUM_LIT:0> ] == <NUM_LIT:5> and krel [ <NUM_LIT:1> ] > <NUM_LIT:0> ) : <EOL> if not os . path . exists ( '<STR_LIT>' ) : <EOL> return __virtualname__ <EOL> return ( False , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def start ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( name ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> def stop ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( name ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> def restart ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( name ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> def status ( name , sig = None ) : <EOL> '''<STR_LIT>''' <EOL> if sig : <EOL> return bool ( __salt__ [ '<STR_LIT>' ] ( sig ) ) <EOL> cmd = '<STR_LIT>' . format ( name ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> def reload_ ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( name ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> import re <EOL> service_flags_regex = re . compile ( r'<STR_LIT>' ) <EOL> pkg_scripts_regex = re . compile ( r'<STR_LIT>' ) <EOL> start_daemon_call_regex = re . compile ( r'<STR_LIT>' ) <EOL> start_daemon_parameter_regex = re . compile ( r'<STR_LIT>' ) <EOL> def _get_rc ( ) : <EOL> '''<STR_LIT>''' <EOL> daemons_flags = { } <EOL> try : <EOL> with salt . utils . fopen ( '<STR_LIT>' , '<STR_LIT:r>' ) as handle : <EOL> lines = handle . readlines ( ) <EOL> except IOError : <EOL> log . error ( '<STR_LIT>' ) <EOL> else : <EOL> for line in lines : <EOL> match = start_daemon_call_regex . match ( line ) <EOL> if match : <EOL> line = line [ len ( match . group ( <NUM_LIT:1> ) ) : ] <EOL> for daemon in start_daemon_parameter_regex . findall ( line ) : <EOL> daemons_flags [ daemon ] = True <EOL> variables = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , <EOL> clean_env = True , <EOL> output_loglevel = '<STR_LIT>' , <EOL> python_shell = True ) . split ( '<STR_LIT:\n>' ) <EOL> for var in variables : <EOL> match = service_flags_regex . match ( var ) <EOL> if match : <EOL> if match . group ( <NUM_LIT:2> ) == '<STR_LIT>' : <EOL> daemons_flags [ match . group ( <NUM_LIT:1> ) ] = False <EOL> else : <EOL> match = pkg_scripts_regex . match ( var ) <EOL> if match : <EOL> for daemon in match . group ( <NUM_LIT:1> ) . split ( ) : <EOL> daemons_flags [ daemon ] = True <EOL> return daemons_flags <EOL> def available ( name ) : <EOL> '''<STR_LIT>''' <EOL> path = '<STR_LIT>' . format ( name ) <EOL> return os . path . isfile ( path ) and os . access ( path , os . X_OK ) <EOL> def missing ( name ) : <EOL> '''<STR_LIT>''' <EOL> return not available ( name ) <EOL> def get_all ( ) : <EOL> '''<STR_LIT>''' <EOL> services = [ ] <EOL> if not os . path . isdir ( '<STR_LIT>' ) : <EOL> return services <EOL> for service in os . listdir ( '<STR_LIT>' ) : <EOL> if available ( service ) : <EOL> services . append ( service ) <EOL> return sorted ( services ) <EOL> def get_enabled ( ) : <EOL> '''<STR_LIT>''' <EOL> services = [ ] <EOL> for daemon , is_enabled in six . iteritems ( _get_rc ( ) ) : <EOL> if is_enabled : <EOL> services . append ( daemon ) <EOL> return sorted ( set ( get_all ( ) ) & set ( services ) ) <EOL> def enabled ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return name in get_enabled ( ) <EOL> def get_disabled ( ) : <EOL> '''<STR_LIT>''' <EOL> services = [ ] <EOL> for daemon , is_enabled in six . iteritems ( _get_rc ( ) ) : <EOL> if not is_enabled : <EOL> services . append ( daemon ) <EOL> return sorted ( set ( get_all ( ) ) & set ( services ) ) <EOL> def disabled ( name ) : <EOL> '''<STR_LIT>''' <EOL> return name in get_disabled ( ) </s>
