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/states/__pycache__/pkg.cpython-310.pyc
o

�N�g�%�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZmZm
Z
ddlmZddlmZddlmZddlmZeee��Zejj��r�ddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$eee��Zee#e��Z#eee��Zeee��Zee$e��Z$ee"e��Z"ee e��Z eee��Zee!e��Z!e�%e&�Z'd	d
�Z(dd�Z)dLd
d�Z*dd�Z+		dMdd�Z,dLdd�Z-dd�Z.						dNdd�Z/dOdd�Z0	dPdd�Z1										dQdd �Z2dOd!d"�Z3d#d$�Z4d%d&�Z5d'd(�Z6dRd)d*�Z7													dSd+d,�Z8	dTd-d.�Z9dOd/d0�Z:dLd1d2�Z;					dUd3d4�Z<	5					dVd6d7�Z=dWd8d9�Z>dWd:d;�Z?dXd<d=�Z@dOd>d?�ZAd@dA�ZBdBdC�ZCdDdE�ZDdFdG�ZEdYdHdI�ZFdYdJdK�ZGdS)Za�
Installation of packages using OS package managers such as yum or apt-get
=========================================================================

.. note::
    On minions running systemd>=205, as of version 2015.8.12, 2016.3.3, and
    2016.11.0, `systemd-run(1)`_ is now used to isolate commands which modify
    installed packages from the ``salt-minion`` daemon's control group. This is
    done to keep systemd from killing the package manager commands spawned by
    Salt, when Salt updates itself (see ``KillMode`` in the `systemd.kill(5)`_
    manpage for more information). If desired, usage of `systemd-run(1)`_ can
    be suppressed by setting a :mod:`config option <salt.modules.config.get>`
    called ``systemd.use_scope``, with a value of ``False`` (no quotes).

.. _`systemd-run(1)`: https://www.freedesktop.org/software/systemd/man/systemd-run.html
.. _`systemd.kill(5)`: https://www.freedesktop.org/software/systemd/man/systemd.kill.html

Salt can manage software packages via the pkg state module, packages can be
set up to be installed, latest, removed and purged. Package management
declarations are typically rather simple:

.. code-block:: yaml

    vim:
      pkg.installed

A more involved example involves pulling from a custom repository.

.. code-block:: yaml

    base:
      pkgrepo.managed:
        - name: ppa:wolfnet/logstash
        - dist: precise
        - file: /etc/apt/sources.list.d/logstash.list
        - keyid: 28B04E4A
        - keyserver: keyserver.ubuntu.com

    logstash:
      pkg.installed:
        - fromrepo: ppa:wolfnet/logstash

Multiple packages can also be installed with the use of the pkgs
state module

.. code-block:: yaml

    dotdeb.repo:
      pkgrepo.managed:
        - name: deb http://packages.dotdeb.org wheezy-php55 all
        - dist: wheezy-php55
        - file: /etc/apt/sources.list.d/dotbeb.list
        - keyid: 89DF5277
        - keyserver: keys.gnupg.net
        - refresh_db: true

    php.packages:
      pkg.installed:
        - fromrepo: wheezy-php55
        - pkgs:
          - php5-fpm
          - php5-cli
          - php5-curl

.. warning::

    Make sure the package name has the correct case for package managers which are
    case-sensitive (such as :mod:`pkgng <salt.modules.pkgng>`).
�N)�CommandExecutionError�MinionError�SaltInvocationError)�_repack_pkgs)�nested)�namespaced_function)�OrderedDict)	�_get_latest_pkg_version�_get_package_info�_get_repo_details�_refresh_db_conditional�_repo_process_pkg_sls�_reverse_cmp_pkg_versions�genrepo�
get_repo_data�
refresh_dbcCsdtvrdSdS)zn
    Only make these states available if a pkg provider has been detected or
    assigned for this minion
    �pkg.installT)Fzpkg module could not be loaded��__salt__�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/pkg.py�__virtual__tsrcCs*tjj�|���\}}|dvrd}||fS)z�
    Return a tuple containing the comparison operator and the version. If no
    comparison operator was passed, the comparison is assumed to be an "equals"
    comparison, and "==" will be the operator returned.
    )�=��==)�salt�utils�pkgZsplit_comparison�strip)�pkgver�oper�verstrrrr�_get_comparison_spec~sr"cCs$|dur|Sd|vod|vod|vS)z�
    Conditionally ignore epoch, but only under all of the following
    circumstances:

    1. No value for ignore_epoch passed to state
    2. desired_version has no epoch
    3. oper does not contain a "<" or ">"
    N�<�>�:r)r �desired_version�ignore_epochrrr�_check_ignore_epoch�s	r(cCs:g}|��}|s
|S|�d�D]}t|�}|�|�q|S)zF
    Returns a list of two-tuples containing (operator, version).
    �,)r�splitr"�append)�version_conditions_string�resultZversion_conditionZoperator_and_versionrrr�_parse_version_string�sr.Fc	Csdt|�}|D])}d}|D]\}}|rt|�dkr|dkrd}|o(t|g|||d�}q|r/dSqdS)a
    Returns True if any of the installed versions match the specified version conditions,
    otherwise returns False.

    installed_versions
        The installed versions

    version_conditions_string
        The string containing all version conditions. E.G.
        1.2.3-4
        >=1.2.3-4
        >=1.2.3-4, <2.3.4-5
        >=1.2.3-4, <2.3.4-5, !=1.2.4-1

    ignore_epoch : None
        When a package version contains an non-zero epoch (e.g.
        ``1:3.14.159-2.el7``), and a specific version of a package is desired,
        set this option to ``True`` to ignore the epoch when comparing
        versions.

        .. versionchanged:: 3001
            If no value for this argument is passed to the state that calls
            this helper function, and ``version_conditions_string`` contains no
            epoch or greater-than/less-than, then the epoch will be ignored.

    allow_updates : False
        Allow the package to be updated outside Salt's control (e.g. auto updates on Windows).
        This means a package on the Minion can have a newer version than the latest available in
        the repository without enforcing a re-installation of the package.
        (Only applicable if only one strict version condition is specified E.G. version: 2.0.6~ubuntu3)
    T�rz>=�r'F)r.�len�_fulfills_version_spec)	Zinstalled_versionsr,r'�
allow_updates�version_conditionsZinstalled_versionZ
fullfills_all�operator�version_stringrrr�_fulfills_version_string�s%
��r7c
Csxt�d�}tjj��rt|t�rd|vr|d}|D]}|dkr&t�||�s6tjj	j
||||t|||�d�r9dSqdS)zp
    Returns True if any of the installed versions match the specified version,
    otherwise returns False
    zpkg.version_cmp�versionr)Zver1r Zver2�cmp_funcr'TF)r�getrr�platformZ
is_freebsd�
isinstance�dict�fnmatch�versionsZcomparer()r?r r&r'r9�verrrrr2�s"

���	r2cs�fdd�|D�S)a/
    Find packages which are marked to be purged but can't yet be removed
    because they are dependencies for other installed packages. These are the
    packages which will need to be 'unpurged' because they are part of
    pkg.installed states. This really just applies to Debian-based Linuxes.
    cs*g|]}|tddddi���vr|�qS)�
pkg.list_pkgs�
purge_desiredTrr��.0�x��kwargsrr�
<listcomp>�s
�z)_find_unpurge_targets.<locals>.<listcomp>r)�desiredrGrrFr�_find_unpurge_targets�s
�rJTcKsVtddi|��}|rt||d�}|s|iddd�SnA|r,t�ddd��}	|	|�|i}n||i}|�|i�}
||vr\|
rK||
vrK|id	d
�||�d�S|
r\|dur\|id	d|�d
�d�Sd}|s�z
t|fi|��}Wn	tysYnLwg}
|�d�r�|
�d�d�t|d����|�d�r�|d�	�D]\}}|
�d�|d�|���q�|
r�t
|
�dkr�|
�d�|idd�|
���d�Si}g}|�	�D]@\}}|�|i�}
|
s�|||<q�|
r�|s�q�d	}zt|
�
�||d�s�|||<Wq�t�y}z|�|j�WYd}~q�d}~ww|�r|idd�|�d�S|�s)d�|�rdnd�}|id	|d�S|S)z�
    Inspect the arguments to pkg.downloaded and discover what packages need to
    be downloaded. Return a dict of packages to download.
    �pkg.list_downloaded��	normalizeF�3Invalidly formatted pkgs parameter. See minion log.��name�changesr-�comment�pkg.normalize_namecS�|S�Nr��pkgnamerrr�<lambda>�z(_find_download_targets.<locals>.<lambda>Tz0Version {} of package '{}' is already downloadedN�Package z is already downloaded�
no_suggest�aThe following package(s) were not found, and no possible matches were found in the package db: {}�, �suggest�-Package '{}' not found (possible matches: {})r/r�. r0� z/All specified packages{} are already downloaded� (matching specified versions)r)rrr:�format�_preflight_checkrr+�join�sorted�itemsr1�rstripr7�keys�strerror)rPr8�pkgsrM�skip_suggestionsr'rG�cur_pkgs�to_download�_normalize_name�cver�version_spec�problems�commentsrW�suggestions�targetsr�exc�msgrrr�_find_download_targets�s�
��	���
��
�

��
�	
������rxc	Ks�tddi|��}|r|}n|g}|�|i�r"|idd|�d�d�Sg}|D]}|�|i�}|s6|�|�q&q&|sBd}|id|d�S|S)	z�
    Inspect the arguments to pkg.patch_installed and discover what advisory
    patches need to be installed. Return a dict of advisory patches to install.
    zpkg.list_installed_patchesTzAdvisory patch � is already installedrOz4All specified advisory patches are already installedNr)rr:r+)	rP�advisory_idsrGZcur_patchesrnruZ
patch_namerprwrrr�_find_advisory_targets�s*
�
�r{cs�tddkr
d|d<tddddi|��}|r't||d�}|s&|idd	d
�Snt�ddd
��}||�|i}d}	g}
g}|��D]g\�}tt�d���}
tddkr_|
r_�fdd�|��D�}n|��g�}|shq?td|�durv|
���q?d}	zt	|||d�r�|
���nt
�d||�Wq?ty�}z|�|j
�WYd}~q?d}~ww|r�|idd�|�d
�S|
s�d�|	r�dnd�}|id|d
�S|
S)z�
    Inspect the arguments to pkg.removed and discover what packages need to
    be removed. Return a dict of packages to remove.
    �os�FreeBSDT�with_originrA�versions_as_listrLFrNrOrScSrTrUrrVrrrrX�rYz&_find_remove_targets.<locals>.<lambda>�/c� g|]\}}|d�kr|�qS��originr�rD�k�vrVrrrH�� z(_find_remove_targets.<locals>.<listcomp>�pkg_resource.version_cleanNr0zVCurrent version (%s) did not match desired version specification (%s), will not removeraz+All specified packages{} are already absentrbrr)�
__grains__rrr:rg�bool�re�searchr+r7�log�debugrrjrerc)rPr8rkrMr'rGrm�	to_removerorqrurrrr�rprvrwrrVr�_find_remove_targets�sl��	
�����
�r�c
1sxd}t||f�r�iddd�Si}t|t�r)tdd�|D��r)tdd�|D��}
ng}
t|t�rCtdd�|D��rCtdd�|D��}ng}td	d
krOd|
d<tjj�	�rY|	|
d
<|
�
dd�obdtv}ztddGddi|
���|rztddGi|
��p|t�}Wnt
y�}z�id|jd�WYd}~Sd}~wwtjj�	�r�|
�d
d�r�d}d}	t||f�r�|r�t||d�}n
|r�td||d�}|sՈidd�|r�d�d�Sd�d�St|fi|
��}n�tjj�	��rt�|
dd�}|s��idd��d�d�S|du�rt|�}|�rt�
ddd��}|��|i}n�|i}t|fi|
��}tt�d���}td	d
k�r?|�r?�fd d!����D�}n��
�g�}�|v�r||�rc||v�rc|�sc|�sc�idd"�|��d�S|�r||du�r||�s||�s|�idd��d#�d�Sd}|�s�|�s���fd$d%�|��D�}|�r�z
t|fi|
��}Wn
t
�y�YnQwg}|�
d&��r�|�d'�d(�t|d&����|�
d)��r�|d)��D]\}}|�d*�|d(�|����q�|�r�t|�d+k�r�|�d,��idd-�|���d�S|�r�gnd.d!�|��D�}|�rKtd/|d
|	i|
��}t|�d+k�r!|d0|i}|	�r(d}d}	|D]} || �sD| �v�r@�| d1|| <�q*d|| <�q*|�|�i}!i}"g}g}#d}$|��D�]�\}%}&��
|%g�}|�rz|�sz|%|v�rz��
|�
|%�d0g�}|�s�|&|!|%<�qY|�r|�r�|&|"|%<�qYd2tv�r��qYd3}'ztd4|&|
d|
�
d5d�d6�}(Wnt
�y�}z|�|'�|&|��WYd}~�qYd}~ww|(�s�|�|'�|&d7���qYt j!�"|(��s�|�|&�d8���qYtd2|(�})|)du�r�|#�d9|&����qY|)d:}*n^|&}*|�r|&|"|%<�qYtd;|%|&��s|&|!|%<�qYtd<|&�du�r^|�s\|�r\ztd=|%f|
|d>�|
��}+Wnt
t#f�yP}z
|j}$WYd}~�qYd}~ww|+�r\|&|"|%<|+||%<�qYd},t|�oi|
�
d?��}-z
t$||*�|-d@�},Wnt
�y�}z
|�|j�WYd}~�qYd}~wwd}|,�s�|�r�|&|"|%<�qYt%|&�}.|�r�tdAd�|.D���r�ztd=|%f|
|d>�|
��}+Wnt
t#f�y�}z
|j}$WYd}~�qYd}~ww|+�r�|&|"|%<|+||%<�qYt&�'dB||&�|&|!|%<�qY|$�r�|�|$�|�r�iddC�|�d�St|!||"f��s3dD}/|/�|�r|�sdEnd,�}/�id|/d�}0|#�r1|0�(dFg��)|#�|0S||!||"||#|fS)Hz�
    Inspect the arguments to pkg.installed and discover what packages need to
    be installed. Return a dict of desired packages
    Fz.Only one of "pkgs" and "sources" is permitted.rOcs�0�|]}t|t�rd|vr|�d�duVqdS��ignore_typesN�r<�_OrderedDictr:rCrrr�	<genexpr>�����z(_find_install_targets.<locals>.<genexpr>cs�"�|]}d|vr|�d�VqdSr��r:rCrrrr����csr���verify_optionsNr�rCrrrr�$r�csr�r�r�rCrrrr�)r�r|r}Tr~�refresh�resolve_capabilities�pkg.list_providesrArNrLzpkg_resource.pack_sourcesz3Invalidly formatted '{}' parameter. See minion log.rk�sources�saltenv)r�rZz not found in the repository.rScSrTrUrrVrrrrXqrYz'_find_install_targets.<locals>.<lambda>r�cr�r�rr�)rPrrrH}r�z)_find_install_targets.<locals>.<listcomp>z/Version {} of package '{}' is already installedrycs8i|]\}}|�vr|dust�||�d�s||�qS)Nr0)r7)rDrPr8)rmr'rr�
<dictcomp>�s
���z)_find_install_targets.<locals>.<dictcomp>r[r\r]r^r_r/rr`cSsg|]
\}}|dkr|�qS)�latestr�rDrE�yrrrrH���pkg.latest_versionr���zlowpkg.bin_pkg_infozUnable to cache {0}: {1}z
cp.cache_file�
verify_ssl)r�r�zfile not foundz does not exist on minionzFailed to parse metadata for r8z%pkg_resource.check_extra_requirementsr��
pkg.verify�r�r�r3)r'r3css�|]	\}}|dkVqdS)rNr)rDr r8rrrr�<s�
�zeCurrent version (%s) did not match desired version specification (%s), adding to installation targetsraz/All specified packages are already installed{0}z and are at the desired version�warningsr)*�allr<�list�any�nextr�rrr;�
is_windowsr:rr=rrj�poprrcrJr
r	r�r�r�rgrdr+rerfr1rh�updater|�path�existsrr7r.r�r��
setdefault�extend)1rPr8rkr�rl�
pkg_verifyrMr'�	reinstallr�rG�
was_refreshed�
altered_filesr�r�r�Zcur_provrvrI�
to_unpurge�pkginforor�rprq�
not_installedrrrsrWrtZwants_latestZresolved_latest�keyru�to_reinstallr�Z
failed_verifyZpackage_namer6�errZcached_pathZsource_infor!�
verify_resultZversion_fulfilledr3r4rw�retr)rmr'rPr�_find_install_targets�s@��
��
����������	
�
�
��

��
��
��
�	���

�



���

���
���
���
���
������
���r�c		s�g}g}|s	t�}|��D]�\�}d�v}tddkr)|r)�fdd�|��D�}nNtddkr@|r@|��|���d�d��}n7tddkrQ|���d	�d
�}n&tddkrb|���d
�d
�}n|���}|sw�|vrw|�|���d
�}|s|���q
|dkr�|���q
td|�s�|���q
|�d�r�|d
�|dd��r�|���q
t	|||d�r�|���q
|���q
||fS)zg
    Determine whether or not the installed packages match what was requested in
    the SLS file.
    r�r|r}cr�r�rr�rVrrrH�r�z#_verify_install.<locals>.<listcomp>ZMacOSr�ZOpenBSD�%r�	os_familyZDebianrr�r��*Nr0)
r=rgr�r:r*r+r�endswith�
startswithr7)	rI�new_pkgsr'�new_caps�_ok�failedrZ
has_originrprrVr�_verify_installvsB



 
r�cCs@||r||�d�rd}nd}d�||||sd�S||�S)z�
    Helper function that retrieves and nicely formats the desired pkg (and
    version if specified) so that helpful information can be printed in the
    comment for the state.
    )r#r$rrrz{}{}{})r�rc)rPrIr rrr�_get_desired_pkg�s r�cKs�dtvriSigd�}tdt|���d|i|��}|D]"}||ddur>||dr7||d|d|<q|d�|�q|S)	z>
    Perform platform-specific checks on desired packages
    zpkg.check_db)r^r[�fromrepo�foundFrtr^r[)rr�rir+)rIr�rGr�r�rWrrrrd�s"

����rdcCstt_t�|���}|S)z-
    Serialize obj and format for output
    )�__opts__r�outputrh)�objr�rrr�_nested_output�sr�cKs4|rdtvr
||fStd|fd|i|��}|dfS)a�
    Resolve capabilities in ``pkgs`` and exchange them with real package
    names, when the result is distinct.
    This feature can be turned on while setting the paramter
    ``resolve_capabilities`` to True.

    Return the input dictionary with replaced capability names and as
    second return value a bool which say if a refresh need to be run.

    In case of ``resolve_capabilities`` is False (disabled) or not
    supported by the implementation the input is returned unchanged.
    zpkg.resolve_capabilitiesr�Fr)rkr�rGr�rrr�_resolve_capabilities�s
r�c0s�t|t�rt|�dkr|iddd�S|r't||f�s'|r$||ig}d}n|g}t|d<tjj�t	|�}|rAt
|fd|i|��\}}t|	t�sJ|	du}	|	sQt|	t�r\dtvr\|id	d
d�St|t�si|durit|�}||d<t
||||f|||	|
|||d�|��}z|\��}�}}}|r�d	}Wn�t�y^d
tv�rZd|v�rZz|dr�d
nd}t||||d��Wnttfy�}z|id	t|�d�WYd}~YSd}~wwd�vr�ds�|id	d��d�d�YS�fdd��D�}�fdd��D�}�fdd��D�}|D] }|dd�|d�7<|d|d<|d|d|d<�q|D]}|dd�|d�7<|d|d<�q*|D]}|dd�|d�7<|d|d<�qC|YSw|�r|dtv�r||id	dd�}|�rz|�dg��|�|S|�r�dd����D�}|�dd����D��n|�r�|}�fd d�|D�}|��fd!d�|D��g}i}t	d"�rr��r�|�r��}n	�fd#d��D�}d$���}|�d%d&��D��|�d'|���|�r�|�d(�d$�|���|�d)d&�|D����rZ|�r1g} �D]}!|�r| �|!�n| �t|!���|�d*d&�| D���qd+}"|"d$�| �7}"|�|"�n)�D]&}!|�r;|!}#nt|!��}#|�d,�|#��|�|!ii�|�t||!���q3||dd-�|�d�}|�rp|�dg��|�|Sd}d}d}��s~��r�ztd.dbd||||||t��|
|
|d	d/�|��}$WnDt�y�}z7|d	d0�}|j�r�|j�di�|d<|j|d<ni|d<d1�|�|d<|�r�|�dg��|�|WYd}~Sd}~ww|�r�d	}t|$t��r�|�|$�n
t|$t��r�|�|$�i}$d
tv�r�d|v�r�z|d�r
d
nd}t||�d2��Wn4ttf�yL}z%|�t|��||d	d-�|�d�}|�r@|�dg��|�|WYd}~Sd}~wwd�v�rq�d�sq|id	d��d�d�}|�ro|�dg��|�|S�fd3d��D�}�fd4d��D�}�fd5d��D�}|�r�td|�|d6<|�r��fd7d�|D����fd8d��D�}%�fd9d��D�}&nTtd:d;k�r�d|d<<td=dbd>di|��}'|�d?d	��r�d@tv�r�td@dbi|��}(ni}(t �|'||(dA�\})}&�fdBd�|)D����fdCd�|)D�}%�fdDd�|&D�}&��rQ|�rd$���}nd$��fdEd��D��}t|�dFk�r3|�dG|���n|�dH�t��t��dIk�rCdJndKt��dIk�rMdLndM��|�r�|D]y}|d}*|*|v�r�|�|d�t||*dN�dk�r}||*dNd-7<||*dNdO�|ddN�7<t||*dP�dk�r�||*dPd-7<||*dPdO�|ddP�7<�qV|�|d�i||*<dO�|ddN�||*dN<�qV|%�r|�r�d$�|%�}nd$��fdQd�|%D��}t|%�dFk�r�|�dR|���n|�dS�t|%�t|%�dIk�rdJndKt|%�dIk�rdLndM��|�r&|D]
}|�|d��qd}|&�rK|�r4d$�|&�}nd$��fdTd�|&D��}|�!ddU|���d	}|�r]|D]
}|�|d��qPd	}t|	t��rwtdVdW�|	D���rwt"dXdW�|	D��}+ng}+t|	t��r�tdYdW�|	D���r�t"dZdW�|	D��},ng},g�g}&�D]<}!|�r�|!|$v�r���|!��q�|&�|!��q�|	�r�td|!f|+|,d[�|��}-|-�r�|&�|!�|-||!<�q���|!��q���r�D]2}.|�r�|.}#nt|.��}#d\|#�d]�}"|.|v�r	|"d^7}"|�|"�|�t||.���q�|�|"��q�|&�rJ|&D]2}/|�r|/}#nt|/��}#d_|#�d`�}"|/|v�rA|"da7}"|�|"�|�t||/���q|�|"��qd	}|||d-�|�d�}|�r`|�dg��|�|S)cu�_
    Ensure that the package is installed, and that it is the correct version
    (if specified).

    .. note::
        Any argument which is either a) not explicitly defined for this state,
        or b) not a global state argument like ``saltenv``, or
        ``reload_modules``, will be passed through to the call to
        ``pkg.install`` to install the package(s). For example, you can include
        a ``disablerepo`` argument on platforms that use yum/dnf to disable
        that repo:

        .. code-block:: yaml

            mypkg:
              pkg.installed:
                - disablerepo: base,updates

        To see what is supported, check :ref:`this page <virtual-pkg>` to find
        the documentation for your platform's ``pkg`` module, then look at the
        documentation for the ``install`` function.

        Any argument that is passed through to the ``install`` function, which
        is not defined for that function, will be silently ignored.

    :param str name:
        The name of the package to be installed. This parameter is ignored if
        either "pkgs" or "sources" is used. 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 detailed
        below.

    :param str version:
        Install a specific version of a package. This option is ignored if
        "sources" is used. Currently, this option is supported
        for the following pkg providers: :mod:`apt <salt.modules.aptpkg>`,
        :mod:`ebuild <salt.modules.ebuild>`,
        :mod:`pacman <salt.modules.pacman>`,
        :mod:`pkgin <salt.modules.pkgin>`,
        :mod:`win_pkg <salt.modules.win_pkg>`,
        :mod:`yum <salt.modules.yumpkg>`, and
        :mod:`zypper <salt.modules.zypperpkg>`. The version number includes the
        release designation where applicable, to allow Salt to target a
        specific release of a given version. When in doubt, using the
        ``pkg.latest_version`` function for an uninstalled package will tell
        you the version available.

        .. code-block:: bash

            # salt myminion pkg.latest_version vim-enhanced
            myminion:
                2:7.4.160-1.el7

        .. important::
            As of version 2015.8.7, for distros which use yum/dnf, packages
            which have a version with a nonzero epoch (that is, versions which
            start with a number followed by a colon like in the
            ``pkg.latest_version`` output above) must have the epoch included
            when specifying the version number. For example:

            .. code-block:: yaml

                vim-enhanced:
                  pkg.installed:
                    - version: 2:7.4.160-1.el7

            In version 2015.8.9, an **ignore_epoch** argument has been added to
            :py:mod:`pkg.installed <salt.states.pkg.installed>`,
            :py:mod:`pkg.removed <salt.states.pkg.removed>`, and
            :py:mod:`pkg.purged <salt.states.pkg.purged>` states, which
            causes the epoch to be disregarded when the state checks to see if
            the desired version was installed.

        Also, while this function is not yet implemented for all pkg frontends,
        :mod:`pkg.list_repo_pkgs <salt.modules.yumpkg.list_repo_pkgs>` will
        show all versions available in the various repositories for a given
        package, irrespective of whether or not it is installed.

        .. code-block:: bash

            # salt myminion pkg.list_repo_pkgs bash
            myminion:
            ----------
                bash:
                    - 4.2.46-21.el7_3
                    - 4.2.46-20.el7_2

        This function was first added for :mod:`pkg.list_repo_pkgs
        <salt.modules.yumpkg.list_repo_pkgs>` in 2014.1.0, and was expanded to
        :py:func:`Debian/Ubuntu <salt.modules.aptpkg.list_repo_pkgs>` and
        :py:func:`Arch Linux <salt.modules.pacman.list_repo_pkgs>`-based
        distros in the 2017.7.0 release.

        The version strings returned by either of these functions can be used
        as version specifiers in pkg states.

        You can install a specific version when using the ``pkgs`` argument by
        including the version after the package:

        .. code-block:: yaml

            common_packages:
              pkg.installed:
                - pkgs:
                  - unzip
                  - dos2unix
                  - salt-minion: 2015.8.5-1.el6

        If the version given is the string ``latest``, the latest available
        package version will be installed à la ``pkg.latest``.

        **WILDCARD VERSIONS**

        As of the 2017.7.0 release, this state now supports wildcards in
        package versions for SUSE SLES/Leap/Tumbleweed, Debian/Ubuntu,
        RHEL/CentOS, Arch Linux, and their derivatives. Using wildcards can be
        useful for packages where the release name is built into the version in
        some way, such as for RHEL/CentOS which typically has version numbers
        like ``1.2.34-5.el7``. An example of the usage for this would be:

        .. code-block:: yaml

            mypkg:
              pkg.installed:
                - version: '1.2.34*'

        Keep in mind that using wildcard versions will result in a slower state
        run since Salt must gather the available versions of the specified
        packages and figure out which of them match the specified wildcard
        expression.

    :param bool refresh:
        This parameter controls whether or not the package repo database is
        updated prior to installing the requested package(s).

        If ``True``, the package database will be refreshed (``apt-get
        update`` or equivalent, depending on platform) before installing.

        If ``False``, the package database will *not* be refreshed before
        installing.

        If unset, then Salt treats package database refreshes differently
        depending on whether or not a ``pkg`` state has been executed already
        during the current Salt run. Once a refresh has been performed in a
        ``pkg`` state, for the remainder of that Salt run no other refreshes
        will be performed for ``pkg`` states which do not explicitly set
        ``refresh`` to ``True``. This prevents needless additional refreshes
        from slowing down the Salt run.

    :param str cache_valid_time:

        .. versionadded:: 2016.11.0

        This parameter sets the value in seconds after which the cache is
        marked as invalid, and a cache update is necessary. This overwrites
        the ``refresh`` parameter's default behavior.

        Example:

        .. code-block:: yaml

            httpd:
              pkg.installed:
                - fromrepo: mycustomrepo
                - skip_verify: True
                - skip_suggestions: True
                - version: 2.0.6~ubuntu3
                - refresh: True
                - cache_valid_time: 300
                - allow_updates: True
                - hold: False

        In this case, a refresh will not take place for 5 minutes since the last
        ``apt-get update`` was executed on the system.

        .. note::

            This parameter is available only on Debian based distributions and
            has no effect on the rest.

    :param str fromrepo:
        Specify a repository from which to install

        .. note::

            Distros which use APT (Debian, Ubuntu, etc.) do not have a concept
            of repositories, in the same way as YUM-based distros do. When a
            source is added, it is assigned to a given release. Consider the
            following source configuration:

            .. code-block:: text

                deb http://ppa.launchpad.net/saltstack/salt/ubuntu precise main

            The packages provided by this source would be made available via
            the ``precise`` release, therefore ``fromrepo`` would need to be
            set to ``precise`` for Salt to install the package from this
            source.

            Having multiple sources in the same release may result in the
            default install candidate being newer than what is desired. If this
            is the case, the desired version must be specified using the
            ``version`` parameter.

            If the ``pkgs`` parameter is being used to install multiple
            packages in the same state, then instead of using ``version``,
            use the method of version specification described in the **Multiple
            Package Installation Options** section below.

            Running the shell command ``apt-cache policy pkgname`` on a minion
            can help elucidate the APT configuration and aid in properly
            configuring states:

            .. code-block:: bash

                root@saltmaster:~# salt ubuntu01 cmd.run 'apt-cache policy ffmpeg'
                ubuntu01:
                    ffmpeg:
                    Installed: (none)
                    Candidate: 7:0.10.11-1~precise1
                    Version table:
                        7:0.10.11-1~precise1 0
                            500 http://ppa.launchpad.net/jon-severinsson/ffmpeg/ubuntu/ precise/main amd64 Packages
                        4:0.8.10-0ubuntu0.12.04.1 0
                            500 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages
                            500 http://security.ubuntu.com/ubuntu/ precise-security/main amd64 Packages
                        4:0.8.1-0ubuntu1 0
                            500 http://us.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages

            The release is located directly after the source's URL. The actual
            release name is the part before the slash, so to install version
            **4:0.8.10-0ubuntu0.12.04.1** either ``precise-updates`` or
            ``precise-security`` could be used for the ``fromrepo`` value.

    :param bool skip_verify:
        Skip the GPG verification check for the package to be installed

    :param bool skip_suggestions:
        Force strict package naming. Disables lookup of package alternatives.

        .. versionadded:: 2014.1.1

    :param bool resolve_capabilities:
        Turn on resolving capabilities. This allow one to name "provides" or alias names for packages.

        .. versionadded:: 2018.3.0

    :param bool allow_updates:
        Allow the package to be updated outside Salt's control (e.g. auto
        updates on Windows). This means a package on the Minion can have a
        newer version than the latest available in the repository without
        enforcing a re-installation of the package.

        .. versionadded:: 2014.7.0

        Example:

        .. code-block:: yaml

            httpd:
              pkg.installed:
                - fromrepo: mycustomrepo
                - skip_verify: True
                - skip_suggestions: True
                - version: 2.0.6~ubuntu3
                - refresh: True
                - allow_updates: True
                - hold: False

    :param bool pkg_verify:

        .. versionadded:: 2014.7.0

        Use pkg.verify to check if already installed packages require
        reinstallion. Requested packages that are already installed and not
        targeted for up- or downgrade are verified with pkg.verify to determine
        if any file installed by the package have been modified or if package
        dependencies are not fulfilled. ``ignore_types`` and ``verify_options``
        can be passed to pkg.verify. See examples below. Currently, this option
        is supported for the following pkg providers:
        :mod:`yum <salt.modules.yumpkg>`,
        :mod:`zypperpkg <salt.modules.zypperpkg>`.

        Examples:

        .. code-block:: yaml

            httpd:
              pkg.installed:
                - version: 2.2.15-30.el6.centos
                - pkg_verify: True

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - pkgs:
                  - foo
                  - bar: 1.2.3-4
                  - baz
                - pkg_verify:
                  - ignore_types:
                    - config
                    - doc

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - pkgs:
                  - foo
                  - bar: 1.2.3-4
                  - baz
                - pkg_verify:
                  - ignore_types:
                    - config
                    - doc
                  - verify_options:
                    - nodeps
                    - nofiledigest

    :param list ignore_types:
        List of types to ignore when verifying the package

        .. versionadded:: 2014.7.0

    :param list verify_options:
        List of additional options to pass when verifying the package. These
        options will be added to the ``rpm -V`` command, prepended with ``--``
        (for example, when ``nodeps`` is passed in this option, ``rpm -V`` will
        be run with ``--nodeps``).

        .. versionadded:: 2016.11.0

    :param bool normalize:
        Normalize the package name by removing the architecture, if the
        architecture of the package is different from the architecture of the
        operating system. The ability to disable this behavior is useful for
        poorly-created packages which include the architecture as an actual
        part of the name, such as kernel modules which match a specific kernel
        version.

        .. versionadded:: 2014.7.0

        Example:

        .. code-block:: yaml

            gpfs.gplbin-2.6.32-279.31.1.el6.x86_64:
              pkg.installed:
                - normalize: False

    :param bool ignore_epoch:
        If this option is not explicitly set, and there is no epoch in the
        desired package version, the epoch will be implicitly ignored. Set this
        argument to ``True`` to explicitly ignore the epoch, and ``False`` to
        strictly enforce it.

        .. versionadded:: 2015.8.9

        .. versionchanged:: 3001
            In prior releases, the default behavior was to strictly enforce
            epochs unless this argument was set to ``True``.

    |

    **MULTIPLE PACKAGE INSTALLATION OPTIONS:**

    :param list pkgs:
        A list of packages to install from a software repository. All packages
        listed under ``pkgs`` will be installed via a single command.

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - pkgs:
                  - foo
                  - bar
                  - baz
                - hold: True

        ``NOTE:`` For :mod:`apt <salt.modules.aptpkg>`,
        :mod:`ebuild <salt.modules.ebuild>`,
        :mod:`pacman <salt.modules.pacman>`,
        :mod:`winrepo <salt.modules.win_pkg>`,
        :mod:`yum <salt.modules.yumpkg>`, and
        :mod:`zypper <salt.modules.zypperpkg>`,
        version numbers can be specified
        in the ``pkgs`` argument. For example:

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - pkgs:
                  - foo
                  - bar: 1.2.3-4
                  - baz

        Additionally, :mod:`ebuild <salt.modules.ebuild>`, :mod:`pacman
        <salt.modules.pacman>`, :mod:`zypper <salt.modules.zypperpkg>`,
        :mod:`yum/dnf <salt.modules.yumpkg>`, and :mod:`apt
        <salt.modules.aptpkg>` support the ``<``, ``<=``, ``>=``, and ``>``
        operators for more control over what versions will be installed. For
        example:

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - pkgs:
                  - foo
                  - bar: '>=1.2.3-4'
                  - baz

        ``NOTE:`` When using comparison operators, the expression must be enclosed
        in quotes to avoid a YAML render error.

        With :mod:`ebuild <salt.modules.ebuild>` is also possible to specify a
        use flag list and/or if the given packages should be in
        package.accept_keywords file and/or the overlay from which you want the
        package to be installed. For example:

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - pkgs:
                  - foo: '~'
                  - bar: '~>=1.2:slot::overlay[use,-otheruse]'
                  - baz

    :param list sources:
        A list of packages to install, along with the source URI or local path
        from which to install each package. In the example below, ``foo``,
        ``bar``, ``baz``, etc. refer to the name of the package, as it would
        appear in the output of the ``pkg.version`` or ``pkg.list_pkgs`` salt
        CLI commands.

        .. code-block:: yaml

            mypkgs:
              pkg.installed:
                - sources:
                  - foo: salt://rpms/foo.rpm
                  - bar: http://somesite.org/bar.rpm
                  - baz: ftp://someothersite.org/baz.rpm
                  - qux: /minion/path/to/qux.rpm

    **PLATFORM-SPECIFIC ARGUMENTS**

    These are specific to each OS. If it does not apply to the execution
    module for your OS, it is ignored.

    :param bool hold:
        Force the package to be held at the current installed version.

        Supported on YUM/DNF & APT based systems.

        .. versionadded:: 2014.7.0

        Supported on Zypper-based systems.

        .. versionadded:: 3003

    :param bool update_holds:
        If ``True``, and this function would update the package version, any
        packages which are being held will be temporarily unheld so that they
        can be updated. Otherwise, if this function attempts to update a held
        package, the held package(s) will be skipped and the state will fail.
        By default, this parameter is set to ``False``.

        Supported on YUM/DNF & APT based systems.

        .. versionadded:: 2016.11.0

        Supported on Zypper-based systems.

        .. versionadded:: 3003

    :param list names:
        A list of packages to install from a software repository. Each package
        will be installed individually by the package manager.

        .. warning::

            Unlike ``pkgs``, the ``names`` parameter cannot specify a version.
            In addition, it makes a separate call to the package management
            frontend to install each package, whereas ``pkgs`` makes just a
            single call. It is therefore recommended to use ``pkgs`` instead of
            ``names`` to install multiple packages, both for the additional
            features and the performance improvement that it brings.

    :param bool install_recommends:
        Whether to install the packages marked as recommended. Default is
        ``True``. Currently only works with APT-based systems.

        .. versionadded:: 2015.5.0

        .. code-block:: yaml

            httpd:
              pkg.installed:
                - install_recommends: False

    :param bool only_upgrade:
        Only upgrade the packages, if they are already installed. Default is
        ``False``. Currently only works with APT-based systems.

        .. versionadded:: 2015.5.0

        .. code-block:: yaml

            httpd:
              pkg.installed:
                - only_upgrade: True

        .. note::
            If this parameter is set to True and the package is not already
            installed, the state will fail.

    :param bool report_reboot_exit_codes:
       If the installer exits with a recognized exit code indicating that
       a reboot is required, the module function

           *win_system.set_reboot_required_witnessed*

       will be called, preserving the knowledge of this event
       for the remainder of the current boot session. For the time being,
       ``3010`` is the only recognized exit code,
       but this is subject to future refinement.
       The value of this param
       defaults to ``True``. This parameter has no effect
       on non-Windows systems.

       .. versionadded:: 2016.11.0

       .. code-block:: yaml

           ms vcpp installed:
             pkg.installed:
               - name: ms-vcpp
               - version: 10.0.40219
               - report_reboot_exit_codes: False

    :return:
        A dictionary containing the state of the software installation
    :rtype dict:

    .. note::

        The ``pkg.installed`` state supports the usage of ``reload_modules``.
        This functionality allows you to force Salt to reload all modules. In
        many cases, Salt is clever enough to transparently reload the modules.
        For example, if you install a package, Salt reloads modules because some
        other module or state might require the package which was installed.
        However, there are some edge cases where this may not be the case, which
        is what ``reload_modules`` is meant to resolve.

        You should only use ``reload_modules`` if your ``pkg.installed`` does some
        sort of installation where if you do not reload the modules future items
        in your state which rely on the software being installed will fail. Please
        see the :ref:`Reloading Modules <reloading-modules>` documentation for more
        information.

    .. seealso:: unless and onlyif

        If running pkg commands together with :ref:`aggregate <mod-aggregate-state>`
        isn't an option, you can use the :ref:`creates <creates-requisite>`,
        :ref:`unless <unless-requisite>`, or :ref:`onlyif <onlyif-requisite>`
        syntax to skip a full package run. This can be helpful in large environments
        with multiple states that include requisites for packages to be installed.

        .. code-block:: yaml

            # Using creates for a simple single-factor check
            install_nginx:
              pkg.installed:
                - name: nginx
                - creates:
                  - /etc/nginx/nginx.conf

        .. code-block:: yaml

            # Using file.file_exists for a single-factor check
            install_nginx:
              pkg.installed:
                - name: nginx
                - unless:
                  - fun: file.file_exists
                    args:
                      - /etc/nginx/nginx.conf

            # Using unless with a shell test
            install_nginx:
              pkg.installed:
                - name: nginx
                - unless: test -f /etc/nginx/nginx.conf

        .. code-block:: yaml

            # Using file.search for a two-factor check
            install_nginx:
              pkg.installed:
                - name: nginx
                - unless:
                  - fun: file.search
                    args:
                      - /etc/nginx/nginx.conf
                      - 'user www-data;'

        The above examples use different methods to reasonably ensure
        that a package has already been installed. First, with checking for a
        file that would be created with the package. Second, by checking for
        specific text within a file that would be created or managed by salt.
        With these requisists satisfied, creates/unless will return ``True`` and the
        ``pkg.installed`` state will be skipped.

        .. code-block:: bash

            # Example of state run without unless used
            salt 'saltdev' state.apply nginx
            saltdev:
            ----------
                      ID: install_nginx
                      Function: pkg.installed
                      Name: nginx
                      Result: True
                      Comment: All specified packages are already installed
                      Started: 20:11:56.388331
                      Duration: 4290.0 ms
                      Changes:

            # Example of state run using unless requisite
            salt 'saltdev' state.apply nginx
            saltdev:
            ----------
                      ID: install_nginx
                      Function: pkg.installed
                      Name: nginx
                      Result: True
                      Comment: unless condition is true
                      Started: 20:10:50.659215
                      Duration: 1530.0 ms
                      Changes:

        The result is a reduction of almost 3 seconds. In larger environments,
        small reductions in waiting time can add up.

        :ref:`Unless Requisite <unless-requisite>`
    rT�No packages to install providedrONr�r�r�Fzpkg.verify not implementedr3)r�rlr�rMr'r�r��pkg.hold�hold�
pkg.unhold)rPrkr�r-z?An error was encountered while holding/unholding package(s): {}rRc� g|]}�|dr�|�qS�rQrrC��hold_retrrrH��
��zinstalled.<locals>.<listcomp>c�,g|]}�|ds�|dr�|�qS�rQr-rrCr�rrrH��
�
��c� g|]}�|ds�|�qS�r-rrCr�rrrH�r�z.
{}rQrPzlowpkg.unpurgezlowpkg.unpurge not implementedr�cS�g|]\}}t||fg��qSr�r=r�rrrrH�cSr�rr�r�rrrrHr�c�(g|]}ttt|������vr|�qSr�r��iterr�rirC�rurrrH�(cr�rr�rC)r�rrrH
r��testc�g|]}t|���qSr�r�rCr�rrrH�r]cS�i|]}|ddd��qS��	installedr��new�oldrrCrrrr��zinstalled.<locals>.<dictcomp>z3The following packages would be installed/updated: z^The following packages would have their selection status changed from 'purge' to 'install': {}cSr�r�rrCrrrr�r�cSr�r�rrCrrrr�-r�z-The following packages would be reinstalled: zPPackage '{}' would be reinstalled because the following files have been altered:�
r)rPr�r8r��skip_verifyrkr�r�rM�update_holdsr'�
split_arch�rPr-�8An error was encountered while installing package(s): {}�rPrkcr�r�rrCr�rrrH�r�cr�r�rrCr�rrrH�r�cr�r�rrCr�rrrH�r�rBc�g|]}|�vr|�qSrrrCr�rrrH�r�c� g|]}|�vr|�vr|�qSrrrC�rur�rrrH�sc�g|]}|�vr|�qSrrrC)�modifiedrrrH�r�r|r}r~rArr�r�)r'r�cr�rrrCr�rrrH�r�crrrrCrrrrH�r�cr�rrrCr�rrrH�r�cr�rr�rC�rIrrrH�r��z/The following packages were installed/updated: z+{} targeted package{} {} installed/updated.r/�srZwereZwasr�z{}r�cr�rr�rCrrrrH�r�z/The following packages were already installed: z*{} targeted package{} {} already installedcr�rr�rCrrrrH�r�z1The following packages failed to install/update: csr�r�r�rCrrrr�r�zinstalled.<locals>.<genexpr>csr�r�r�rCrrrr�r�csr�r�r�rCrrrr�r�csr�r�r�rCrrrr�r�r�rZz was reinstalled.z% The following files were remediated:z)Reinstall was not successful for package �.z- The following files could not be remediated:r)#r<r�r1r��__env__rrr�
check_refreshr�r�r�strr��
ValueErrorrrrcr�r�rgrer�r+r�r�r��infor:�strerror_without_changesr=r�r��insertr�)0rPr8r�r�r�rlrkr�r3r�rMr'r�r�rGr-r�r�r�r��actionrvZ
modified_holdZnot_modified_holdZfailed_hold�ir�Z
oldsourcesrRrQZ_targets�summaryZreinstall_targetsZ
reinstall_pkgrwZpkgstr�pkg_retZnot_modifiedr�r�r�r�Zchange_namer�r�r�Zmodified_pkgZ
failed_pkgr)rIr�rrur�rr��s"�	

����	�����

�

�
�
��5��

����
���
�
����
���
�	
�
�
��
�

���
"&��
�
�
�
�
���

�





�r�c
sD|iddd�}dtvrd|d<d|d<|St|t�r*t|�d	kr*d
|d<d|d<|S|r;|s;|r8||ig}d}n|g}d|vrB|d=t|fi|��\}}t|||f||d
�|���t�t�rdd�vrd�St�t�svd|d<d���|d<|Stdr�d�	��}d�|�|d<|Sztdd|||d
||d�|��}	d
|d<|d�
|	�Wn6ty�}
z*|dd�}|
jr�|
j�
di�|d<|
j|d<ni|d<d|
��|d<|WYd}
~
Sd}
~
wwtddi|��}t�||d�\}}
|
�rd�	�fdd�|
D��}d|d<d|��|d<|d�s |d�s d
|d<d�d�	���|d<|S)aI
    .. versionadded:: 2017.7.0

    Ensure that the package is downloaded, and that it is the correct version
    (if specified).

    .. note::
        Any argument which is either a) not explicitly defined for this state,
        or b) not a global state argument like ``saltenv``, or
        ``reload_modules``, will be passed through to the call to
        ``pkg.install`` to download the package(s). For example, you can include
        a ``disablerepo`` argument on platforms that use yum/dnf to disable
        that repo:

        .. code-block:: yaml

            mypkg:
              pkg.downloaded:
                - disablerepo: base,updates

        To see what is supported, check :ref:`this page <virtual-pkg>` to find
        the documentation for your platform's ``pkg`` module, then look at the
        documentation for the ``install`` function.

        Any argument that is passed through to the ``install`` function, which
        is not defined for that function, will be silently ignored.

    Currently supported for the following pkg providers:
    :mod:`yum <salt.modules.yumpkg>`, :mod:`zypper <salt.modules.zypperpkg>` and :mod:`apt <salt.modules.aptpkg>`

    :param str name:
        The name of the package to be downloaded. This parameter is ignored if
        either "pkgs" is used. Additionally, please note that this option can
        only be used to download packages from a software repository.

    :param str version:
        Download a specific version of a package.

        .. important::
            As of version 2015.8.7, for distros which use yum/dnf, packages
            which have a version with a nonzero epoch (that is, versions which
            start with a number followed by a colon must have the epoch included
            when specifying the version number. For example:

            .. code-block:: yaml

                vim-enhanced:
                  pkg.downloaded:
                    - version: 2:7.4.160-1.el7

            An **ignore_epoch** argument has been added to which causes the
            epoch to be disregarded when the state checks to see if the desired
            version was installed.

            You can install a specific version when using the ``pkgs`` argument by
            including the version after the package:

            .. code-block:: yaml

                common_packages:
                  pkg.downloaded:
                    - pkgs:
                      - unzip
                      - dos2unix
                      - salt-minion: 2015.8.5-1.el6

    :param bool resolve_capabilities:
        Turn on resolving capabilities. This allow one to name "provides" or alias names for packages.

        .. versionadded:: 2018.3.0

    CLI Example:

    .. code-block:: yaml

        zsh:
          pkg.downloaded:
            - version: 5.0.5-4.63
            - fromrepo: "myrepository"
    NrrOrKFr-z:The pkg.downloaded state is not available on this platformrRrTz No packages to download provided�downloadonly)r�r'�3An error was encountered while checking targets: {}r�r]z.The following packages would be downloaded: {}r)rPrkr8rr�r'rQr��7An error was encountered while downloading package(s): r0cr�rr�rCr�rrrH�r�zdownloaded.<locals>.<listcomp>z+The following packages failed to download: zPackages downloaded: {}r)rr<r�r1r�rxr=rcr�rer�rrr:r
r�)rPr8rkr�r'rGr�Z_refreshrrrvr�r�r�rr�r�
downloaded_s�S
���
�
���	
���
rc

Ks�|iddd�}dtvrd|d<d|d<|St|t�r*t|�d	kr*d
|d<d|d<|St||fi|��}t|t�r>d|vr>|St|t�sPd|d<d�|�|d<|Std
rbd�|�}d|��|d<|Sztdd|||d�|��}d
|d<|d�	|�Wn6t
y�}z*|dd�}|jr�|j�di�|d<|j
|d<ni|d<d|��|d<|WYd}~Sd}~ww|ds�|ds�|r�dnd}	d
|d<d�|	�|d<|S)a�
    .. versionadded:: 2017.7.0

    Ensure that packages related to certain advisory ids are installed.

    .. note::
        Any argument which is either a) not explicitly defined for this state,
        or b) not a global state argument like ``saltenv``, or
        ``reload_modules``, will be passed through to the call to
        ``pkg.install`` to install the patch(es).

        To see what is supported, check :ref:`this page <virtual-pkg>` to find
        the documentation for your platform's ``pkg`` module, then look at the
        documentation for the ``install`` function.

        Any argument that is passed through to the ``install`` function, which
        is not defined for that function, will be silently ignored.

    Currently supported for the following pkg providers:
    :mod:`yum <salt.modules.yumpkg>` and :mod:`zypper <salt.modules.zypperpkg>`

    CLI Example:

    .. code-block:: yaml

        issue-foo-fixed:
          pkg.patch_installed:
            - advisory_ids:
              - SUSE-SLE-SERVER-12-SP2-2017-185
              - SUSE-SLE-SERVER-12-SP2-2017-150
              - SUSE-SLE-SERVER-12-SP2-2017-120
    NrrO�pkg.list_patchesFr-z?The pkg.patch_installed state is not available on this platformrRrTzNo advisory ids providedrr�r]z4The following advisory patches would be downloaded: r�rPrzrrQr�rrr�z?Advisory patch is not needed or related packages are already {}r)rr<r�r1r{r=rcr�rer�rrr:r
)
rPrzrrGr�rurrrv�statusrrr�patch_installed
	sf!�
�
���
���
��rcKs:dtvr|didd�Sd|vr|d=td	||dd�|��S)
a
    .. versionadded:: 2017.7.0

    Ensure that packages related to certain advisory ids are downloaded.

    Currently supported for the following pkg providers:
    :mod:`yum <salt.modules.yumpkg>` and :mod:`zypper <salt.modules.zypperpkg>`

    CLI Example:

    .. code-block:: yaml

        preparing-to-fix-issues:
          pkg.patch_downloaded:
            - advisory_ids:
              - SUSE-SLE-SERVER-12-SP2-2017-185
              - SUSE-SLE-SERVER-12-SP2-2017-150
              - SUSE-SLE-SERVER-12-SP2-2017-120
    rFz@The pkg.patch_downloaded state is not available on this platform)rPr-rQrRrTrNr)rr)rPrzrGrrr�patch_downloadedj	s���rc
stjj�t|�}|�d�r|iddd�S|r(tt|����}|s'|iddd�Snt	|t�r:t
|�dkr:|iddd�S|g}t|d	<t|fd
|i|��\}}zt
d|||d�|��}Wntyw}	z|idd
�|	�d�WYd}	~	Sd}	~	wwzt
d|i|���Wnty�}	z|id|	jd�WYd}	~	Sd}	~	wwt	�t�r�|d�i�t	|t�r�|d|i}i�g}
|D]9}|�|�s��|�s�d|�d�}t�|�|
�|�q�|r�t�d�dkr�t
d|�r�|�|<q�||�|<q�|
�r|idd�|
�d�S��r]|�s
g}
n	�fdd�|D�}
td�rXg}|�dd�t����|
�rNt
|
�}|dk�rF|�dd��fdd�t|
�D���n|�|�d��|idd�|�d�Stjj���ri�fd d��D�}nt��}zt
d!d5dd|||d"�|���Wnt�y�}	z|idd#�|	�d�WYd}	~	Sd}	~	ww��r��fd$d��D���fd%d��D�}g}��r�d&�d�t����}|�|�|�r�d'�d�t|���}|�|�|
�r�t
|
�dk�r�d(�d�t|
���}nt
|
��d)�}|�|�|���rdndd�|�d�St
��dk�rd*�t
���}nt
��d+k�r)d,�d�t����}n
d-�ttt�������}|
�rVt
|
�dk�rM|d.�d�t|
���7}n	|d/�t
|
��7}|�d|d�St
|�dk�rmd0t
|��d1�}nt
|�d+k�rd2�d�t|���}nd3|d�d4�}|id|d�S)6a�
    Ensure that the named package is installed and the latest available
    package. If the package can be updated, this state function will update
    the package. Generally it is better for the
    :mod:`installed <salt.states.pkg.installed>` function to be
    used, as :mod:`latest <salt.states.pkg.latest>` will update the package
    whenever a new package is available.

    .. note::
        Any argument which is either a) not explicitly defined for this state,
        or b) not a global state argument like ``saltenv``, or
        ``reload_modules``, will be passed through to the call to
        ``pkg.install`` to install the package(s). For example, you can include
        a ``disablerepo`` argument on platforms that use yum/dnf to disable
        that repo:

        .. code-block:: yaml

            mypkg:
              pkg.latest:
                - disablerepo: base,updates

        To see what is supported, check :ref:`this page <virtual-pkg>` to find
        the documentation for your platform's ``pkg`` module, then look at the
        documentation for the ``install`` function.

        Any argument that is passed through to the ``install`` function, which
        is not defined for that function, will be silently ignored.

    name
        The name of the package to maintain at the latest available version.
        This parameter is ignored if "pkgs" is used.

    fromrepo
        Specify a repository from which to install

    skip_verify
        Skip the GPG verification check for the package to be installed

    refresh
        This parameter controls whether or not the package repo database is
        updated prior to checking for the latest available version of the
        requested packages.

        If ``True``, the package database will be refreshed (``apt-get update``
        or equivalent, depending on platform) before checking for the latest
        available version of the requested packages.

        If ``False``, the package database will *not* be refreshed before
        checking.

        If unset, then Salt treats package database refreshes differently
        depending on whether or not a ``pkg`` state has been executed already
        during the current Salt run. Once a refresh has been performed in a
        ``pkg`` state, for the remainder of that Salt run no other refreshes
        will be performed for ``pkg`` states which do not explicitly set
        ``refresh`` to ``True``. This prevents needless additional refreshes
        from slowing down the Salt run.

    :param str cache_valid_time:

        .. versionadded:: 2016.11.0

        This parameter sets the value in seconds after which the cache is
        marked as invalid, and a cache update is necessary. This overwrites
        the ``refresh`` parameter's default behavior.

        Example:

        .. code-block:: yaml

            httpd:
              pkg.latest:
                - refresh: True
                - cache_valid_time: 300

        In this case, a refresh will not take place for 5 minutes since the last
        ``apt-get update`` was executed on the system.

        .. note::

            This parameter is available only on Debian based distributions and
            has no effect on the rest.

    :param bool resolve_capabilities:
        Turn on resolving capabilities. This allow one to name "provides" or alias names for packages.

        .. versionadded:: 2018.3.0

    Multiple Package Installation Options:

    (Not yet supported for: FreeBSD, OpenBSD, MacOS, and Solaris pkgutil)

    pkgs
        A list of packages to maintain at the latest available version.

    .. code-block:: yaml

        mypkgs:
          pkg.latest:
            - pkgs:
              - foo
              - bar
              - baz

    install_recommends
        Whether to install the packages marked as recommended. Default is
        ``True``. Currently only works with APT-based systems.

        .. versionadded:: 2015.5.0

    .. code-block:: yaml

        httpd:
          pkg.latest:
            - install_recommends: False

    only_upgrade
        Only upgrade the packages, if they are already installed. Default is
        ``False``. Currently only works with APT-based systems.

        .. versionadded:: 2015.5.0

    .. code-block:: yaml

        httpd:
          pkg.latest:
            - only_upgrade: True

    .. note::
        If this parameter is set to True and the package is not already
        installed, the state will fail.

    report_reboot_exit_codes
        If the installer exits with a recognized exit code indicating that
        a reboot is required, the module function

           *win_system.set_reboot_required_witnessed*

        will be called, preserving the knowledge of this event
        for the remainder of the current boot session. For the time being,
        ``3010`` is the only recognized exit code, but this
        is subject to future refinement. The value of this param
        defaults to ``True``. This parameter has no effect on
        non-Windows systems.

        .. versionadded:: 2016.11.0

        .. code-block:: yaml

           ms vcpp installed:
             pkg.latest:
               - name: ms-vcpp
               - report_reboot_exit_codes: False
    r�Fz)The "sources" parameter is not supported.rOz5Invalidly formatted "pkgs" parameter. See minion log.rTr�r�r�r�)r�r�zVAn error was encountered while checking the newest available version of package(s): {}N�pkg.versionzNo information found for 'z'.r|�Gentoozportage_config.is_changed_usesracrrrrCr�rrrH�
r�zlatest.<locals>.<listcomp>r�z4The following packages would be installed/upgraded: r]�
z/The following packages are already up-to-date: cs g|]}|�d�|�d��qS)z (�)rrC)�currrrH�
r�z  packages are already up-to-dater�csg|]}|�|i�qSrrrCr�rrrH�
r�r)rPr�r�r�rkr�csTg|]&}��|�r&�|�d�dur(�|�|�d��d�vr(�|dkr|�qS)r�Nr)r�)r:r*rC)rQrurrrH�
s��crrrrC)r�rrrH�
r�z+The following packages failed to update: {}z?The following packages were successfully installed/upgraded: {}z2The following packages were already up-to-date: {}z" packages were already up-to-date zA{} targeted packages failed to update. See debug log for details.r/zRThe following targeted packages failed to update. See debug log for details: ({}).zPackage {} failed to update.z3 The following packages were already up-to-date: {}z#{} packages were already up-to-datezAll z packages are up-to-date.z!All packages are up-to-date ({}).rZz is already up-to-dater)rrrr	r�r:r�rrir<r1rr�rrrcrjr
r��errorr+r�rerfr;r�r�r�)rPr�r�r�rkZwatch_flagsrGZdesired_pkgsZavailrvrrrrwZ
up_to_datersZup_to_date_countZ
targeted_pkgsZ
successfulrRr)rQr r�rurr��	s�%
���	���
��
������




�
���
��
�����
�������
�
�
�
���������r��removec
s"�dvr|idd��d�d�Sztd||f||d�|��d}Wnty=}z|idd	|��d�WYd
}~Sd
}~wwt||||fd|i|���t�t�r]d�vr]�d
kr[g�n�St�t�ss�d
krig�n
|idd���d�S�d
kr�tdd+ddd�|������fdd�|D������s�|idd��d
kr�d�d�Sd�d�St	dr�i}	|	�
�fdd��D��||	d
d��d����d�Std���|f||dd�|��}
tdd+ddi|��}g}|D];}
tdd v�r|
|vr�||
s�|�
|
�q�|
|v�r||
||
v�r|�
|
d!||
�q�|
|v�r#|�
|
�q�d
k�rAtdd+ddd�|���|��fd"d�|D��|��|�rV||
dd#��d�|��d�Sg}t�fd$d%�|D��}|�r~|�
d&�d�|���|�
d'��d�����n	|�
d(��d)��||
dd*�|�d�S),z-
    Common function for package removal
    )r"�purgeFzInvalid action 'z'. This is probably a bug.rOzpkg_resource.parse_targets)rMr8rz0An error was encountered while parsing targets: Nr'r-r#rrAT)r�removedcr�rrrC)�old_removedrrrHjr�z_uninstall.<locals>.<listcomp>z-None of the targeted packages are installed{}z or partially installedrr�csi|]}|��d�dd��qS)�drr�rrC)rrrr�yr�z_uninstall.<locals>.<dictcomp>z'The following packages will be {}d: {}.r]�pkg.)rkr8r�rr�)ZSuseZRedHat�Windows�-cr�rrrC)�new_removedrrrH�r�z(The following packages failed to {}: {}.c3s�|]	}|�vr|VqdSrUrrCr�rrr��s�z_uninstall.<locals>.<genexpr>z-The following packages were not installed: {}z$The following packages were {}d: {}.zAll targeted packages were zd.rar)rrr�r<r=r�rcr��sortr�r�rer�r+rf)rrPr8rkrMr'rGZ
pkg_paramsrvZ_changesrQr�r��paramrsr�r)rr*r%rur�
_uninstall1s�
�����������
����
����	
��	����

�
��
��	����r-c
K�t|d<ztd
d|||||d�|��WStyI}z*|dd�}|jr2|j�di�|d<|j|d<ni|d<d|��|d<|WYd	}~Sd	}~ww)a�

    Verify that a package is not installed, calling ``pkg.remove`` if necessary
    to remove the package.

    name
        The name of the package to be removed.

    version
        The version of the package that should be removed. Don't do anything if
        the package is installed with an unmatching version.

        .. important::
            As of version 2015.8.7, for distros which use yum/dnf, packages
            which have a version with a nonzero epoch (that is, versions which
            start with a number followed by a colon like in the example above)
            must have the epoch included when specifying the version number.
            For example:

            .. code-block:: yaml

                vim-enhanced:
                  pkg.removed:
                    - version: 2:7.4.160-1.el7

            In version 2015.8.9, an **ignore_epoch** argument has been added to
            :py:mod:`pkg.installed <salt.states.pkg.installed>`,
            :py:mod:`pkg.removed <salt.states.pkg.removed>`, and
            :py:mod:`pkg.purged <salt.states.pkg.purged>` states, which
            causes the epoch to be disregarded when the state checks to see if
            the desired version was installed. If **ignore_epoch** was not set
            to ``True``, and instead of ``2:7.4.160-1.el7`` a version of
            ``7.4.160-1.el7`` were used, this state would report success since
            the actual installed version includes the epoch, and the specified
            version would not match.

    normalize : True
        Normalize the package name by removing the architecture, if the
        architecture of the package is different from the architecture of the
        operating system. The ability to disable this behavior is useful for
        poorly-created packages which include the architecture as an actual
        part of the name, such as kernel modules which match a specific kernel
        version.

        .. versionadded:: 2015.8.0

    ignore_epoch : None
        If this option is not explicitly set, and there is no epoch in the
        desired package version, the epoch will be implicitly ignored. Set this
        argument to ``True`` to explicitly ignore the epoch, and ``False`` to
        strictly enforce it.

        .. versionadded:: 2015.8.9

        .. versionchanged:: 3001
            In prior releases, the default behavior was to strictly enforce
            epochs unless this argument was set to ``True``.

    Multiple Package Options:

    pkgs
        A list of packages to remove. Must be passed as a python list. The
        ``name`` parameter will be ignored if this option is passed. It accepts
        version numbers as well.

        .. versionadded:: 0.16.0
    r�r"�rrPr8rkrMr'Fr�rQrRz4An error was encountered while removing package(s): Nr�rr-rrr:r
�rPr8rkrMr'rGrvr�rrrr$�s.C��	
���r$c
Kr.)a�

    Verify that a package is not installed, calling ``pkg.purge`` if necessary
    to purge the package. All configuration files are also removed.

    name
        The name of the package to be purged.

    version
        The version of the package that should be removed. Don't do anything if
        the package is installed with an unmatching version.

        .. important::
            As of version 2015.8.7, for distros which use yum/dnf, packages
            which have a version with a nonzero epoch (that is, versions which
            start with a number followed by a colon like in the example above)
            must have the epoch included when specifying the version number.
            For example:

            .. code-block:: yaml

                vim-enhanced:
                  pkg.purged:
                    - version: 2:7.4.160-1.el7

            In version 2015.8.9, an **ignore_epoch** argument has been added to
            :py:mod:`pkg.installed <salt.states.pkg.installed>`,
            :py:mod:`pkg.removed <salt.states.pkg.removed>`, and
            :py:mod:`pkg.purged <salt.states.pkg.purged>` states, which
            causes the epoch to be disregarded when the state checks to see if
            the desired version was installed. If **ignore_epoch** was not set
            to ``True``, and instead of ``2:7.4.160-1.el7`` a version of
            ``7.4.160-1.el7`` were used, this state would report success since
            the actual installed version includes the epoch, and the specified
            version would not match.

    normalize : True
        Normalize the package name by removing the architecture, if the
        architecture of the package is different from the architecture of the
        operating system. The ability to disable this behavior is useful for
        poorly-created packages which include the architecture as an actual
        part of the name, such as kernel modules which match a specific kernel
        version.

        .. versionadded:: 2015.8.0

    ignore_epoch : None
        If this option is not explicitly set, and there is no epoch in the
        desired package version, the epoch will be implicitly ignored. Set this
        argument to ``True`` to explicitly ignore the epoch, and ``False`` to
        strictly enforce it.

        .. versionadded:: 2015.8.9

        .. versionchanged:: 3001
            In prior releases, the default behavior was to strictly enforce
            epochs unless this argument was set to ``True``.

    Multiple Package Options:

    pkgs
        A list of packages to purge. Must be passed as a python list. The
        ``name`` parameter will be ignored if this option is passed. It accepts
        version numbers as well.

        .. versionadded:: 0.16.0
    r�r#r/Fr�rQrRz3An error was encountered while purging package(s): Nrr0r1rrr�purgeds,C��	
��r2c
s&|iddd��dtvrd�d<�Sd�vr!tdd	kr!d
�d<�St|t�r~t�fd|i���\�}z1tdd d|i���}�fdd
�|��D�}t�t�rb�fdd�|D�}�fdd
�|��D�}Wn ty}}zt|��d<�WYd}~Sd}~wwd�d<�S|s�d�d<d�d<�St	dr�d�d<|�d<d�d<�Sztdd |�d�����d<Wn1t
y�}z%|jr�|j�di��d<|j
�d<ni�d<d|���d<�WYd}~Sd}~wwg}t�t�r��fdd�|��D�}|�r	d�d�|���d<d�d<�Sd�d<d�d<�S)!a@
    .. versionadded:: 2014.7.0
    .. versionchanged:: 2018.3.0

        Added support for the ``pkgin`` provider.

    Verify that the system is completely up to date.

    :param str name
        The name has no functional value and is only used as a tracking
        reference

    :param bool refresh
        refresh the package database before checking for new upgrades

    :param list pkgs
        list of packages to upgrade

    :param bool resolve_capabilities:
        Turn on resolving capabilities. This allow one to name "provides" or alias names for packages.

        .. versionadded:: 2018.3.0

    :param kwargs
        Any keyword arguments to pass through to the ``pkg`` module.

        For example, for apt systems: `dist_upgrade`, `cache_valid_time`, `force_conf_new`

        .. versionadded:: 2015.5.0
    FzFailed to updaterOzpkg.list_upgradesz#State pkg.uptodate is not availablerRr�r|rz2'fromrepo' argument not supported on this platformr�cs,i|]\}}||td|fi���d��qS)rr�r�rDrWrrFrrr��s���zuptodate.<locals>.<dictcomp>cr�rr�rDr�rkrrrH�r�zuptodate.<locals>.<listcomp>csi|]\}}|�vr||�qSrrr3r5rrr��s
�Nz$refresh must be either True or FalsezSystem is already up-to-dateTr-r�zSystem update will be performedrQzpkg.upgrade)r�rkz2An error was encountered while updating packages: csg|]
}|�dvr|�qSr�rr4)r�rrrH�r�z-The following package(s) failed to update: {}r]zUpgrade ran successfullyr)rr�r<r�r�rgr��	Exceptionr
r�rrr:r
rircre)rPr�rkrGZpackages�expectedrv�missingr)rGrkr�r�uptodatepsv

�

���� ��
��r9c
s$|iddd�}dtvrd|d<|S�durg�nt�t�s#d|d<|St��D]\}}t|t�s6t|��|<q'|dur>g}nt|t�sId	|d<|St|�D]\}}t|t�s\t|�||<qMztd|fitjjjd)i�����}Wn,t	t
fy�}zd
t|�vr�d|d<nd|�d
|�d�|d<|WYd}~Sd}~ww|dd|dd}	�fdd�|	D�}
|
r�d�d�|
��|d<|S|dd}|�
�fdd�|ddD��|�
|�|s�d|d<d|�d�|d<|S|ddp�|ddp�|dd}td�rd|d<|�rd|�d�|d<|Sd|�d�|d<|Sztd d)d!|i���|d"<Wn9t	�yf}
z,|dd#�}|
j�rN|
j�d"i�|d"<|
j|d<ni|d"<d$�||
�|d<|WYd}
~
Sd}
~
ww�fd%d�|D�}|�rd&�d�|��|d<|Sd|d<d'�||�r�d(nd�|d<|S)*a�
    .. versionadded:: 2015.8.0

    .. versionchanged:: 2016.11.0
        Added support in :mod:`pacman <salt.modules.pacman>`

    .. versionchanged:: 3006.2
        For RPM-based systems, support for ``fromrepo``, ``enablerepo``, and
        ``disablerepo`` (as used in :py:func:`pkg.install
        <salt.modules.yumpkg.install>`) has been added. This allows one to, for
        example, use ``enablerepo`` to perform a group install from a repo that
        is otherwise disabled.

    Ensure that an entire package group is installed. This state is currently
    only supported for the :mod:`yum <salt.modules.yumpkg>` and :mod:`pacman
    <salt.modules.pacman>` package managers.

    skip
        Packages that would normally be installed by the package group
        ("default" packages), which should not be installed.

        .. code-block:: yaml

            Load Balancer:
              pkg.group_installed:
                - skip:
                  - piranha

    include
        Packages which are included in a group, which would not normally be
        installed by a ``yum groupinstall`` ("optional" packages). Note that
        this will not enforce group membership; if you include packages which
        are not members of the specified groups, they will still be installed.

        .. code-block:: yaml

            Load Balancer:
              pkg.group_installed:
                - include:
                  - haproxy

        .. versionchanged:: 2016.3.0
            This option can no longer be passed as a comma-separated list, it
            must now be passed as a list (as shown in the above example).

    .. note::
        The below options are only supported on RPM-based systems

    fromrepo
        Restrict ``yum groupinfo`` to the specified repo(s).
        (e.g., ``yum --disablerepo='*' --enablerepo='somerepo'``)

        .. code-block:: yaml

            MyGroup:
              pkg.group_installed:
                - fromrepo: base,updates

        .. versionadded:: 3006.2

    enablerepo (ignored if ``fromrepo`` is specified)
        Specify a disabled package repository (or repositories) to enable.
        (e.g., ``yum --enablerepo='somerepo'``)

        .. code-block:: yaml

            MyGroup:
              pkg.group_installed:
                - enablerepo: myrepo

        .. versionadded:: 3006.2

    disablerepo (ignored if ``fromrepo`` is specified)
        Specify an enabled package repository (or repositories) to disable.
        (e.g., ``yum --disablerepo='somerepo'``)

        .. code-block:: yaml

            MyGroup:
              pkg.group_installed:
                - disablerepo: epel

        .. versionadded:: 3006.2

    .. note::
        Because this is essentially a wrapper around :py:func:`pkg.install
        <salt.modules.yumpkg.install>`, any argument which can be passed to
        pkg.install may also be included here, and it will be passed on to the
        call to :py:func:`pkg.install <salt.modules.yumpkg.install>`.
    FrrOzpkg.group_diffz1pkg.group_install not available for this platformrRNz skip must be formatted as a listz#include must be formatted as a listzunexpected keyword argumentz/Repo options are not supported on this platformz:An error was encountered while installing/updating group 'z': r�	mandatoryr�z
not installedcr�rrrC��skiprrrH^
r�z#group_installed.<locals>.<listcomp>z6The following mandatory packages cannot be skipped: {}r]crrrrCr;rrrHh
r��defaultTr-zGroup 'z' is already installedZoptionalr�z,' is partially installed and will be updatedz' will be installedrrkrQr�zAAn error was encountered while installing/updating group '{}': {}cs&g|]}|tddi���vr|�qS)rArrrCrFrrrH�
s&z,Failed to install the following packages: {}zGroup '{}' was {}�updatedr)rr<r��	enumerater
rr�argsZclean_kwargsr�	TypeErrorrcrer�r�rr:r
)rPr<ZincluderGr��idx�item�diffr�r:Zinvalid_skipruZpartially_installedrvr�r)rGr<r�group_installed�s�[

�

��
�
���	�� 

�
�

��
�����rEcCsFd}dtvrtd|�}|ddks|ddkr!tjj�t�|SdS)a�
    Set a flag to tell the install functions to refresh the package database.
    This ensures that the package database is refreshed only once during
    a state run significantly improving the speed of package management
    during a state run.

    It sets a flag for a number of reasons, primarily due to timeline logic.
    When originally setting up the mod_init for pkg a number of corner cases
    arose with different package managers and how they refresh package data.

    It also runs the "ex_mod_init" from the package manager module that is
    currently loaded. The "ex_mod_init" is expected to work as a normal
    "mod_init" function.

    .. seealso::
       :py:func:`salt.modules.ebuild.ex_mod_init`

    Tzpkg.ex_mod_init�funr�r�F)rrrrZ
write_rtagr�)�lowr�rrr�mod_init�
srHc	Csng}d}gd�}|�d�|vr|S|D]�}td|�}||vr q|�d�dkr�d|vr,q|�d�|�d�kr7q|�d�|�d�krBqd	|vr\|durLd	}|d	kr[|�|d	�d
|d<qd|vr�|durfd}|dkr�d|vrz|�|d�d
|d<qd
|vr�|�dd�}|dur�|�|d
|i�n|�|d
�d
|d<q|dur�|r�||vr�||�|�|S|||<|S)z�
    The mod_aggregate function which looks up all packages in the available
    low chunks and merges them into a single pkgs ref in the present low data
    N)r�r�r$r2rFz
state.gen_tag�staterZ__agg__r�r�Tr�rkrPr8)r:Z	__utils__r�r�r+)	rG�chunksZrunningrkZpkg_typeZagg_enabled�chunk�tagr8rrr�
mod_aggregate�
sV�
��rMcKsL|�dd�}ttttd�}||vr|||fi|��S|id|�d�dd�S)a1
    Install/reinstall a package based on a watch requisite

    .. note::
        This state exists to support special handling of the ``watch``
        :ref:`requisite <requisites>`. It should not be called directly.

        Parameters for this function should be set by the state being triggered.
    �sfunN)r2r�r$r�r'z' does not work with the watch requisiteF�rPrQrRr-)r�r2r�r$r�)rPrGrNZmapfunrrr�	mod_watch�
s
�
�rPcKs�|iddd�}|�dd�}ddg}||vrB|�d�r;d	}d
|�d|��}||�d|g�d
|d�}tddi|��}|S|iddd�S|id�|�dd�S)a
    Create a beacon to monitor a package or packages
    based on a beacon state argument.

    .. note::
        This state exists to support special handling of the ``beacon``
        state argument for supported state functions. It should not be called directly.

    TrrOrNNr�r$ZbeaconrZbeacon_�_rk�<)rPrk�interval�
beacon_modulezbeacon.presentzNot adding beacon.rOz7pkg.{} does not work with the mod_beacon state functionFr)r�r:Z
__states__rc)rPrGr�rNZsupported_funcsrTZbeacon_nameZ
beacon_kwargsrrr�
mod_beacons4

��	��rUc	Ks<t|t�rt|�dkr|s|iddd�S|r'|dur'|r$||ig}d}n|g}i}d}dtvr7td�}d}nldtvr�tddd	�}t�d
�}|D]5}	|�|	�}
|
rw|
�d�}|dkr^d
}n|�d�}|�|
�d�d|�|
�d���ii�qI|�|	ii�qIn#dtvr�tddd�}|�	dg�D]	}	|�|	ii�q�n|iddd�Sdtvr�|iddd�S|idd
d�}g}
t
�}|D]�}t|t�r�tt
|����\}}n|}d}d}||vr�d||vr�||d}|�d�}|�|�||vs�|�r�||k�r�td�r*||v�r|
�d�||�sd
nd|�d���q�|
�d�||�s!d
nd|�d���q�d}||v�r:td||gd�}td||gd�}|�	|i��	d d��sRd|d <|�rx|�	|i��	d d��rx|�rx|�	|i��	d d��rx|
�d!|�d"��n!|�r�|�	|i��	d d��r�|
�d!|�d#��n	|
�d!|�d$��|d%�|�q�|�r|D]`}||�	d&d'�d'k�r��q�td�r�||v�r�|
�d(|����q�||v�rtd||gd�}|�	|i��	d d��s�d|d <|�r�|�	|i��	d)��r�|
�|�	|��	d)��|d%�|��q�d*�|
�|d)<|d%�s|d)�sd+|d)<|S),a4
    .. versionadded:: 3005

    Set package in 'hold' state, meaning it will not be changed.

    :param str name:
        The name of the package to be held. This parameter is ignored
        if ``pkgs`` is used.

    :param str version:
        Hold a specific version of a package.
        Full description of this parameter is in `installed` function.

        .. note::

            This parameter make sense for Zypper-based systems.
            Ignored for YUM/DNF and APT

    :param list pkgs:
        A list of packages to be held. All packages listed under ``pkgs``
        will be held.

        .. code-block:: yaml

            mypkgs:
              pkg.held:
                - pkgs:
                  - foo
                  - bar: 1.2.3-4
                  - baz

        .. note::

            For Zypper-based systems the package could be held for
            the version specified. YUM/DNF and APT ingore it.

    :param bool replace:
        Force replacement of existings holds with specified.
        By default, this parameter is set to ``False``.
    rTzNo packages to be held providedrONF�pkg.list_locks�pkg.list_holds��full�^(.+)-(\d+):(.*)\.\*��0rr%r/r8��pkg.get_selectionsr��rI�rNo any function to get the list of held packages available.
Check if the package manager supports package locking.r�z;`hold` function is not implemented for the package manager.�= r�z8The following package's hold rule would be updated: {}{}� (version = rz)The following package would be held: {}{}r�r�r-rZz was updated with hold rulez is now being heldz
 was not heldrQ�type�packagez'The following package would be unheld: rRr��No changes made)r<r�r1rr��compile�match�groupr�r:�setr=r�r�rg�lstrip�addr�r+rcre)rPr8rk�replacerG�locks�vr_lock�_locks�lock_re�lockrg�epochr�rsZ	held_pkgsr�pkg_name�pkg_ver�lock_ver�
unhold_retr�rrr�heldHs�*�	





(����




����
�����

��
�rwc	Ks�t|t�rt|�dkr|s|iddd�S|r!|dur!||ig}d}i}d}dtvr1td�}d}nldtvrztddd	�}t�d
�}|D]5}	|�|	�}
|
rq|
�d�}|dkrXd
}n|�d�}|�|
�d�d|�|
�d���ii�qC|�|	ii�qCn#dtvr�tddd�}|�	dg�D]	}	|�|	ii�q�n|iddd�Si}|D] }
t|
t
�r�tt|
�
���\}}|�||i�q�|�|
di�q�|idd
d�}g}|D]�}||�	dd�dkr�q�d}|r�d||vr�||d}|�d�}|s�||v�rQ|r�|||k�rQtd�r|�d�||�	|��sd
nd|�d���q�td||gd�}|�	|i��	dd��s2d|d<|�rJ|�	|i��	d ��rJ|�|�	|��	d ��|d!�|�q�d"�|�|d <|d!�sg|d �sgd#|d <|S)$a�
    .. versionadded:: 3005

    Unset package from 'hold' state, to allow operations with the package.

    :param str name:
        The name of the package to be unheld. This parameter is ignored
        if ``pkgs`` is used.

    :param str version:
        Unhold a specific version of a package.
        Full description of this parameter is in `installed` function.

        .. note::

            This parameter make sense for Zypper-based systems.
            Ignored for YUM/DNF and APT

    :param list pkgs:
        A list of packages to be unheld. All packages listed under ``pkgs``
        will be unheld.

        .. code-block:: yaml

            mypkgs:
              pkg.unheld:
                - pkgs:
                  - foo
                  - bar: 1.2.3-4
                  - baz

        .. note::

            For Zypper-based systems the package could be held for
            the version specified. YUM/DNF and APT ingore it.
            For ``unheld`` there is no need to specify the exact version
            to be unheld.

    :param bool all:
        Force removing of all existings locks.
        By default, this parameter is set to ``False``.
    rTz!No packages to be unheld providedrONFrVrWrXrZr[r\rr%r/r8r]r^r�r_r`rcrdrar�z+The following package would be unheld: {}{}rbrr�r�r-rRrQr�re)r<r�r1rr�rfrgrhr�r:r=r�r�rgrjr�r+rcre)rPr8rkr�rGrmrnrorprqrgrrZdpkgsrrsrtr�rsrurvrrr�unheld�s�,�	





(���

 
���rxrU)NF)NNNTFN)NN)NNNTN)
NNNNFFTNFF)F)
NNNFFNNFFTNFF)NNNN)NNFNT)r"NNNTN)NNTN)FN)NNF)H�__doc__r>�loggingr|r�Zsalt.utils.argsrZsalt.utils.pkgZsalt.utils.platformZsalt.utils.versionsZsalt.exceptionsrrrZsalt.modules.pkg_resourcerZsalt.outputrZsalt.utils.functoolsrZsalt.utils.odictrr��globalsrr;r�Zsalt.modules.win_pkgr	r
rrr
rrrr�	getLogger�__name__r�rr"r(r.r7r2rJrxr{r�r�r�r�rdr�r�r�rrrr�r-r$r2r9rErHrMrPrUrwrxrrrr�<module>s�F,�



�
3
�
%
�R
�
~/

	
�
�
,
`)
�$
�


\
Z
jEA
10