<commit_before># -*- coding: utf-8 -*-
'''
Module for managing PowerShell through PowerShellGet (PSGet)

:depends:
    - PowerShell 5.0
    - PSGet

Support for PowerShell
'''
from __future__ import absolute_import, print_function, unicode_literals

# Import Python libs
import logging
import xml.etree.ElementTree

# Import Salt libs
import salt.utils.platform
import salt.utils.versions
from salt.exceptions import CommandExecutionError

# Set up logging
log = logging.getLogger(__name__)

# Define the module's virtual name
__virtualname__ = 'psget'


def __virtual__():
    '''
    Set the system module of the kernel is Windows
    '''
    # Verify Windows
    if not salt.utils.platform.is_windows():
        log.debug('Module PSGet: Only available on Windows systems')
        return False, 'Module PSGet: Only available on Windows systems'

    # Verify PowerShell
    powershell_info = __salt__['cmd.shell_info']('powershell')
    if not powershell_info['installed']:
        log.debug('Module PSGet: Requires PowerShell')
        return False, 'Module PSGet: Requires PowerShell'

    # Verify PowerShell 5.0 or greater
    if salt.utils.versions.compare(powershell_info['version'], '<', '5.0'):
        log.debug('Module PSGet: Requires PowerShell 5 or newer')
        return False, 'Module PSGet: Requires PowerShell 5 or newer.'

    return __virtualname__


def _ps_xml_to_dict(parent, dic=None):
    '''
    Formats powershell Xml to a dict.
    Note: This _ps_xml_to_dict is not perfect with powershell Xml.
    '''

    if dic is None:
        dic = {}

    for child in parent:
        if list(child):
            new_dic = _ps_xml_to_dict(child, {})
            if "Name" in new_dic:
                dic[new_dic["Name"]] = new_dic
            else:
                try:
                    dic[[name for ps_type, name in child.items() if ps_type == "Type"][0]] = new_dic
                except IndexError:
                    dic[child.text] = new_dic
        else:
            for xml_type, name in child.items():
                if xml_type == "Name":
                    dic[name] = child.text

    return dic


def _pshell(cmd, cwd=None, depth=2):<commit_msg>win_psget Json to Xml fix<commit_after># -*- coding: utf-8 -*-
'''
Module for managing PowerShell through PowerShellGet (PSGet)

:depends:
    - PowerShell 5.0
    - PSGet

Support for PowerShell
'''
from __future__ import absolute_import, print_function, unicode_literals

# Import Python libs
import logging
import xml.etree.ElementTree

# Import Salt libs
import salt.utils.platform
import salt.utils.versions
from salt.exceptions import CommandExecutionError

# Set up logging
log = logging.getLogger(__name__)

# Define the module's virtual name
__virtualname__ = 'psget'


def __virtual__():
    '''
    Set the system module of the kernel is Windows
    '''
    # Verify Windows
    if not salt.utils.platform.is_windows():
        log.debug('Module PSGet: Only available on Windows systems')
        return False, 'Module PSGet: Only available on Windows systems'

    # Verify PowerShell
    powershell_info = __salt__['cmd.shell_info']('powershell')
    if not powershell_info['installed']:
        log.debug('Module PSGet: Requires PowerShell')
        return False, 'Module PSGet: Requires PowerShell'

    # Verify PowerShell 5.0 or greater
    if salt.utils.versions.compare(powershell_info['version'], '<', '5.0'):
        log.debug('Module PSGet: Requires PowerShell 5 or newer')
        return False, 'Module PSGet: Requires PowerShell 5 or newer.'

    return __virtualname__


def _ps_xml_to_dict(parent, dic=None):
    '''
    Formats powershell Xml to a dict.
    Note: This _ps_xml_to_dict is not perfect with powershell Xml.
    '''

    if dic is None:
        dic = {}

    for child in parent:
        if list(child) :
            new_dic = _ps_xml_to_dict(child, {})
            if "Name" in new_dic:
                dic[new_dic["Name"]] = new_dic
            else:
                try:
                    dic[[name for ps_type, name in child.items() if ps_type == "Type"][0]] = new_dic
                except IndexError:
                    dic[child.text] = new_dic
        else:
            for xml_type, name in child.items():
                if xml_type == "Name":
                    dic[name] = child.text

    return dic


def _pshell(cmd, cwd=None, depth=2):
{'fraction_non_alphanumeric': 0.09641306831162896, 'fraction_numerical': 0.005026273703449852, 'mean_word_length': 2.6003289473684212, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '326035', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1294, 'n_words': 399}