<commit_before><commit_msg>Initial commit for state management - yes, it needs a lot of work, this is experimental so that the data input model can be developed<commit_after>'''
State enforcing for pacman packages
'''

import salt.modules.pacman as pacman

__virtual__ = pacman.__virtual__

def install(name):
    '''
    Verify that the package is installed, return the packages changed in the
    operation and a bool if the job was sucessfull
    '''
    if pacman.version(name):
        return {'changes': {},
                'result': True,
                'comment': 'The package is already installed'}
    changes = pacman.install(name)
    if not changes:
        return {'changes': changes,
                'result': False,
                'comment': 'The package failed to install'}
    return {'changes': changes,
            'result': True,
            'commant': 'Package installed'}

def latest(name):
    '''
    Verify that the latest package is installed
    '''
    version = pacman.version(name)
    avail = pacman.available_version(name)
    if avail > version:
        changes = pacman.install(name, True)
    if not changes:
        return {'changes': changes,
                'result': False,
                'comment': 'The package failed to install'}
    return {'changes': changes,
            'result': True,
            'commant': 'Package installed'}

def remove(name):
    '''
    Verify that the package is removed
    '''
    if not pacman.version(name):
        return {'changes': {},
                'result': True,
                'comment': 'The package is not installed'}
    else:
        changes = pacman.remove(name)
    if not changes:
        return {'changes': changes,
                'result': False,
                'comment': 'The package failed to remove'}
    return {'changes': changes,
            'result': True,
            'commant': 'Package removed'}

def purge(name):
    '''
    Verify that the package is purged
    '''
    if not pacman.version(name):
        return {'changes': {},
                'result': True,
                'comment': 'The package is not installed'}
    else:
        changes = pacman.purge(name)
    if not changes:
        return {'changes': changes,
                'result': False,
                'comment': 'The package failed to purge'}
    return {'changes': changes,
            'result': True,
            'commant': 'Package purged'}

{'fraction_non_alphanumeric': 0.11198023878139152, 'fraction_numerical': 0.0, 'mean_word_length': 2.083756345177665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6053162', 'n_tokens_mistral': 632, 'n_tokens_neox': 626, 'n_words': 227}