<commit_before># -*- coding: utf-8 -*-
'''
Interface to Red Hat tuned-adm module

:maintainer:    <NAME> <<EMAIL>>
:maturity:      new
:depends:       tuned-adm
:platform:      Linux
'''

# Import Python libs
from __future__ import absolute_import
import re

# Import Salt libs
import salt.utils

__func_alias__ = {
    'list_': 'list',
}

__virtualname__ = 'tuned'


def __virtual__():
    '''
    Check to see if tuned-adm binary is installed on the system

    '''
    tuned_adm = salt.utils.which('tuned-adm')
    if not tuned_adm:
        return (False, 'The tuned execution module failed to load: the tuned-adm binary is not in the path.')
    return __virtualname__


def list_():
    '''
    List the profiles available

    CLI Example:

    .. code-block:: bash

        salt '*' tuned.list
    '''

    result = __salt__['cmd.run']('tuned-adm list').splitlines()
    result.pop(0)
    result.pop()
    result = [i.lstrip('- ') for i in result]
    return result


def active():
    '''
    Return current active profile

    CLI Example:

    .. code-block:: bash

        salt '*' tuned.active
    '''

    # turn off all profiles
    result = __salt__['cmd.run']('tuned-adm active')
    pattern = re.compile(r'''(?P<stmt>Current active profile:) (?P<profile>\w+.*)''')
    match = re.match(pattern, result)<commit_msg>Enh: Support new version of tuned-adm binary<commit_after># -*- coding: utf-8 -*-
'''
Interface to Red Hat tuned-adm module

:maintainer:    <NAME> <<EMAIL>>
:maturity:      new
:depends:       tuned-adm
:platform:      Linux
'''

# Import Python libs
from __future__ import absolute_import
import re

# Import Salt libs
import salt.utils

__func_alias__ = {
    'list_': 'list',
}

__virtualname__ = 'tuned'


def __virtual__():
    '''
    Check to see if tuned-adm binary is installed on the system

    '''
    tuned_adm = salt.utils.which('tuned-adm')
    if not tuned_adm:
        return (False, 'The tuned execution module failed to load: the tuned-adm binary is not in the path.')
    return __virtualname__


def list_():
    '''
    List the profiles available

    CLI Example:

    .. code-block:: bash

        salt '*' tuned.list
    '''

    result = __salt__['cmd.run']('tuned-adm list').splitlines()
    # Remove "Available profiles:"
    result.pop(0)
    # Remove "Current active profile:.*"
    result.pop()
    # Output can be : " - <profile name> - <description>" (v2.7.1)
    # or " - <profile name> " (v2.4.1)
    result = [i.split('-')[1].strip() for i in result]
    return result


def active():
    '''
    Return current active profile

    CLI Example:

    .. code-block:: bash

        salt '*' tuned.active
    '''

    # turn off all profiles
    result = __salt__['cmd.run']('tuned-adm active')
    pattern = re.compile(r'''(?P<stmt>Current active profile:) (?P<profile>\w+.*)''')
    match = re.match(pattern, result)
{'fraction_non_alphanumeric': 0.14251040221914008, 'fraction_numerical': 0.0038141470180305132, 'mean_word_length': 2.74189364461738, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3910242', 'n_tokens_mistral': 1004, 'n_tokens_neox': 922, 'n_words': 275}