HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_path.cpython-310.pyc
o

�N�gv,�@s�dZddlZddlZddlZddlZddlZddlZddlZzdZ	Wne
y-dZ	Ynwe�e�Z
dZdZdZdZeej�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zddd�Zdd�ZdS)z�
Manage the Windows System PATH

Note that not all Windows applications will rehash the PATH environment variable,
Only the ones that listen to the WM_SETTINGCHANGE message
http://support.microsoft.com/kb/104011
�NTF�HKEY_LOCAL_MACHINE�<SYSTEM\CurrentControlSet\Control\Session Manager\Environment�PATHZ
REG_EXPAND_SZcCstjj��r
tr
dSdS)z
    Load only on Windows
    Zwin_path)Fz5Module win_path: module only works on Windows systems)�salt�utils�platformZ
is_windows�	HAS_WIN32�r	r	�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_path.py�__virtual__!srcCstj�tjj�|��S)z=
    Normalize the directory to make comparison possible
    )�os�path�normpathrr�stringutils�
to_unicode)Zstring_r	r	r
�_normalize_dir*srcCstjj�d�S)a�
    Send a WM_SETTINGCHANGE Broadcast to Windows to refresh the Environment
    variables for new processes.

    .. note::
        This will only affect new processes that aren't launched by services. To
        apply changes to the path to services, the host must be restarted. The
        ``salt-minion``, if running as a service, will not see changes to the
        environment until the system is restarted. See
        `MSDN Documentation <https://support.microsoft.com/en-us/help/821761/changes-that-you-make-to-environment-variables-do-not-affect-services>`_

    CLI Example:

    .. code-block:: bash

        salt '*' win_path.rehash
    ZEnvironment)rrZ
win_functionsZbroadcast_setting_changer	r	r	r
�rehash1srcCsNtjj�tdddd�d��d�}|ddkr|d	d�n|}ttt|��S)
z�
    Returns a list of items in the SYSTEM path

    CLI Example:

    .. code-block:: bash

        salt '*' win_path.get_path
    zreg.read_valuerrrZvdata�;����N)	rrrr�	__utils__�split�list�mapr)�retr	r	r
�get_pathFs
����
rcCs$t|�}t�}|��dd�|D�vS)ap
    Check if the directory is configured in the SYSTEM path
    Case-insensitive and ignores trailing backslash

    Returns:
        boolean True if path exists, False if not

    CLI Example:

    .. code-block:: bash

        salt '*' win_path.exists 'c:\python27'
        salt '*' win_path.exists 'c:\python27\'
        salt '*' win_path.exists 'C:\pyThon27'
    css�|]}|��VqdS�N��lower��.0�xr	r	r
�	<genexpr>rs�zexists.<locals>.<genexpr>)rrr)r
ZsysPathr	r	r
�exists_sr#cCst�|�tjd<dS)Nr)�PATHSEP�joinr�environ)�
local_pathr	r	r
�_update_local_pathusr(c		Kstjjjd
i|��}|�dd�}|rtjj�|�t|�}|dkr#dStjj�|�}t	�}dd�t
jd�t
�D�}|durRzt|�}Wn
ttfyQd}Ynwd	d
�}||||�r`t|�||||�shdStdtttd�tjj�|��t�}|r�|r�t�S|S)a�
    Add the directory to the SYSTEM path in the index location. Returns
    ``True`` if successful, otherwise ``False``.

    path
        Directory to add to path

    index
        Optionally specify an index at which to insert the directory

    rehash : True
        If the registry was updated, and this value is set to ``True``, sends a
        WM_SETTINGCHANGE broadcast to refresh the environment variables. Set
        this to ``False`` to skip this broadcast.

    CLI Examples:

    .. code-block:: bash

        # Will add to the beginning of the path
        salt '*' win_path.add 'c:\python27' 0

        # Will add to the end of the path
        salt '*' win_path.add 'c:\python27' index='-1'
    rT�.FcS�g|]	}tjj�|��qSr	�rrr�to_strrr	r	r
�
<listcomp>���zadd.<locals>.<listcomp>rNcSsHdd�|D�}z	|�|���}Wntyd}Ynwt|�}|}|durC||ks.|dkr1d}n||kr;d}}n|dkrC|d7}|dkrf|dur_||dkrSdS|�|�|�|�d	S|�|�d	S|durw|durpdS|�|�d	S|dur�|dkr�|||ks�|dkr�||kr�|�|�|�||�d	SdS|�||�d	S)
z�
        Check the dir list for the specified path, at the specified index, and
        make changes to the list if needed. Return True if changes were made to
        the list, otherwise return False.
        cS�g|]}|���qSr	rrr	r	r
r-��z,add.<locals>._check_path.<locals>.<listcomp>NrZENDr�FT)�indexr�
ValueError�len�pop�append�insert)�dirsr
r2�dirs_lcZ	cur_indexZnum_dirs�posr	r	r
�_check_path�sL�	






zadd.<locals>._check_path�
reg.set_valuerr	)rr�args�clean_kwargsr5�invalid_kwargsrrr,rrr&rr$�int�	TypeErrorr3r(r�HIVE�KEY�VNAMEr%�data�decode�VTYPEr)	r
r2�kwargs�rehash_�path_str�system_pathr'r;�resultr	r	r
�addys:��^�rMc	Ks�tjjjdi|��}|�dd�}|rtjj�|�t|�}tjj�|�}t	�}dd�t
jd�t
�D�}dd�}|||�rAt|�|||�sHdStdtttd	�tjj�|��t�}|ra|rat�S|S)a�
    Remove the directory from the SYSTEM path

    Returns:
        boolean True if successful, False if unsuccessful

    rehash : True
        If the registry was updated, and this value is set to ``True``, sends a
        WM_SETTINGCHANGE broadcast to refresh the environment variables. Set
        this to ``False`` to skip this broadcast.

    CLI Example:

    .. code-block:: bash

        # Will remove C:\Python27 from the path
        salt '*' win_path.remove 'c:\\python27'
    rTcSr*r	r+rr	r	r
r-;r.zremove.<locals>.<listcomp>rcSsndd�|D�}|��}g}t|�D]\}}||kr |�||�qt|�t|�kr5|dd�|dd�<dSdS)z�
        Check the dir list for the specified path, and make changes to the list
        if needed. Return True if changes were made to the list, otherwise
        return False.
        cSr/r	rrr	r	r
r-Er0z/remove.<locals>._check_path.<locals>.<listcomp>NTF)r�	enumerater6r4)r8r
r9Zpath_lcZnew_dirsr2�dirnamer	r	r
r;?s�zremove.<locals>._check_pathr<rNr	)rrr=r>r5r?rrr,rrr&rr$r(rrBrCrDr%rErFrGr)r
rHrIrJrKr'r;rLr	r	r
�removes*�

�rPr)�__doc__�loggingrZsalt.utils.argsrZsalt.utils.dataZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.win_functionsr�ImportError�	getLogger�__name__�logrBrCrDrG�str�pathsepr$rrrrr#r(rMrPr	r	r	r
�<module>s8�

	
%