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__/cyg.cpython-310.pyc
o

�N�g� �@s�dZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlmZe�
e�ZdZdZdZdd�Zd	d
iZddd
�Zddd�Zedfdd�Zd dd�Zd!dd�Zddd�Zd"dd�Zd dd�Zd dd�Zd#dd	�ZdS)$zB
Manage cygwin packages.

Module file to accompany the cyg state.
�N��SaltInvocationErrorz+ftp://mirrors.kernel.org/sourceware/cygwin/�ZcygcCstjj��rtSdS)z'
    Only works on Windows systems
    )Fz1Module cyg: module only works on Windows systems.)�salt�utils�platformZ
is_windows�__virtualname__�r	r	�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/cyg.py�__virtual__sr�list_�list�x86_64cCs&|dkrdS|dkrdStd|����)zH
    Return the cygwin install directory based on the architecture.
    rZcygwin64�x86�cygwinzInvalid architecture r��cyg_archr	r	r
�_get_cyg_dir's
rcCsBtj�dt|�ddg�}t�d|�tj�|�st�d�dSdS)z�
    Return True or False if cygwin is installed.

    Use the cygcheck executable to check install. It is installed as part of
    the base package, and we use it to check packages
    zC:�binzcygcheck.exezPath to cygcheck.exe: %szCould not find cygcheck.exeFT)�os�sep�joinr�LOG�debug�path�exists)rZpath_to_cygcheckr	r	r
�_check_cygwin_installed3s�
rcCs�dtvritd<|tdvrgtd|<td|sCd�||dg�}tj�|���}t�|�jddd��	�}dd�|D�}|td|<td|S)	zC
    Return the list of packages based on the mirror provided.
    zcyg.all_packages�/z	setup.bz2�utf_8�replace)�errorscSs*g|]}t�d|�rt�d|��d��qS)z^@ [^ ]+z
^@ ([^ ]+)�)�re�match�search�group)�.0�liner	r	r
�
<listcomp>Ts
��z%_get_all_packages.<locals>.<listcomp>)
�__context__r�urllib�request�urlopen�read�bz2�
decompress�decode�
splitlines)�mirrorrZ
pkg_source�	file_dataZ
file_lines�packagesr	r	r
�_get_all_packagesDs��r5cCsT|dur	ttig}t�d|�|D]}|��D]\}}|t||�vr&dSqqdS)aZ
    Check if the package is valid on the given mirrors.

    Args:
        package: The name of the package
        cyg_arch: The cygwin architecture
        mirrors: any mirrors to check

    Returns (bool): True if Valid, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' cyg.check_valid_package <package name>
    NzChecking Valid Mirrors: %sTF)�DEFAULT_MIRROR�DEFAULT_MIRROR_KEYrr�itemsr5)�packager�mirrorsr2�
mirror_url�keyr	r	r
�check_valid_package_s
��r=cCs�tj�ddg�}d|�d�}tj�||g�}d|��}tj�|�s't�|�ntj�|�r2t�|�tj�	|�}t
jj�
|d��}|�|���Wd�n1sRwY|}	g}
|
�d|���|durlttig}|D]}|��D]\}}
|
�d	|���|
r�|
�d
|
���qtqn|
�d�|
�d�|
�d
�|dur�|D]}|
�|�q�d�|
�}d�||g�}	td|	�}|ddkr�|dSdS)z�
    Retrieve the correct setup.exe.

    Run it with the correct arguments to get the bare minimum cygwin
    installation up and running.
    �c:Zcygcachezsetup-z.exezhttp://cygwin.com/�wbNz--local-package-dir z--site z	--pubkey z--no-desktopz--quiet-modez--disable-buggy-antivirus� �cmd.run_all�retcoder�stdoutF)rrrrr�mkdir�remover*r+r,rr�filesZfopen�writer-�appendr6r7r8�__salt__)r�argsr:Z
cyg_cache_dirZ	cyg_setupZcyg_setup_pathZcyg_setup_sourcer3ZfhwZ
setup_command�optionsr2r;r<�argZcmdline_args�retr	r	r
�_run_silent_cygwin|sH

�
��



rNcCsHd�tj�dt|�ddg�d|g�}td|�}|ddkr"|d	Sd
S)z&
    Run the cygcheck executable.
    r@r>rZcygcheck�-crArBrrCF)rrrrrI)rJr�cmdrMr	r	r
�	_cygcheck�s�rQcCs<g}|dur|�d|���t|�st|d�t|||d�S)a�
    Install one or several packages.

    packages : None
        The packages to install

    cyg_arch : x86_64
        Specify the architecture to install the package under
        Current options are x86 and x86_64

    CLI Example:

    .. code-block:: bash

        salt '*' cyg.install dos2unix
        salt '*' cyg.install dos2unix mirrors="[{'http://mirror': 'http://url/to/public/key}]'
    Nz--packages r�rrJr:)rHrrN�r4rr:rJr	r	r
�install�s
rTcCsLg}|dur|�d|���t�d|�t|�st�d�dSt|||d�S)a�
    Uninstall one or several packages.

    packages
        The packages to uninstall.

    cyg_arch : x86_64
        Specify the architecture to remove the package from
        Current options are x86 and x86_64

    CLI Example:

    .. code-block:: bash

        salt '*' cyg.uninstall dos2unix
        salt '*' cyg.uninstall dos2unix mirrors="[{'http://mirror': 'http://url/to/public/key}]"
    Nz--remove-packages zargs: %sz&We're convinced cygwin isn't installedTrR)rHrrrrNrSr	r	r
�	uninstall�s
rUcCs4g}|�d�t|�st�d|�dSt|||d�S)a6
    Update all packages.

    cyg_arch : x86_64
        Specify the cygwin architecture update
        Current options are x86 and x86_64

    CLI Example:

    .. code-block:: bash

        salt '*' cyg.update
        salt '*' cyg.update dos2unix mirrors="[{'http://mirror': 'http://url/to/public/key}]"
    z--upgrade-alsoz+Cygwin (%s) not installed, could not updateFrR)rHrrrrN)rr:rJr	r	r
�update�s
rVc
Cszi}d�dd|g�}t||d�}g}t|t�r tjj�|���}|D]}t	�
d|�}|r:|�d�}|�d�}	|	||<q"|S)a
    List locally installed packages.

    package : ''
        package name to check. else all

    cyg_arch :
        Cygwin architecture to use
        Options are x86 and x86_64

    CLI Example:

    .. code-block:: bash

        salt '*' cyg.list
    r@rOz-drz^([^ ]+) *([^ ]+)r!�)rrQ�
isinstance�strrrZstringutilsZ
to_unicoder1r"r#r%)
r9rZpkgsrJrC�linesr'r#Zpkg�versionr	r	r
rs


�)r)rN)rNN)NrN)rr)�__doc__r.�loggingrr"�urllib.requestr*Zsalt.utils.filesrZsalt.utils.platformZsalt.utils.stringutilsZsalt.exceptionsr�	getLogger�__name__rr6r7rrZ__func_alias__rrr5r=rNrQrTrUrVrr	r	r	r
�<module>s4
	




5