HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_wusa.cpython-310.pyc
o

�N�g+�@spdZddlZddlZddlZddlmZe�e�Z	dZ
dd�Zddd�Zd	d
�Z
ddd
�Zddd�Zdd�ZdS)z�
Microsoft Update files management via wusa.exe

:maintainer:    Thomas Lemarchand
:platform:      Windows
:depends:       PowerShell

.. versionadded:: 2018.3.4
�N)�CommandExecutionErrorZwusacCs0tjj��sdStdddd�}|dsdStS)z
    Load only on Windows
    )Fz!Only available on Windows systemszcmd.shell_info�
powershellF)�shellZlist_modulesZ	installed)FzPowerShell not available)�salt�utils�platformZ
is_windows�__salt__�__virtualname__)Zpowershell_info�r
�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_wusa.py�__virtual__srcCs�d|��vr|�d�}t�d|�td|d|d�}d|vr!|d=|�dd	�r5|d��d
}t||d��d|vs?|dd
krHtd
|��|d��|dd	krRd|d<ztjj	j
|ddd�}W|Stymtd|d��w)z}
    Execute the desired powershell command and ensure that it returns data
    in JSON format and load that into python
    zconvertto-jsonz | ConvertTo-JsonzPowerShell: %szcmd.run_allr)r�cwd�pid�stderr�r)�info�retcodezIssue executing PowerShell �stdoutz{}F)�strictzNo JSON results from PowerShell)�lower�log�debugr�get�
splitlinesrrr�json�loads�
ValueError)�cmdr
�ret�errorr
r
r�_pshell_json%s&
��r cCstdd|��ddd�dkS)a
    Check if a specific KB is installed.

    Args:

        name (str):
            The name of the KB to check

    Returns:
        bool: ``True`` if installed, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' wusa.is_installed KB123456
    �cmd.retcodezGet-HotFix -Id rT)rr�ignore_retcoder)r)�namer
r
r�is_installedFs���r$FcCs�d|dg}|r
|�d�n|�d�td|dd�}tj�|�}|�d�d	�|�d
d�}||vr7t|||��|r@td|����dS)
a�
    Install a KB from a .msu file.

    Args:

        path (str):
            The full path to the msu file to install

        restart (bool):
            ``True`` to force a restart if required by the installation. Adds
            the ``/forcerestart`` switch to the ``wusa.exe`` command. ``False``
            will add the ``/norestart`` switch instead. Default is ``False``

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    Raise:
        CommandExecutionError: If the package is already installed or an error
            is encountered

    CLI Example:

    .. code-block:: bash

        salt '*' wusa.install C:/temp/KB123456.msu
    �wusa.exe�/quiet�
/forcerestart�
/norestartr!T�r"z is already installedzK{} correctly installed but server reboot is needed to complete installationz
Unknown error)i$i��W�Unknown error: )�appendr�os�path�basename�formatr)r.�restartr�ret_code�	file_name�errorsr
r
r�installbs 

�r5cCs�gd�}tj�tj�|��d}tj�|�r|�|�n|�d�|���d�r-|dd�n|��|r9|�d�n|�d�t	d	|d
d�}|�d�|�d
�dd�}||vr]t
|||��|rft
d|����d
S)a�
    Uninstall a specific KB.

    Args:

        path (str):
            The full path to the msu file to uninstall. This can also be just
            the name of the KB to uninstall

        restart (bool):
            ``True`` to force a restart if required by the installation. Adds
            the ``/forcerestart`` switch to the ``wusa.exe`` command. ``False``
            will add the ``/norestart`` switch instead. Default is ``False``

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    Raises:
        CommandExecutionError: If an error is encountered

    CLI Example:

    .. code-block:: bash

        salt '*' wusa.uninstall KB123456

        # or

        salt '*' wusa.uninstall C:/temp/KB123456.msu
    )r%z
/uninstallr&rz/kb:{}�kb�Nr'r(r!Tr)z does not support uninstallz not installedz*Unknown error. Try specifying an .msu file)i $�i$r*r+)r-r.�splitextr/�existsr,r0r�
startswithrr)r.r1rr6r2r4r
r
r�	uninstall�s$ *
�r;cCs(g}td�}|D]	}|�|d�q|S)z�
    Get a list of updates installed on the machine

    Returns:
        list: A list of installed updates

    CLI Example:

    .. code-block:: bash

        salt '*' wusa.list
    zGet-HotFix | Select HotFixIDZHotFixID)r r,)Zkbsr�itemr
r
r�list�s

r=)N)F)�__doc__�loggingr-Zsalt.utils.platformrZsalt.exceptionsr�	getLogger�__name__rr	rr r$r5r;r=r
r
r
r�<module>s


!

7>