<commit_before>'''
Module for managing logrotate.
'''

# Import python libs
import os
import logging

# Import salt libs
import salt.utils

log = logging.getLogger(__name__)
default_conf = '/etc/logrotate.conf'


def __virtual__():
    '''
    Only work on POSIX-like systems
    '''
    # Disable on these platforms
    disable = ('Windows',)
    if __grains__['os'] in disable:
        return False
    return 'logrotate'


def _parse_conf(conf_file=default_conf):
    '''
    Parse a logrotate configuration file.

    Includes will also be parsed, and their configuration will be stored in the
    return dict, as if they were part of the main config file. A dict of which
    configs came from which includes will be stored in the 'include files' dict
    inside the return dict, for later reference by the user or module.
    '''
    ret = {}
    mode = 'single'
    multi_name = ''
    multi = {}
    with salt.utils.fopen(conf_file, 'r') as ifile:
        for line in ifile.readlines():
            if not line.strip():
                continue
            if line.strip().startswith('#'):
                continue

            comps = line.strip().split()
            if '{' in line and '}' not in line:
                mode = 'multi'
                multi_name = comps[0]
                continue
            if '}' in line:
                mode = 'single'<commit_msg>logrotate._parse_conf: avoid readlines(); only strip() once<commit_after>'''
Module for managing logrotate.
'''

# Import python libs
import os
import logging

# Import salt libs
import salt.utils

log = logging.getLogger(__name__)
default_conf = '/etc/logrotate.conf'


def __virtual__():
    '''
    Only work on POSIX-like systems
    '''
    # Disable on these platforms
    disable = ('Windows',)
    if __grains__['os'] in disable:
        return False
    return 'logrotate'


def _parse_conf(conf_file=default_conf):
    '''
    Parse a logrotate configuration file.

    Includes will also be parsed, and their configuration will be stored in the
    return dict, as if they were part of the main config file. A dict of which
    configs came from which includes will be stored in the 'include files' dict
    inside the return dict, for later reference by the user or module.
    '''
    ret = {}
    mode = 'single'
    multi_name = ''
    multi = {}
    with salt.utils.fopen(conf_file, 'r') as ifile:
        for line in ifile:
            line = line.strip()
            if not line:
                continue
            if line.startswith('#'):
                continue

            comps = line.split()
            if '{' in line and '}' not in line:
                mode = 'multi'
                multi_name = comps[0]
                continue
            if '}' in line:
                mode = 'single'
{'fraction_non_alphanumeric': 0.09256611865618299, 'fraction_numerical': 0.0007147962830593281, 'mean_word_length': 2.0996677740863787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '741308', 'n_tokens_mistral': 786, 'n_tokens_neox': 763, 'n_words': 292}