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

�N�g�?�@s�dZddlZddlZddlZddlZddlmZe�e	�Z
dZdd�Zdd�Z
d	d
�Zdd�Zd#dd�Zdd�Zd$dd�Zd%dd�Z	
d&dd�Zd'dd�Zd(dd�Zdd�Zdd �Zd!d"�ZdS))a0
Support for apk

.. important::
    If you feel that Salt should be using this module to manage packages on a
    minion, and it is using a different module (or gives an error similar to
    *'pkg.install' is not available*), see :ref:`here
    <module-provider-override>`.

.. versionadded:: 2017.7.0

�N)�CommandExecutionError�pkgcCst�dd�dkr
tSdS)zH
    Confirm this module is running on an Alpine Linux distribution
    Z	os_familyFZAlpine)Fz3Module apk only works on Alpine Linux based systems)Z
__grains__�get�__virtualname__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/apkpkg.py�__virtual__srcOstd|i|��S)aY
    Returns a string representing the package version or an empty string if not
    installed. If more than one package name is specified, a dict of
    name/version pairs is returned.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.version <package name>
        salt '*' pkg.version <package1> <package2> <package3> ...
    zpkg_resource.version)�__salt__)�names�kwargsrrr�versionBs
rcKs\i}ddg}td|ddd�}|ddkrg}d	}n|d
g}d}|r,td||d�d
��|S)z�
    Updates the package list

    - ``True``: Database updated successfully
    - ``False``: Problem updating database

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.refresh_db
    �apk�update�cmd.run_all�traceF��output_loglevel�python_shell�retcoderT�stdout�)Problem encountered installing package(s)��errors�changes��info)r	r)r�ret�cmd�callrrrr�
refresh_dbRs

�rcCs*|rtdSt�td�}td|�|S)z'
    Use pkg list from __context__
    �
pkg.list_pkgs�pkg_resource.stringify)�__context__�copy�deepcopyr	)�versions_as_listrrrr�_list_pkgs_from_contextrs
r&Fcs�tjj�|�}t�fdd�dD��riSdtvr"��dd�r"t|�Sgd�}i}td|d	d
d�}tjj	�
|d�D]"}d
�|�
d
�dd��}d
�|�
d
�dd��}td|||�q9td|�t�
|�td<|sqtd|�|S)z�
    List the packages currently installed in a dict::

        {'<package_name>': '<version>'}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_pkgs
        salt '*' pkg.list_pkgs versions_as_list=True
    cs g|]}tjj���|���qSr)�salt�utils�data�is_truer)�.0�x�rrr�
<listcomp>�s zlist_pkgs.<locals>.<listcomp>)ZremovedZ
purge_desiredr Zuse_contextT)r
rz-vzcmd.runrFr�
�-���Nzpkg_resource.add_pkgzpkg_resource.sort_pkglistr!)r'r(r)r*�anyr"rr&r	�	itertools�split�joinr#r$)r%rrr�out�line�pkg_version�pkg_namerr-r�	list_pkgs~s&
�r:c
Os�tjj�|�dd��}|sdSi}|D]}d||<qt�}|r"t�gd�}td|ddd�}tjj�	|d	�D]2}z%|�	d
�d}|�	d
�d�
d
�}	|�	d
�d�
d�}
||vr]|
||<Wq7ttfyiYq7w|D]X}||s�|�
|�}dd|g}td|ddd�}tjj�	|d	�D]6}z+d�|�	d�dd��}
d�|�	d�dd��}||kr�||
kr�d||<n|
||<Wq�ty�Yq�wqlt|�dkr�||dS|S)a
    Return the latest version of the named package available for upgrade or
    installation. If more than one package name is specified, a dict of
    name/version pairs is returned.

    If the latest version of a given package is already installed, an empty
    string will be returned for that package.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.latest_version <package name>
        salt '*' pkg.latest_version <package name>
        salt '*' pkg.latest_version <package1> <package2> <package3> ...
    �refreshT��r
�upgradez-s�cmd.run_stdoutrFrr/� ���(��)r
�searchr0r1N�r)r'r(r)r*�popr:rr	r3r4�strip�
ValueError�
IndexErrorrr5�len)r
rr;r�name�pkgsrr6r7�_oldversion�
newversionrZ	installedr8r9rrr�latest_version�sZ
��

�
���rQcKstjj�|�}g}t�}|r|s|sd|vr|�d�}n|g}|r-dd�|D�}|�|�|s1iS|r6t�ddg}|D]}	|�|	�rJ|�	d�nq<|�|�t
d|dd	d
�}
|
ddkri|
d
ri|
d
g}ng}t�dd�t�}tjj�
||�}
|r�td||
d�d��|
S)a/
    Install the passed package, add refresh=True to update the apk database.

    name
        The name of the package to be installed. Note that this parameter is
        ignored if either "pkgs" or "sources" is passed. Additionally, please
        note that this option can only be used to install packages from a
        software repository. To install a package file manually, use the
        "sources" option.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install <package name>

    refresh
        Whether or not to refresh the package database before installing.


    Multiple Package Installation Options:

    pkgs
        A list of packages to install from a software repository. Must be
        passed as a python list.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install pkgs='["foo", "bar"]'

    sources
        A list of IPK packages to install. Must be passed as a list of dicts,
        with the keys being package names, and the values being the source URI
        or local path to the package.  Dependencies are automatically resolved
        and marked as auto-installed.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install sources='[{"foo": "salt://foo.deb"},{"bar": "salt://bar.deb"}]'

    install_recommends
        Whether to install the packages marked as recommended. Default is True.

    Returns a dict containing the new package names and versions::

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}
    �,cSs"g|]
}t|t�rtt|���qSr)�
isinstance�dict�next�iter)r+�prrrr..s"zinstall.<locals>.<listcomp>r
�add�-urrFrrr�stderrr Nrrr)r'r(r)r*r:r4�extendrr�appendr	r"rH�
compare_dictsr)rMr;rNZsourcesrZ	refreshdbZpkg_to_install�oldrZ_pkgr6r�newrrrr�install�sD5


�
�r`cKst||dd�S)z
    Alias to remove
    T)rMrN�purge)�remove)rMrNrrrrraUsracKs�t�}g}|rd|vr|�d�}n|g}|r|�|�|siS|r&gd�}nddg}|�|�td|ddd�}|d	d
krH|drH|dg}ng}t�dd
�t�}	tjj�	||	�}
|rft
d||
d�d��|
S)a
    Remove packages using ``apk del``.

    name
        The name of the package to be deleted.


    Multiple Package Options:

    pkgs
        A list of packages to delete. Must be passed as a python list. The
        ``name`` parameter will be ignored if this option is passed.

    Returns a dict containing the changes.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.remove <package name>
        salt '*' pkg.remove <package1>,<package2>,<package3>
        salt '*' pkg.remove pkgs='["foo", "bar"]'
    rR)r
�delz--purger
rcrrFrrrrZr Nz'Problem encountered removing package(s)rr)r:r4r[r	r"rHr'r(r)r]r)rMrNrarr^Z
pkg_to_removerr6rr_rrrrrb\s6


�rbTc
Ks�iddd�}tjj�|�rt�t�}g}|r&|s&d|vr#|�d�}n|g}|r-|�|�|r9gd�}|�|�nddg}td|d	d
dd�}|dd
kr[d
|d<|dr[|d|d<t	�
dd�t�}	tjj�||	�|d<|S)ah
    Upgrades all packages via ``apk upgrade`` or a specific package if name or
    pkgs is specified. Name is ignored if pkgs is specified

    Returns a dict containing the changes.

        {'<package>':  {'old': '<old-version>',
                        'new': '<new-version>'}}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    Tr<)r�result�commentrR)r
rXrYr
r>rrF)rr�redirect_stderrrrrdrrer Nr)r'r(r)r*rr:r4r[r	r"rHr])
rMrNr;rrr^Zpkg_to_upgraderrr_rrrr>�s:�
�r>cKs�i}tjj�|�rt�gd�}td|ddd�}|ddkr9d}d	|vr+||d	7}d
|vr5||d
7}t|��|d
}|��D]%}d|vrf|�d�d
}|�d�d�	d�}	|�d�d�	d�}
|
||<qA|S)z~
    List all available package upgrades.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_upgrades
    r=rrFrrrr<rZrZ	Upgradingr@rArBrCrDrE)
r'r(r)r*rr	r�
splitlinesr4rI)r;rrrrrer6r7rMrOrPrrr�
list_upgrades�s*
�rhcOst|�S)aV
    List the files that belong to a package. Not specifying any packages will
    return a list of _every_ file on the system's package database (not
    generally recommended).

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.file_list httpd
        salt '*' pkg.file_list httpd postfix
        salt '*' pkg.file_list
    )�	file_dict)�packagesrrrr�	file_listsrkc
Os�g}i}gd�}|sdS|D]2}g}|dd�}|�|�td|ddd�}|d��D]
}	|	�d	�r4q,|�|	�q,|r@|||<q||d
�S)aj
    List the files that belong to a package, grouped by package. Not
    specifying any packages will return a list of _every_ file on the system's
    package database (not generally recommended).

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.file_list httpd
        salt '*' pkg.file_list httpd postfix
        salt '*' pkg.file_list
    )r
rz-LzPackage name should be providedNrrFrrz	contains:)rrj)r\r	rg�endswith)
rjrrrZ	cmd_files�package�filesrr6r7rrrris$

�
ricOs�|sdSi}gd�}|D]4}|dd�}|�|�td|ddd�}|r9d|vr-d	||<q|�d
�d��||<qd|��||<q|S)
aP
    Return the name of the package that owns the file. Multiple file paths can
    be passed. Like :mod:`pkg.version <salt.modules.apk.version`, if a single
    path is passed, a string will be returned, and if multiple paths are passed,
    a dictionary of file/package name pairs will be returned.

    If the file is not owned by a package, or is not present on the minion,
    then an empty string will be returned for that path.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.owns /usr/bin/apachectl
        salt '*' pkg.owns /usr/bin/apachectl /usr/bin/basename
    zYou must provide a path)r
rz-WNr?rFrzERROR:zCould not find owner packagezby rGzError running )r\r	r4rI)�pathsrrZ
cmd_search�pathr�outputrrr�owner6s 
�
rr)F)NFNN)NN)NNF)NNT)T)�__doc__r#�loggingZsalt.utils.datar'Zsalt.utils.itertoolsZsalt.exceptionsr�	getLogger�__name__�logrrrrr&r:rQr`rarbr>rhrkrirrrrrr�<module>s.

' 
&
G
j
�
C
<%%