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

�N�g���@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zddl%m&Z&m'Z'm(Z(m)Z)ddl*m+Z+e�,e-�Z.zdd	l/m0Z0m1Z1d
Z2Wne3y�dZ2Ynwzddl4Z4d
Z5Wne3y�dZ5Ynwzddl6Z7d
Z8Wne3y�dZ8YnwdZ9d
Z:dZ;dZ<e=gd��Z>ddddd�Z?dZ@dd�ZAdd�ZBdd�ZCe2�s
Gdd�d�Z0Gdd�d�Z1d d!�ZDd"d#�ZEd�d$d%�ZFd&d'�ZGd(d)�ZHd*d+�ZId,d-�ZJejKjL�MeJd.�ZNd/d0�ZOd�d1d2�ZP										d�d3d4�ZQd�d6d7�ZRd�d8d9�ZSd�d:d5�ZTd�d;d<�ZUd�d=d>�ZVd�d?d@�ZWd�dAdB�ZXdCdD�ZY	d�dEdF�ZZd�dGdH�Z[d�dIdJ�Z\dKdL�Z]d�dMdN�Z^dOdP�Z_dQdR�Z`dSdT�ZadUdV�ZbdWdX�ZcdYdZ�Zdd[d\�Zed]d^�Zfd_d`�Zgdadb�Zhd�dcdd�Zidedf�Zj					g	
		d�dhdi�Zkdjdk�Zld�dldm�Zmd�dndo�Zndpdq�Zodrds�Zpd�dtdu�Zqdvdw�Zrd�dxdy�Zsd�dzd{�Ztd|d}�Zud~d�Zvd�d��Zwd�d��Zxd�d�d��Zyd�d��ZzdS)�a{
Support for APT (Advanced Packaging Tool)

.. 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>`.

    For repository management, the ``python-apt`` package must be installed.
�N)�OrderedDict)�	HTTPError)�Request)�urlopen)�CommandExecutionError�CommandNotFoundError�MinionError�SaltInvocationError)�
_parse_env)�SourceEntry�SourcesListTFz/var/lib/apt/lists�:z4deb http://ppa.launchpad.net/{0}/{1}/ubuntu {2} mainz@deb https://{0}private-ppa.launchpad.net/{1}/{2}/ubuntu {3} main)�uri�comps�
architectures�disabled�file�dist�signedbyZnoneZnoninteractive�1)ZAPT_LISTBUGS_FRONTENDZAPT_LISTCHANGES_FRONTENDZDEBIAN_FRONTENDZUCF_FORCE_CONFFOLD�pkgcCst�d�dkr	tSdS)z9
    Confirm this module is on a Debian-based system
    Z	os_familyZDebian)Fz9The pkg module could not be loaded: unsupported OS family)�
__grains__�get�__virtualname__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/aptpkg.py�__virtual__bs
rcCst�tkr
tj�t�dSdS)zv
    For Debian and derivative systems, set up
    a few env variables to keep apt happy and
    non-interactive.
    N)rr�os�environ�update�
DPKG_ENV_VARS)�optsrrr�__init__qs
�r"cCsBd}d}d}|��}|sd}|||dfS|�d�r!d}|dd�}|�d�}|dkr8||dd�}|d|�}t�d|���}|rcd	d
�|�d���D�|�d���gdd
�|�d
���D�}n|����}|rw|ddvswt|�d
krd}||||fS|d�d�r�tdd�|dd�D��s�d}||||fS||||fS)z�
    This is a workaround since python3-apt does not support
    the signed-by argument. This function was removed from
    the class to ensure users using the python3-apt module or
    not can use the signed-by option.
    F�T�#�Nrz(.*)(cdrom:.*/)(.*)cS�g|]}|���qSr��strip��.0�prrr�
<listcomp>��z_invalid.<locals>.<listcomp>�cSr&rr'r)rrrr,�r-���deb�deb-srcZrpmzrpm-src�[cs��|]}|�d�VqdS)�]N)�endswith�r*�xrrr�	<genexpr>���z_invalid.<locals>.<genexpr>)	r(�
startswith�find�re�match�group�split�len�any)�liner�invalid�comment�idxZcdrom_match�	repo_linerrr�_invalid|sD

����rHc@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)rNcCsnd|_g|_d|_d|_d|_d|_d|_||_g|_d|_	||_
|j
s0tt�
tjddd��|_
|�|�dS)NFr#�etc�apt�sources.list)rDrrrEr�typerrCrrr�str�pathlib�Pathr�sep�_parse_sources)�selfrCrrrrr"�szSourceEntry.__init__cCs|��S�N)rG�rRrrrrM�szSourceEntry.strcCs4g}|jr|jS|jr|�d�|�|j�t|j�}|jr:d|vr&i|d<dd�|j���|dd<|j|dd<|jrVd|vrEi|d<d|j��|dd<|j|dd<g}|�	�D]}|dd	krk|�|d�q\|rz|�d
d�|��d��||j
|jd�|j�g7}|j
r�|�d|j
���d�|�d
S)zC
            Return the repo line for the sources file
            r$�archzarch=�,�full�valuer�
signed-by=r#r3� r5�
)rDrCr�appendrL�	_get_optsr�joinr�valuesrrrrE)rRrGr!Zordered_opts�optrrrrG�s8

�zSourceEntry.repo_linec
Cst|�\|_|_|_}|jrdS|d�d�rndd�dd�|D�D�}t|j�}d|vr6|j�|dd	�d
|vrA|d
d	|_	|�
�D](}|d}|rmz
|�|�|��WqEt
yl|�|�d|d��YqEwqE|d
|_|d|_|d|_|dd�|_dS)z8
            Parse lines from sources files
            Fr%r3cSsg|]}|r|�qSrrr7rrrr,�r-z.SourceEntry._parse_sources.<locals>.<listcomp>csr4)�[]Nr'�r*rCrrrr9�r:z-SourceEntry._parse_sources.<locals>.<genexpr>rUrXrrWr5rr.r/NT)rHrrDrEr;r]rCr�extendrr_�pop�index�
ValueErrorrLrrr)rRrCrGr!r`rrrrQ�s0
��


zSourceEntry._parse_sourcesrS)�__name__�
__module__�__qualname__r"rMrGrQrrrrr�s

%rc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)rcCslg|_t�tjddd�t�tjddd�g|_|jD]}|��r.|�d�D]}|j|d�q$q|�|�qdS)NrIrJrKzsources.list.dz	**/*.list�r)	�listrNrOrrP�files�is_dir�glob�add_file)rRr�fprrrr"s�
��zSourcesList.__init__ccs�|jEdHdSrS)rkrTrrr�__iter__s�zSourcesList.__iter__cCsr|��r1tjj�t|���}|D]}|j�t|t|�d��qWd�dS1s*wYdSt	�
d|�dS)z>
            Add the lines of a file to self.list
            rjNz&The apt sources file %s does not exist)�is_file�salt�utilsrl�fopenrMrkr\r�log�debug)rRr�sourcerCrrrros�"�zSourcesList.add_filec
Cs�g}d}|rd�d�|��}|�|�|rd|��}|�|�t|�dkr/dd�|�d}nt|�dkr>dd�|�d}||||d�|�g}	td�d	d
�|	D���S)Nr#zarch={}rVrYr%r3rZr5cS�g|]}|��r|�qSrr'rbrrrr,3�z#SourcesList.add.<locals>.<listcomp>)�formatr^r\rAr)
rRrLrr�
orig_compsrrZ
opts_countZ	opts_linerGrrr�adds&


�zSourcesList.addcCs|j�|�dS)zB
            remove a source from the list of sources
            N)rk�remove)rRrxrrrr~5�zSourcesList.removec
Cs�i}t���X}|jD]:}t�|t�|j�j�}tjj	�
t|�d��}|�|�
��Wd�n1s3wY|j|vrDd|i||j<q
|D]}t�t||d�|�qGWd�dS1sawYdS)zd
            write all of the sources from the list of sources
            to the file.
            �aN�tmp)�tempfileZTemporaryDirectoryrkrNrOr�namersrtrlrurM�writerG�shutil�move)rRZfilemapZtmpdirrx�fnamerprrr�save;s

�
��"�zSourcesList.saveN)	rgrhrir"rqror}r~r�rrrrrs
rcCs2d�||�}t|ddid�}t|�}tjj�|�S)z�
    Idea from softwareproperties.ppa.
    Uses urllib2 which sacrifices server cert verification.

    This is used as fall-back code or for secure PPAs

    :param owner_name:
    :param ppa_name:
    :return:
    z-https://launchpad.net/api/1.0/~{}/+archive/{}ZAcceptzapplication/json)�headers)r{�_Request�_urlopenrsrt�json�load)�
owner_name�ppa_nameZlp_url�requestZlp_pagerrr�_get_ppa_info_from_launchpadMs�r�cCsd|�d|��S)z'
    Stringify PPA name from args.
    �ppa:�/r)r�r�rrr�_reconstruct_ppa_namearr�cKs�g}|rtjj�t�rtddd�r|�ddddt�d�g�|�|�dd	tjj�	t
��d
�}|�|�td|fi|��}d}d
|�dd�vrt|dkrt|d7}t
�d|�t�d|�td|fi|��}d
|�dd�vrt|dksM|S)z
    Call apt* utilities.
    z
config.getz
systemd.scopeTzsystemd-runz--scopez
--description�"�traceF)�output_loglevel�python_shell�env�cmd.run_allrzCould not get lock�stderrr#�
r%z1Waiting for dpkg lock release: retrying... %s/100r.)rsrtZsystemdZ	has_scope�__context__�__salt__rcrgZenvironmentZget_module_environment�globalsrrrv�warning�time�sleep)�args�scope�kwargs�cmd�params�cmd_ret�countrrr�	_call_apths.���
�
�r�cCst�d�t�d|�dS)z=
    Warn of missing python-software-properties package.
    z�The 'python-software-properties' package is not installed. For more accurate support of PPA repositories, you should install this package.zBest guess at ppa format: %sN)rvr�)�reporrr�_warn_software_properties�s�r�cCsNz
|�td�\}}Wnty|}td}Ynw|tdddfvr%|S|S)z�
    Strips the architecture from the specified package name, if necessary.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.normalize_name zsh:amd64
    r%�osarch�allrB)�rsplit�PKG_ARCH_SEPARATORrfr)r��pkgnameZpkgarchrrr�normalize_name�s
�r�cCs<z
|�td�\}}Wnty|d}}Ynw||d�S)z�
    Parse name and architecture from the specified package name.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.parse_arch zsh:amd64
    r%N)r�rU)r�r�rf)r��_nameZ_archrrr�
parse_arch�s
�
r�cs�tjj�|�dd��}tjj�|�dd��}d|vrtd��|�dd�}|�d	d
�}|s.dSi}|D]}d||<q2tdd�}|rGd
d|��gnd}	|rOt|�|D]i}ddd|g}
|	durb|
�|	�t	|
dd�}d�tjj
�|dd�D]}d|vr�|��}
t|
�dkr�|
d���
�dkr�d�nqt|�|g�}|s��||<qQ|r�|r��||<qQ�r�t�fdd�|D��s��||<qQt|�dkr�||d
S|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.

    A specific repo can be requested using the ``fromrepo`` keyword argument.

    cache_valid_time

        .. versionadded:: 2016.11.0

        Skip refreshing the package database if refresh has already occurred within
        <value> seconds

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.latest_version <package name>
        salt '*' pkg.latest_version <package name> fromrepo=unstable
        salt '*' pkg.latest_version <package1> <package2> <package3> ...
    �refreshT�show_installedFr�z6The 'repo' argument is invalid, use 'fromrepo' instead�fromrepoN�cache_valid_timerr#)�versions_as_list�-ozAPT::Default-Release=�	apt-cache�-q�policy�r��stdoutr[Z	Candidater.���z(none)c3s&�|]}tjjj|d�td�VqdS)�>=�Zver1�operZver2�cmp_funcN)rsrt�versions�compare�version_cmpr7��	candidaterrr9�s���
�z!latest_version.<locals>.<genexpr>r%)rsrt�data�is_truerdr	�	list_pkgs�
refresh_dbrcr��	itertoolsr@rA�lowerrrB)�namesr�r�r�r�r��retr��pkgsr�r��outrCr�	installedrr�r�latest_version�s\�


�

��r��available_versioncOstd|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�r�)r�r�rrr�versions
r�c
Ks�tjj�t�tjj�|�}i}t�}|rbzt�	t
�j}t��}t
�d|||�|||kr1|WSWn/tyJ}zt
�d|�WYd}~nd}~wtya}zt
�d|�WYd}~nd}~wwtgd�dd�}|dd	kr�d
}	d|vr||	|d7}	t|	��|d}
|
��D]I}|��}|s�q�d
�|dd��}
d|d	vr�t�dd
|
�}
d||
<q�d|d	vr�d||
<q�d|d	vr�d||
<q�d|d	vr�d||
<|�|
�q�|r�|r�td�d�|����|S)aO
    Updates the APT database to latest packages based upon repositories

    Returns a dict, with the keys being package databases and the values being
    the result of the update attempt. Values can be one of the following:

    - ``True``: Database updated successfully
    - ``False``: Problem updating database
    - ``None``: Database already up-to-date

    cache_valid_time

        .. versionadded:: 2016.11.0

        Skip refreshing the package database if refresh has already occurred within
        <value> seconds

    failhard

        If False, return results of Err lines as ``False`` for the package database that
        encountered the error.
        If True, raise an error with a list of the package databases that encountered
        errors.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.refresh_db
    z7now: %s, last update time: %s, expire after: %s secondsz@expected integer for cache_valid_time parameter, failed with: %sNz)could not stat cache directory due to: %s)�apt-getr�rFr��retcoderr#r�r�rZr%ZGetz	 \[.+B\]$TZIgnZHitZErrzError getting repos: {}�, )rsrtrZ
clear_rtag�__opts__r�r�rkr�stat�APT_LISTS_PATH�st_mtimer�rvrw�	TypeErrorr��OSErrorr�r�
splitlinesr@r^r=�subr\r{)r��failhardr�r�Zerror_reposZ
latest_update�now�exp�callrEr�rC�cols�identrrrr�#sl ������



��r�c
1
s�d}tjj�|�rQd}d|
vr'|
dr'd}t|ddd�}|
�d�}
||
ks'd}|rQd}|D]#}t|t�rNtt	|�
���}t|ddd�}||}
||
ksMd}q-d}q-|rYtd|�ztd|||fi|
��\}}Wntyy}zt
|��d}~ww|
�dd	�}|s�|r�|}|s�iSg}t�}g}g}i}g}|d
kr�t|���}dd�|D�}|r�t|d
di|
��ni}n1g}|D],}dtvr�td|�}nd}|dur�t�d|�|�|g�q�|�|d||dg�q�|�gd��|
�dd�r�|�d�d|
v�r|
d�r|�ddg�n
|�ddg�|ddg7}d|
v�r-|
d�s(|�d�n|�d�d|
v�r<|
d�r<|�d�|�rD|�d�|�rS|d
k�rS|�d|g�|�d �|D]�}|d
k�r|\} }!|�r~|du�r~|
�d��r~t|�d!k�r~|
d}!nz|\} }"}!Wnt�y�d} |d"}"d}!Ynw|!du�r�|d
k�r�|�r�| |v�r�| || <�qZ|�| ��qZ|�|"��qZ|d
k�r|!�d#�}!| |v�r�|�| g�}#tjjj|!|#t|	d$�}$|$du�r�|�d%�| |!|#�r�d&�|#�nd���qZ|$}!| �d#|!��}%n|"}%|�| d	�}&|�r"|&�r"tjjj|!d'|&td(��r"|%|| <�qZ|&�r1tjjj|!d)|&td(��r8|�|%��qZ|�|%��qZ|�rK|�sKt� d*|�g}'g}(|�rf|(�|�t!�"|�})|)�|�|'�|)�|�r�t!�"|�})|d
k�r~d|)v�r~|)�#d+d�|)�|�|'�|)�|�r�|)�d,�|�r�|(�|�t!�"|�})|�s�|)�d-�|)�d.d�|�$�D��|'�|)�|'�s�i}*n�|
�%d/d"�}+|�r�t&|+�t'|
�d0��},|,�(t)�!��t*d1d2��d1g�}-d3d�|(D���fd4d�|-D�}.|.�r�t+|.d5�|'D]})t,|)fi|
��}/|/d6d"k�r|/d7�r|�|/d7��q�t-�%d8d�t�}0tjj�.||0�}*|D]} | |*v�s8| |v�rJ|*�(| |�| d	�|0�| d	�d9�i��q,|.�rTt/|.d5�|�r`t
d:||*d;�d<��|*S)=aI
    .. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
        On minions running systemd>=205, `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 any apt-get/dpkg commands spawned by Salt when the
        ``salt-minion`` service is restarted. (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.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

    Install the passed package, add refresh=True to update the dpkg 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.

        32-bit packages can be installed on 64-bit systems by appending the
        architecture designation (``:i386``, etc.) to the end of the package
        name.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.install <package name>

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

    cache_valid_time

        .. versionadded:: 2016.11.0

        Skip refreshing the package database if refresh has already occurred within
        <value> seconds

    fromrepo
        Specify a package repository to install from
        (e.g., ``apt-get -t unstable install somepackage``)

    skip_verify
        Skip the GPG verification check (e.g., ``--allow-unauthenticated``, or
        ``--force-bad-verify`` for install from package file).

    debconf
        Provide the path to a debconf answers file, processed before
        installation.

    version
        Install a specific version of the package, e.g. 1.2.3~0ubuntu0. Ignored
        if "pkgs" or "sources" is passed.

        .. versionchanged:: 2018.3.0
            version can now contain comparison operators (e.g. ``>1.2.3``,
            ``<=2.0``, etc.)

    reinstall : False
        Specifying reinstall=True will use ``apt-get install --reinstall``
        rather than simply ``apt-get install`` for requested packages that are
        already installed.

        If a version is specified with the requested package, then ``apt-get
        install --reinstall`` will only be used if the installed version
        matches the requested version.

        .. versionadded:: 2015.8.0

    ignore_epoch : False
        Only used when the version of a package is specified using a comparison
        operator (e.g. ``>4.1``). If set to ``True``, then the epoch will be
        ignored when comparing the currently-installed version to the desired
        version.

        .. versionadded:: 2018.3.0

    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"]'
            salt '*' pkg.install pkgs='["foo", {"bar": "1.2.3-0ubuntu0"}]'

    sources
        A list of DEB 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.

        32-bit packages can be installed on 64-bit systems by appending the
        architecture designation (``:i386``, etc.) to the end of the package
        name.

        .. versionchanged:: 2014.7.0

        CLI Example:

        .. code-block:: bash

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

    force_yes
        Passes ``--force-yes`` to the apt-get command.  Don't use this unless
        you know what you're doing.

        .. versionadded:: 0.17.4

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

        .. versionadded:: 2015.5.0

    only_upgrade
        Only upgrade the packages, if they are already installed. Default is False.

        .. versionadded:: 2015.5.0

    force_conf_new
        Always install the new version of any configuration files.

        .. versionadded:: 2015.8.0

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

        {'<package>': {'old': '<old-version>',
                       'new': '<new-version>'}}
    FTr�)r�r�zdebconf.set_file�pkg_resource.parse_targetsNr�r#Z
repositorycSs0g|]\}}|dur|�d�s|�d�r|�qS)N�<�>)r;)r*r8�yrrrr,Os
�zinstall.<locals>.<listcomp>Zbyrepo�lowpkg.bin_pkg_infoz[pkg.install: Unable to get deb information for %s. Version comparisons will be unavailable.r��r�r��-y�	force_yes�--force-yes�force_conf_newr�zDPkg::Options::=--force-confnewzDPkg::Options::=--force-confoldzDPkg::Options::=--force-confdefZinstall_recommendsz--no-install-recommendsz--install-recommendsZonly_upgradez--only-upgrade�--allow-unauthenticatedz-t�installr%r�=)r��ignore_epochz9No version matching '{}{}' could be found (available: {})r�z==r�r�zTargeting repo '%s'r��--download-onlyz--reinstallcS�g|]}|�qSrrr7rrrr,��r�r��hold)�statecSsg|]	}|�d�d�qS)r�r)r@r7rrrr,��c�g|]}|�vr|�qSrrr7�Ztargeted_namesrrr,�rz)r�r�r��
pkg.list_pkgs��old�newz)Problem encountered installing package(s)��errors�changes��info)0rsrtr�r�r�r�
isinstance�dict�next�iter�keysr�rrr�rk�items�list_repo_pkgsrv�errorr\rcrArf�lstriprZ
match_versionr�r{r^r�r�r�copy�deepcopy�insertr_rdr�r
rr �get_selections�unholdr�r��
compare_dictsr�)1r�r�r��skip_verifyZdebconfr��sourcesZ	reinstall�downloadonlyr�r�Z_refresh_dbZ_latest_version�_versionrr��
pkg_paramsZpkg_type�excr�Z
cmd_prefixr�targetsZ	downgradeZto_reinstallrZpkg_params_itemsZhas_comparisonZ
_availableZ
pkg_sourceZdeb_infoZ
pkg_item_listr��version_num�pkgpathZ
candidates�targetZpkgstrZcverZcmdsZall_pkgsr�r�r�r�Z	hold_pkgsZ	to_unholdr�rrr�rr�~s�

�����������







*��




�
�������












�

����	
�r�r~c
sNztd||�d}Wnty}zt|��d}~wwt��tdd���fdd�|D�}|dkr=|��fd	d�|D��|sAiSd
dd|g}|�|�t|�d
��}|�t�	��t
||d�}	|	ddkrp|	drp|	dg}
ng}
t�dd�t�}tdd�}t
jj��|�}
|dkr�t
jj��|�|
d�}n|
}|
r�td|
|d�d��|S)z�
    remove and purge do identical things but with different apt-get commands,
    this function performs the common logic.
    r�rNT)�removedcr�rrr7)rrrr,'rzz_uninstall.<locals>.<listcomp>�purgecr�rrr7)�old_removedrrr,)rzr�r�r�r��r�r�r�r)r"r�z'Problem encountered removing package(s)rr)r�rrr�rcr
rrr rr�r�rdrsrtr�r)�actionr�r�r�rrrr�r�r�rrZnew_removedrr�r)rr$r�
_uninstallsH��


��r'c	Cs�g}|rJg}|�ddg�|r|�d�|�d�t|dd�d}d}|��D]}|dur=|�d	�r:|�|���q'd}q'd
|vrCd}q'|��|St�}|�ddg�|r[|�d�|�d�t|dd�t�	dd
�t�}t
jj�
||�S)a%
    .. versionadded:: 2015.5.0

    Remove packages not required by another package using ``apt-get
    autoremove``.

    list_only : False
        Only retrieve the list of packages to be auto-removed, do not actually
        perform the auto-removal.

    purge : False
        Also remove package config data when autoremoving packages.

        .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.autoremove
        salt '*' pkg.autoremove list_only=True
        salt '*' pkg.autoremove purge=True
    r�z--assume-noz--purge�
autoremoveT)�ignore_retcoder�FrZz'The following packages will be REMOVED:z--assume-yesrN)rcr\r�r�r;r@�sortr�r�rdrsrtr�r)	Z	list_onlyr#r�r�r��foundrCrrrrrr(Ls8


�

r(cK�tdd||d�|��S)a�
    .. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
        On minions running systemd>=205, `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 any apt-get/dpkg commands spawned by Salt when the
        ``salt-minion`` service is restarted. (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.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

    Remove packages using ``apt-get remove``.

    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.

    .. versionadded:: 0.16.0


    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"]'
    r~�r&r�r�Nr�r'�r�r�r�rrrr~��)cKr,)a�
    .. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
        On minions running systemd>=205, `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 any apt-get/dpkg commands spawned by Salt when the
        ``salt-minion`` service is restarted. (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.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

    Remove packages via ``apt-get purge`` along with all configuration files.

    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.

    .. versionadded:: 0.16.0


    Returns a dict containing the changes.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.purge <package name>
        salt '*' pkg.purge <package1>,<package2>,<package3>
        salt '*' pkg.purge pkgs='["foo", "bar"]'
    r#r-Nrr.r/rrrr#�r0r#cKs>|�dd�}tjj�|�rt|�t�}d|vr |dr dg}nddg}gd�}|D]}|�d�|�d	|���q*|�d
d�rE|�d�|�d
d�rP|�d�|�dd�s\|�dd�ra|�d�|�dd�rl|�d�|�|rrdnd�t	|t
��d�}t�dd�t�}	tjj�
||	�}
|ddkr�td|
|d�d��|
S)af
    .. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
        On minions running systemd>=205, `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 any apt-get/dpkg commands spawned by Salt when the
        ``salt-minion`` service is restarted. (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.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

    Upgrades all packages via ``apt-get upgrade`` or ``apt-get dist-upgrade``
    if  ``dist_upgrade`` is ``True``.

    Returns a dictionary containing the changes:

    .. code-block:: python

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

    dist_upgrade
        Whether to perform the upgrade using dist-upgrade vs upgrade.  Default
        is to use upgrade.

        .. versionadded:: 2014.7.0

    refresh : True
        If ``True``, the apt cache will be refreshed first. By default,
        this is ``True`` and a refresh is performed.

    cache_valid_time

        .. versionadded:: 2016.11.0

        Skip refreshing the package database if refresh has already occurred within
        <value> seconds

    download_only (or downloadonly)
        Only download the packages, don't unpack or install them. Use
        downloadonly to be in line with yum and zypper module.

        .. versionadded:: 2018.3.0

    force_conf_new
        Always install the new version of any configuration files.

        .. versionadded:: 2015.8.0

    allow_downgrades
        Allow apt to downgrade packages without a prompt.

        .. versionadded:: 3005

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    r�rr�z--force-confnewz--force-confoldz--force-confdefr�r�zDPkg::Options::=r�Fr�rr�Z
download_onlyrr�Zallow_downgradesz--allow-downgrades�dist-upgrade�upgrader%rNr�z&Problem encountered upgrading packages�r�resultr)rdrsrtr�r�r�r�r\rr�r rr�rr)r��dist_upgrader�r�rZdpkg_optionsr��optionr4rr�rrrr2�s<A




�r2c
Ksn|s
|s
|s
td��|r|rtd��g}|r|�|�n|r-|D]}|�tt|���q n|�|�i}|D]~}t|t�rCtt|��}|iddd�||<t|dd�}|s_d|�d	�||d
<q6tj	j
�|�dd��s�dt
vr�t
dr�||jdd
�d|�d�||d
<q6td|gid�}	||j|	|dd�d|�d�||d
<q6||jdd
�d�|�||d
<q6|S)a�
    .. versionadded:: 2014.7.0

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

    name
        The name of the package, e.g., 'tmux'

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.hold <package name>

    pkgs
        A list of packages to hold. Must be passed as a python list.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.hold pkgs='["foo", "bar"]'
    �0One of name, pkgs, or sources must be specified.�-Only one of pkgs or sources can be specified.Fr#�r�rr4rEr�)�patternr��Package z not currently held.rE�testN�r4z is set to be held.��	selectionTr3z is now being held.z%Package {} is already set to be held.)r	rcr\rrr	r
rrsrtr�r�rr�r�set_selectionsr{�
r�r�rr�rrxr�r!r�r4rrrr�Fs@�

�r�c
Ksh|s
|s
|s
td��|r|rtd��g}|r|�|�n|r-|D]}|�tt|���q n|�|�i}|D]{}t|t�rCtt|��}|iddd�||<t|d�}|s^d|�d�||d	<q6tj	j
�|�d
d��r�dt
vr�t
dr�||jdd
�d�|�||d	<q6td|gid�}	||j|	|dd�d�|�||d	<q6||jdd
�d�|�||d	<q6|S)a�
    .. versionadded:: 2014.7.0

    Set package current in 'hold' state to install state,
    meaning it will be upgraded.

    name
        The name of the package, e.g., 'tmux'

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.unhold <package name>

    pkgs
        A list of packages to unhold. Must be passed as a python list.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.unhold pkgs='["foo", "bar"]'
    r7r8Fr#r9)r:r;z does not have a state.rEr�r<Nr=z!Package {} is set not to be held.r�r>Tr3z#Package {} is no longer being held.z)Package {} is already set not to be held.)r	rcr\rrr	r
rrsrtr�r�rr�rr{r@rArrrr�sH�


���rcCsT|rt�tdd�}nt�tdd�}|s |�tdd�|s(td|�|S)z'
    Use pkg list from __context__
    rr"�
purge_desiredr��pkg_resource.stringify)rrr�rr�)r�r"rBr�rrr�_list_pkgs_from_context�srDc
s�tjj�|�}tjj�|�}tjj�|�}dtvr%|�dd�r%t|||�Siiid�}gd�}td|ddd	�}|��D]}}|�	��z�fd
d�dD�\}}	}
}}Wnt
tfy]Yq<wt�d
d�dkrt�dd�}
|dkr|
dkr|
|kr|
d|��7}
�r�d|vs�d|vr�d|	vr�td|d|
|�q<d|vr�td|d|
|�q<d|vr�|	dkr�td|d|
|�q<dD]
}td||�q�t
�|�td<|r�|d}nt
�tdd�}|s�|�tdd�|s�td|�|S)a�
    List the packages currently installed in a dict::

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

    removed
        If ``True``, then only packages which have been removed (but not
        purged) will be returned.

    purge_desired
        If ``True``, then only packages which have been marked to be purged,
        but can't be purged due to their status as dependencies for other
        installed packages, will be returned. Note that these packages will
        appear in installed

        .. versionchanged:: 2014.1.1

            Packages in this state now correctly show up in the output of this
            function.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_pkgs
        salt '*' pkg.list_pkgs versions_as_list=True
    rZuse_contextT)r�r"rB)z
dpkg-queryz--showformatz0${Status} ${Package} ${Version} ${Architecture}
z-W�cmd.run_stdoutr�F�r�r�c3s�|]}�|VqdSrSrr7�r�rrr9s�
�zlist_pkgs.<locals>.<genexpr>)rr.r/��Zcpuarchr#�x86_64r�r��amd64r
r�r�r�zpkg_resource.add_pkg�	deinstallr"r#rBzpkg_resource.sort_pkglistrC)rsrtr�r�r�rrDr�r�r@rf�
IndexErrorrrrr)r�r"rBr�r�r�r�rCZlinetype�statusr�rrUr�Zpkglist_typerrGrr��sT
��
��
r�cs�ddg}|r|�d�n|�d�z|�dd�|d�g�Wn	ty(Ynwt|�}|dd	krOd
}dD]}||rJ|d||7}t|��q7t|��|d
}t�d�}ddg��fdd�}|�|�}	i}
|	D]}||d�}||d�}
|
|
|<qk|
S)zq
    Utility function to get upgradable packages

    Sample return data:
    { 'pkgname': '1.2.3-45', ... }
    r�z--just-printr1r2r�zAPT::Default-Release={}r�r�rzFailed to get upgrades)r�r��: r�z(?m)^Conf ([^ ]+) \(([^ ]+)r�r�cs|��|�SrS)re)rC�k�r
rr�_getSsz_get_upgradable.<locals>._get)	r\rcr{�KeyErrorr�rr=�compile�findall)r5r�r�r��msg�keyr�ZrexprRZupgradesr�rCr�rrrQr�_get_upgradable1s<
��




rXcKs2|�dd�}tjj�|�rt|�t|fi|��S)a
    List all available package upgrades.

    refresh
        Whether to refresh the package database before listing upgrades.
        Default: True.

    cache_valid_time

        .. versionadded:: 2016.11.0

        Skip refreshing the package database if refresh has already occurred within
        <value> seconds

    dist_upgrade
        Whether to list the upgrades using dist-upgrade vs upgrade.  Default is
        to use dist-upgrade.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_upgrades
    r�r)rdrsrtr�r�r�rX)r�r5r�r�rrr�
list_upgradesasrYcKst|�dkS)z�
    Check whether or not an upgrade is available for a given package

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade_available <package name>
    r#)r�)r�r�rrr�upgrade_available�s
rZc

s�fdd�}||�}||�}trKz1t��zt�||�}Wnty0t�t|�t|��}Ynw|dkr8dWS|dkr?dWSdWStyJYnwz$dD]\}}dd|||g}td	|d
ddd
�}|dkrl|WSqNWdSty�}	zt�	|	�WYd}	~	dSd}	~	ww)a�
    Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
    pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
    making the comparison.

    ignore_epoch : False
        Set to ``True`` to ignore the epoch when comparing versions

        .. versionadded:: 2015.8.10,2016.3.2

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.version_cmp '0.2.4-0ubuntu1' '0.2.4.1-0ubuntu1'
    cs �rt|��dd�dSt|�S)Nr
r%r�)rMr@�r8�r�rr�	normalize�s zversion_cmp.<locals>.normalizerr%r�))�ltr�)�eqr)�gtr%�dpkgz--compare-versionszcmd.retcoder�FT)r�r�r)N)
�
HAS_APTPKG�apt_pkgZinit_systemZversion_comparer�rM�	Exceptionr�rvr)
Zpkg1Zpkg2r�r�r]r�r�r�r�rrr\rr��s>�"��
��	���r�cCs�t�d|�}t�}|s
|S|�d��d�}g}|��D]`}|�d�rA|�|�dd�d�d��i|d<||dd<||dd	<q|�d
�r]i|d<||dd<|�dd�d|dd	<q|�dd�d}i||<|||d<|�dd�d||d	<q|S)z/
    Return all opts in [] for a repo line
    z\[(.*=.*)\]rrarUr�r%rVrWrXz	signed-byr)r=�searchrr?r(r@r;rc)rCZget_optsr�r!rr`Z	other_optrrrr]�s*

r]cCstt|�}|j}ts
|j}nt|d�}d|vr|d�dd�}nd}|r+t|�\}}}}||j|j|j	|j
|j|d�S)z1
    Return APT source entry as a dictionary
    �rCrrXr#)rDrLrrrrr)rrD�HAS_APTrr]rrHrLrrrr)r��entryrDrr!�_rrr�_split_repo_str�s$
�rjc
	Cst|t�stdt|��dt�d���i}t�}td�j}dd�|jD�}|D]@}tt	|dg�|j
|j|j|jf�}||vrT||}t|j
��t|j
��}t|�||_
nt|j�||<|j|krf|�|j�q&t|���|_|��|D]}	zt�|	�Wqtty�Yqtw|S)z"
    Consolidate APT sources.
    �'z	' not a 'r#cS�g|]}|js|�qSr�rD�r*�srrrr,
�z-_consolidate_repo_sources.<locals>.<listcomp>r)r	rr�rL�setrrrkrM�getattrrrrr�unionrCr}r_r�rr~r�)
rZconsolidatedZdelete_filesZ	base_file�reposr�rWZcombinedZcombined_compsZfile_rrr�_consolidate_repo_sourcess@


��	
��ruc
	Os�|rddgdd�|D�}nddg}t|ddd�}i}d	}t�d
�}tjj�|dd�D];}|��s3q,z
|�|��	d
�}Wn	t
yFYnw||krN|}q,|���d	d
�}	|	ddkrg|�|g��|	d
�q,|S)aH
    .. versionadded:: 2017.7.0

    Returns all available packages. Optionally, package names (and name globs)
    can be passed and the results will be filtered to packages matching those
    names.

    This function can be helpful in discovering the version or repo to specify
    in a :mod:`pkg.installed <salt.states.pkg.installed>` state.

    The return data will be a dictionary mapping package names to a list of
    version numbers, ordered from newest to oldest. For example:

    .. code-block:: python

        {
            'bash': ['4.3-14ubuntu1.1',
                     '4.3-14ubuntu1'],
            'nginx': ['1.10.0-0ubuntu0.16.04.4',
                      '1.9.15-0ubuntu1']
        }

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.list_repo_pkgs
        salt '*' pkg.list_repo_pkgs foo bar baz
    r��showcSr�rr)r*�argrrrr,Mr�z"list_repo_pkgs.<locals>.<listcomp>�dumpFT)r�r)Nz^Package: (.+)r�r[r%rzVersion:)
r�r=rTrsrtr�r@r(r>r?�AttributeError�
setdefaultr\)
r�r�r�r�r��pkg_nameZnew_pkgrCZcur_pkgrrrrr-s.
��rcCsz|jr;|jr9|jr9|jdvr9|�|j�}|d��ddkr7|�d��d���}t|�dkr7t	�
d|j�dSdSdSdS)	zH
    Decide to skip source or not.

    :param source:
    :return:
    r0r%rr3raz5Source %s will be included although is marked invalidFT)rDrrLZmysplitrCr(rdr@rArvrw)rx�pieces�optionsrrr�_skip_sourceis$��
�r~cKs�i}t�}|jD]b}t|�rqts|j}nt|jd�}d|vr(|d�dd�}nd}i}|j|d<t	|dg�|d<|j
|d<|j|d<|j|d	<|j
|d
<|j��|d<t	|dg�|d<||d<|�|j
g��|�q|S)
z�
    Lists all repos in the sources.list (and sources.lists.d) files

    CLI Example:

    .. code-block:: bash

       salt '*' pkg.list_repos
       salt '*' pkg.list_repos disabled=True
    rfrrXr#rrrrrLrrCr)rrkr~rgrr]rCrrrrrrrLrr(rzr\)r�rtrrxrr!r�rrr�
list_repos�s.





rc
Ks�|�dd�}|�d�rmtddvrmtd}|dd��d�\}}|r0|�d	�}t�||||�}n=trfzttj	d
�rEtj	�
|��|�d}n	tj	�||�d}Wnt
ye}z
td|�d
|����d}~wwt�|||�}t�}|r�z)t|�}	|r�t�d|	d�}
|
r�|
�d��|�s�d�|
�d�||
�d��|	d<Wnty�td|�d���w|��D]F}|D]A}|d|	dkr�|d�d�|	d�d�kr�|d|	dkr�|	ds�|S|	dD]}
|
|�dg�vr�|Sq�q�q�iS)z�
    Display a repo from the sources.list / sources.list.d

    The repo passed in needs to be a complete repo entry.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.get_repo "myrepo definition"
    �ppa_authNr�r�ZUbuntuZMintZneon�
oscodenamerHr��@�PPAShortcutHandlerrzCould not find ppa rOz(http[s]?://)(.+)rr.z{}{}@{}r%�
Error: repo 'z$' is not a well formatted definitionrLrr)rr;rr@�LP_PVT_SRC_FORMATr{�HAS_SOFTWAREPROPERTIES�hasattr�softwareproperties�ppar��expand�expand_ppa_line�	NameErrorr�
LP_SRC_FORMATrrjr=rer?�SyntaxErrorr_�rstrip)r�r�r�rr�r��	auth_infoZ
name_errorrt�
repo_entryZ	uri_matchrxr��comprrr�get_repo�sn
��������
�����r�c	Ks8d}|�d�r[tddvr[d}td}ts@t|�|dd��d	�\}}d
|vr8d�|d
�}t�||||�}n#t�|||�}ntt	j
d�rRt	j
�|��|�d
}n	t	j
�
||�d
}t�}dd�|jD�}|�r�t�}	zt|�}
Wnty�td|�d���w|D]�}|j|
dkr�|j|
dkr�|j�d	�|
d�d	�kr�|j|
dkr�t|j�}t|
d�}
|�|
�s�|s�|
s�d
|	|j<t|�|
��|_|js�z|�|�Wn	ty�Ynw|�r7|
ddk�r7|jdk�r7|j|
dk�r7|j|
dk�r7t|j�}t|
d�}
|�|
��s|�s7|
�s7d
|	|j<t|�|
��|_|j�s7z|�|�Wn
t�y6Ynw|� �q�|	�r�d}|D]}|j|	v�rT|	|jd7<�qC|	�!�D]4\}}d}|d
k�r�d|v�r�t"j#�$|��r�d}zt"�|�Wn
t%�y�Ynw||�||�7}�qZt&�|St'd|�d���) a�
    Delete a repo from the sources.list / sources.list.d

    If the .list file is in the sources.list.d directory
    and the file that the repo exists in does not contain any other
    repo configuration, the file itself will be deleted.

    The repo passed in must be a fully formed repository definition
    string.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo "myrepo definition"
    Fr�rr�Tr�rHNr�r��{}@r�rcSrlrrmrnrrrr,rpzdel_repo.<locals>.<listcomp>r��!' not a well formatted definitionrLrrrrr1r2r#r%z&Repo '{0}' has been removed from {1}.
zsources.list.d/z0File {1} containing repo '{0}' has been removed.zRepo z% doesn't exist in the sources.list(s))(r;rr�r�r@r{r�r�r�r�r�r�r�r�rrkr
rjr�r	rLrrr�rrqr�intersectionr�
differencer~rfr�rr�path�isfiler�r�r)r�r�Zis_pparr�r�r�rrtZdeleted_fromr�rxZs_compsZr_compsr�Z	repo_filer�rVrrr�del_repo�s�
��

��

�
��r�cCs(z	tt|��}W|StyY|Sw)z�
    .. versionadded:: 2017.7.0

    Convert to an int if necessary.

    :param str value: The value to check/convert.

    :return: The converted or passed value.
    :rtype: bool|int|str
    )�intrMrf)rXrrr�_convert_if_intas��r�cCsZt�}t�}dd�|��D�}|D]�}dd�|�d�D�}t�}t|�dkr-t�d|�q|ddvrc|�|d	|d|d
|d|dt|d
�|dd��|ddkr\|�	|�q||dd<q|ddkr�|d�
dd�r|dd�d|di�q|d�d|di�q|ddkr�|d�|d|dd��q|D]}|||d<q�|S)rZcSryrr'rbrrrr,xrzz+_parse_repo_keys_output.<locals>.<listcomp>cSs$g|]}|��rt|���nd�qSrS)r(r�)r*�itemrrrr,}s��r
r.zSkipping line: %sr)�pubr�r/�rI�rHr%)�	algorithm�bitsZ
capabilityZ
date_creationZdate_expiration�keyidZvalidityr�r�ZsubkeyZfprFZfingerprint�	�uid�)r�Zuid_hashr�)r
rkr�r@rArvrwrrMr\r)r�r�Z	repo_keys�linesrCrZ	key_propsZrepo_keyrrr�_parse_repo_keys_outputssF�
���r�cCs�tjj�d�s	d}|sW|st�ddd�}t|tj�st�|�}|��s+t�	d|�dSg}t
�t|��D]}||}t
ddd	d
|ddg�}|�|d
�q4td�|��}|Sgd�}t|dd�}|ddkrpt�	|d�|St|d
�}|S)a�
    .. versionadded:: 2017.7.0

    List known repo key details.
    :param bool aptkey: Use the binary apt-key.
    :param str keydir: The directory path to save keys. The default directory
    is /etc/apt/keyrings/ which is the recommended path
    for adding third party keys. This argument is only used
    when aptkey is False.

    :return: A dictionary containing the repo keys.
    :rtype: dict

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.get_repo_keys
    �apt-keyF�/etcrJ�keyrings�SThe directory %s does not exist. Please create this directory only writable by rootr��gpg�--no-default-keyring�	--keyring�--list-keys�
--with-colonsr�rZ)r��adv�--batchz--list-public-keys�--with-fingerprintr�r�z--fixed-list-moder�r�rr�)rsrtr��whichrNrOr	rmrvrr�listdirrMr�r\r�r^r�)�aptkey�keydirZ
ret_outputr�key_filer�r�r�rrr�
get_repo_keys�sF
���
�r�cCs�zftjj�|d��S}|���d��d�rStjj�d�s+t	�
d|�	Wd�WdSt|�d}dd	d
|d|g}td|�d
dksIt	�
d|�|Wd�WSWd�W|S1s_wYW|St
yut	�d�Y|Sw)zn
    Check if the key needs to be decrypted. If it needs
    to be decrypt it, do so with the gpg binary.
    �r�-z	BEGIN PGPr�z]Detected an ASCII armored key %s and the gpg binary is not available. Not decrypting the key.NF�
.decryptedz--yesz--outputz	--dearmorr�r�rzFailed to decrypt the key %sz0Key is not ASCII Armored. Do not need to decrypt)rsrtrlru�readr(r;r�r�rvrrMr��UnicodeDecodeErrorrw)rWrpZ
decrypted_keyr�rrr�_decrypt_key�s2�������r��basecCs |s	t�ddd�}t|tj�st�|�}|s"|��s"t�d|�dStjj�	d�s+d}dg}i}	|rPt
||d�D]}
|
t|�d�|krOt�d	||
�d
Sq8|r�t
d||�}|sct�d|�dS|s�t|�}|smdSt�t|��}|s�|j}|�d
�r�|dd�}t�t|�t||��d
S|�d|g�n[|r�t�d|�|�ddg�|	�d|i�nD|r�|s�d�|�}
t|
��|s�|s�t�d�dSddd||d|d|g}n|�ddd|d|g�n|r�d|��}
t|
��ttj�d���t|fi|	��}|dd k�rd
St�d!|d"�dS)#a�
    .. versionadded:: 2017.7.0

    Add a repo key using ``apt-key add``.

    :param str path: The path of the key file to import.
    :param str text: The key data to import, in string form.
    :param str keyserver: The server to download the repo key specified by the keyid.
    :param str keyid: The key id of the repo key to add.
    :param str saltenv: The environment the key file resides in.
    :param bool aptkey: Use the binary apt-key.
    :param str keydir: The directory path to save keys. The default directory
                       is /etc/apt/keyrings/ which is the recommended path
                       for adding third party keys. This argument is only used
                       when aptkey is False.

    :param str keyfile: The name of the key to add. This is only required when
                        aptkey is False and you are using a keyserver. This
                        argument is only used when aptkey is False.

    :return: A boolean representing whether the repo key was added.
    :rtype: bool

    .. warning::
       The apt-key binary is deprecated and will last be available
       in Debian 11 and Ubuntu 22.04. It is recommended to use aptkey=False
       when using this module.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.add_repo_key 'salt://apt/sources/test.key'

        salt '*' pkg.add_repo_key text="'$KEY1'"

        salt '*' pkg.add_repo_key keyserver='keyserver.example' keyid='0000AAAA'
    r�rJr�r�Fr��r�r�Nz"The keyid '%s' already present: %sT�
cp.cache_filez%Unable to get cached copy of file: %sr�i����r}zReceived value: %sr��stdinz-No keyid or keyid too short for keyserver: {}zNYou must define the name of the key file to save the key. See keyfile argumentr�r�r��--keyserver�--recv-keysr�r�z--recvz"No keyserver specified for keyid: z&() takes at least 1 argument (0 given)r�rzUnable to add repo key: %sr�)rNrOr	rmrvrrsrtr�r�r�rArwr�r�rMr�r6r��copyfilercrr{r	r��add_repo_keyrgr�)r��text�	keyserverr��saltenvr�r��keyfiler�r�Z
current_keyidZcached_source_pathrWZ	error_msgr�rrrr�	s�0
��
���

�r�cCs�t|�dvr
t�d�dSt�t|��D],}||}tdddd|dd	g�}t|d
�}|D]}||d�|�r?|Sq.qt�d|�dS)
z6
    Find and return the key file from the keyid.
    )��z/The keyid needs to be either 8 or 16 charactersFr�r�r�r�r�r�r�r�z)Could not find the key file for keyid: %s)	rArvrrr�rMr�r�r6)r�r�rr�Z
key_outputr�rWrrr�_get_key_from_id�	s,
��
��r�cKs>|s	t�ddd�}t|tj�st�|�}|s"|��s"t�d|�dStjj�	d�s+d}|�
dd�rXt|t�rT|�d�rT|d	d
��
d�\}}t||�}|dd
d
�}ntd��d|vrb|�
d�}ntd��|s{t||d�}|srdSt�|���|Stdd|gdd�}	|	ddkr�d}
|	dr�|
d�|	d�7}
t|
��|S)a
    .. versionadded:: 2015.8.0

    Remove a repo key using ``apt-key del``

    name
        Repo from which to remove the key. Unnecessary if ``keyid`` is passed.

    keyid
        The KeyID of the GPG key to remove

    keyid_ppa : False
        If set to ``True``, the repo's GPG key ID will be looked up from
        ppa.launchpad.net and removed.

        .. note::

            Setting this option to ``True`` requires that the ``name`` param
            also be passed.

    aptkey
        Use the binary apt-key.

    keydir
        The directory path to save keys. The default directory
        is /etc/apt/keyrings/ which is the recommended path
        for adding third party keys.

    .. warning::
       The apt-key binary is deprecated and will last be available
       in Debian 11 and Ubuntu 22.04. It is recommended to use aptkey=False
       when using this module.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo_key keyid=0123ABCD
        salt '*' pkg.del_repo_key name='ppa:foo/bar' keyid_ppa=True
    r�rJr�r�Fr�Z	keyid_ppar�rHNr��signing_key_fingerprinti����z'keyid_ppa requires that a PPA be passedr�z.keyid or keyid_ppa and PPA name must be passed)r�r��delr�r�rzFailed to remove keyid {0}r�z: {})rNrOr	rmrvrrsrtr�r�rrMr;r@r�r	r��unlinkr�r{r)r�r�r�r�r�r�Zppa_infor�r�r4rVrrr�del_repo_key�	sD)
�
�r�c0Ksn	d|vr	|d}n|�dd�}tjj�d�sd}|�d��rQtddv�rJtjj�d	�r�d
|vr�t|�}|r:||iSd}t�}|rF||d�}t	td
�dkrSd	|g}nd	d|g}t
|f|dd�|��}	|	drytd�|dd�||	d|	d���|r~t
�||	iSts�t|�nt�d�z|dd��dd�\}
}Wnty�td�|dd����wtd}||d<d}
d|vr�d}|�|
||�|d<z t|
|�}d
|vr�|d|d<nd|vr�d }t|�|
|���Wn*ty�}z	td!�|
||���d}~wt�y}z	td"�|
||���d}~wwd#|v�rd$|d#<d
|v�r-|d%�s-td&�|���d
|v�rBd'�|d
�}
t�|
|
||�}nt�|
||�}ntd(|����t�}|�d)d��r_t|�}g}|D]}t�r{t|j�\}}}}|�sy|�|��qc|�|��qcd}zt|�}|�d*��r�t d+|�d,���Wnt!�y�t!d-|�d.���wd/d0�|d1D�}t"d2d3�}|d4�r�t#�$|d4�nd|d4<|�s�|d4�s�t d5��d|v�r�|�%dd�}|�%d#d�}|�r�|�s�d6}t&|��t'|t(��s�|g}|D]�}t'|t)��rt*|�}|�sd}t+||d4j,d7�}|�|��rd}ndd8|g}t"d9|fd:di|��}|�d;�}|�r�|�s�t�}|�rX||v�rXdd<d=d>d?|��d@|dAdBdC|g}�q�|�ss|d4} t-||d| j,| dD��sqtdE|�����q�dd<d=d@|dAdBdC|g	}t
|fdFdi|��}!|!ddGk�r�tdH�|!dI����q�n�dJ|v�r"|dJ}"t#�$t"dK|"|��}#|#�s�tdL|"����|d4�r�|#j.|d4j.k�r�|#j,|d4j.}$|#�/|$�|$}#|�s�i}%|�d4��r�|�d4�j,|%dM<t-dbt0|#�ddN�|%���s�tdEt0|#�����nLddOt0|#�g}t"d9|fd:di|��}	|	�1��dP��s!tdQ|"����n)dR|v�rK|dR}&gdS�}t"d9|f|&ddT�|��}	|	�1��dP��sKtdU|&����d1|v�rgdVdW�|d1�dX�D�|d1<|t2|d1�O}nt(|�|d1<dY|v�r||dY�dX�|dY<n|dY|dY<dZ|v�r�tjj3�4|dZ�|dZ<nd[|v�r�tjj3�4|d[�|dZ<|�d\�}'|�d�}(|D]W})|)j5|d\k�o�|)j6�7d�|d]�7d�k�o�|)j8|dk}*|)j8|(k�o�|)j5|'k}+|*�s�|+�r|D]},|,t9|)d1g�v�r�|)}�q�|)j:�s�|)}|dY|)j;k�r|)}|�rn�q�d^|v�rtjj<j=�>|d^�|d^<t?|�}-|�s5t?|�}d^|v�r.|d^|_@|j(�|�n
d^|v�r?|d^|_@|-j|_|j�Ad_��sP|jd_|_|D]}|tBv�rgtC||��rgtD||||��qR|j6|d]k�r{|d]|_6|�0�|_|�E�|�r�t
�t�s�|jF}.ntG|�}/d4|/v�r�|/d4�d`d�}.nd}.|t9|dYg�|j:|jH|jI|j5|j6|j|.da�iS)caw
    Modify one or more values for a repo.  If the repo does not exist, it will
    be created, so long as the definition is well formed.  For Ubuntu the
    ``ppa:<project>/repo`` format is acceptable. ``ppa:`` format can only be
    used to create a new repository.

    The following options are available to modify a repo definition:

    architectures
        A comma-separated list of supported architectures, e.g. ``amd64`` If
        this option is not set, all architectures (configured in the system)
        will be used.

    comps
        A comma separated list of components for the repo, e.g. ``main``

    file
        A file name to be used

    keyserver
        Keyserver to get gpg key from

    keyid
        Key ID or a list of key IDs to load with the ``keyserver`` argument

    key_url
        URL to a GPG key to add to the APT GPG keyring

    key_text
        GPG key in string form to add to the APT GPG keyring

        .. versionadded:: 2018.3.0

    consolidate : False
        If ``True``, will attempt to de-duplicate and consolidate sources

    comments
        Sometimes you want to supply additional information, but not as
        enabled configuration. All comments provided here will be joined
        into a single string and appended to the repo configuration with a
        comment marker (#) before it.

        .. versionadded:: 2015.8.9

    refresh : True
        Enable or disable (True or False) refreshing of the apt package
        database. The previous ``refresh_db`` argument was deprecated in
        favor of ``refresh```. The ``refresh_db`` argument will still
        continue to work to ensure backwards compatibility, but please
        change to using the preferred ``refresh``.

    .. note::
        Due to the way keys are stored for APT, there is a known issue where
        the key won't be updated unless another change is made at the same
        time. Keys should be properly added on initial configuration.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.mod_repo 'myrepo definition' uri=http://new/uri
        salt '*' pkg.mod_repo 'myrepo definition' comps=main,universe
    r�r�Tr�Fr�rr�zapt-add-repositoryr�N)Z
http_proxyZhttps_proxyZ	osreleaseg�G�z(@r�)r�r�r�z;Unable to add PPA '{}'. '{}' exited with status {!s}: '{}' rHr�z-Falling back to urllib method for private PPAr�r%z�Unable to get PPA info from argument. Expected format "<PPA_OWNER>/<PPA_NAME>" (e.g. saltstack/salt) not found.  Received '{}' instead.r�rr#r�(/etc/apt/sources.list.d/{0}-{1}-{2}.listr�r�z5Private PPAs require a keyid to be specified: {0}/{1}z'Launchpad does not know about {}/{}: {}z[Launchpad knows about {}/{} but did not return a fingerprint. Please set keyid manually: {}r�zkeyserver.ubuntu.comZprivatez2PPA is not private but auth credentials passed: {}r�z,cannot parse "ppa:" style repo definitions: ZconsolidaterDzName zO is not valid. This must be the complete repo entry as seen in the sources filer�r�cSsh|]}|���qSrr'�r*r�rrr�	<setcomp>�
r-zmod_repo.<locals>.<setcomp>r�
config.option�no_proxyrz1missing 'signedby' option when apt-key is missingz*both keyserver and keyid options required.r�ZexportrEr�z-----BEGIN PGPr�r�z--keyserver-optionszhttp-proxy=r�z--logger-fdrr�)r�r�r�r�r�zError: Could not add key: r�rzError: key retrieval failed: {}r��key_urlr�zError: file not found: r�)r�r�r}�OKzError: failed to add key from �key_text)r�r}r�)r�r�zError: failed to add key:
cSr&rr'r�rrrr,Pr-zmod_repo.<locals>.<listcomp>rVrr�enabledrLrZcommentsr[rX)rrrrrLrrCrr)Jrrsrtr�r�r;rr��_get_http_proxy_url�floatr�rr{r�r�r�rvrr@rfr�rrMr�r�rrurgrHrCr\rjr	r�r�rNrOrdr�r	rkr��hexr��parentr�r��renamerM�upperrqr�r�rLrr�rrrrrrr1Zcombine_commentsrrEr6�
_MODIFY_OKr��setattrr�rr]rr)0r�r�r�r�r�Z	repo_infor��http_proxy_urlr�r�r�r�rr��filenameZlaunchpad_ppa_infoZ	error_strrrrtrxrirDZ
mod_sourcer�Zfull_comp_listr�r�r�rWZimported�outputr�r�r�Zfn_�new_pathZfunc_kwargsr�Zkw_typeZkw_distZ
apt_sourceZrepo_matchesZ
kw_matchesr�Zrepo_source_entryrr!rrr�mod_repo
sP@
�

��

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


��
��
�
����
��

����
�����
A
��
���





����




�



��r�cO�td|�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
    zlowpkg.file_listr��Zpackagesr�rrr�	file_list��r�cOr�)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_dict httpd
        salt '*' pkg.file_dict httpd postfix
        salt '*' pkg.file_dict
    zlowpkg.file_dictr�r�rrr�	file_dict�r�r�c
Ks�d|vrtd��i}|d}|�d�rm|dvrm|}|dd��dd�\}}d	|vr9d
�|d	�}t�||||�}n%trWttjd�rMtj�	|��
|�d}ntj�||�d}nt�|||�}d
|vrmd}	|	�|||�|d
<t
|�}
dD]}||vr�dd�||�d�D�||<qstD]}||vr�t|
|||�q�t�}
i}ts�|
j}||d<nt|�}d|vr�|d�dd�}nd}|
jd%|
j|
j|
jt|
dg�t|
dg�d�|��}t|d�r�|�|
j�n	|
j|_|��|_|j|d
<t|dg�|d<|j|d<|j|d<|j|d<|j|d<|j��|d<t|dg�|d<||d<t�r||�r|||dv�r||d��}t|�}dd�|� �D�}|D]}d ||v�rW||d }||d!||<�q@d"d#�!|�d$}|d�d"��ro||d<n|�"d|�d#�!|�|d<|S)&aV
    Take a repository definition and expand it to the full pkg repository dict
    that can be used for comparison.  This is a helper function to make
    the Debian/Ubuntu apt sources sane for comparison in the pkgrepo states.

    This is designed to be called from pkgrepo states and will have little use
    being called on the CLI.
    r�zmissing 'repo' argumentr�r�rHNr�r%r�r�r�rrr�)rrcSr&rr')r*�kwargrrrr,�s�z$_expand_repo_def.<locals>.<listcomp>rVrrXr#rr)rLrrr|r�set_enabledrrrLrrCcSs g|]\}}|ddkr|�qS)rWr#r)r*Zopt_typeZopt_defrrrr,%s
�rerWr3rZr5r)#r	r;r@r{r�r�r�r�r�r�r�r�r�rr�r�rrgrr]rr}rLrrrrr�rrGrCrr(rr^r)�os_nameZos_codenamer�Z	sanitizedr�rr�r�r�r�Zsource_entryZ	list_argsr�Zsource_listrr!Z
_source_entryrCZ	repo_optsZ
opts_orderr`rFrrr�_expand_repo_def�s�	�
���


��






��
r�cCsXi}t|t�r|�d�}|D]}|r)|��\}}||vr$||�|�q|g||<q|S)z�
    Parses the format from ``dpkg --get-selections`` and return a format that
    pkg.get_selections and pkg.set_selections work with.
    r[)r	rMr@r\)Z
dpkgselectionr�rC�_pkg�_staterrr�_parse_selections9s


�r�cCsPi}ddg}|�|r|nd�td|ddd�}t|�}|r&||�|g�iS|S)a
    View package state from the dpkg database.

    Returns a dict of dicts containing the state, and package names:

    .. code-block:: python

        {'<host>':
            {'<state>': ['pkg1',
                         ...
                        ]
            },
            ...
        }

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.get_selections
        salt '*' pkg.get_selections 'python-*'
        salt '*' pkg.get_selections state=hold
        salt '*' pkg.get_selections 'openssh*' state=hold
    raz--get-selections�*rEr�FrF)r\r�r�r)r:r�r�r�r�rrrrKs�rc
si}|s|s|S|r|rd}t|��t|t�r>z	tjj�|�}Wntjjjjtjjj	j
fy=}ztd|����d}~ww|rltd||�}tjj�
|d��}dd�|��D�}Wd�n1scwYt|�}|�r	d��fd	d�|D�}	|	r�td
�d�|	����|r�dd
g}
tds�t|
dd�}|ddkr�d�|d�}t�|�t|��i}t���D]\�}
|��fdd�|
D��q�|��D]@\�}
|
D]9}�|�|�kr�q�ddg}
|�d���}td�st|
d|d�}|ddkr�t�d�|�q�|�|��d�||<q�q�|S)a�
    Change package state in the dpkg database.

    The state can be any one of, documented in ``dpkg(1)``:

    - install
    - hold
    - deinstall
    - purge

    This command is commonly used to mark specific packages to be held from
    being upgraded, that is, to be kept at a certain version. When a state is
    changed to anything but being held, then it is typically followed by
    ``apt-get -u dselect-upgrade``.

    Note: Be careful with the ``clear`` argument, since it will start
    with setting all packages to deinstall state.

    Returns a dict of dicts containing the package names, and the new and old
    versions:

    .. code-block:: python

        {'<host>':
            {'<package>': {'new': '<new-state>',
                           'old': '<old-state>'}
            },
            ...
        }

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.set_selections selection='{"install": ["netcat"]}'
        salt '*' pkg.set_selections selection='{"hold": ["openssh-server", "openssh-client"]}'
        salt '*' pkg.set_selections salt://path/to/file
        salt '*' pkg.set_selections salt://path/to/file clear=True
    zsThe 'selection' and 'path' arguments to pkg.set_selections are mutually exclusive, and cannot be specified togetherz Improperly-formatted selection: Nr�r�cSsg|]	}tjj�|��qSr)rsrtZstringutilsZ
to_unicoder7rrrr,�r�z"set_selections.<locals>.<listcomp>)r�r�rLr#csg|]}|�vr|�qSrrr7)�valid_statesrrr,�rzzInvalid state(s): {}r�raz--clear-selectionsr<Fr�r�rz*Running dpkg --clear-selections failed: {}r�csi|]}|��qSrr)r*r�)r�rr�
<dictcomp>�sz"set_selections.<locals>.<dictcomp>z--set-selectionsrZ)r�r�z%failed to set state %s for package %sr)r	r	rMrsrtZyamlZ	safe_load�parserZParserError�scannerZScannerErrorr�rlru�	readlinesr�r{r^r�r�rvrrrrrr)r�r?�clearr�r��errrZifile�contentZ
bad_statesr�r4Z
sel_revmapZ_pkgsr�Zcmd_inr)r�r�rr@vsr(�


������

��r@cOs||sdSi}|D]%}dd|g}td|ddd�}|�d�d	||<d
||��vr-d||<qt|�dkr<tt|����S|S)av
    .. versionadded:: 2014.7.0

    Return the name of the package that owns the file. Multiple file paths can
    be passed. Like :mod:`pkg.version <salt.modules.aptpkg.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.owner /usr/bin/apachectl
        salt '*' pkg.owner /usr/bin/apachectl /usr/bin/basename
    r#raz-SrEr�FrFr
rz
no path foundr%)r�r@r�rArrr_)�pathsr�r�r�r�r�rrr�owner�s
��rc	stjjjdi|��}|�dd�}tjj�|�dg�dd���|r'tjj�|�|r,t�|s0iStddgt	|�dd�}d	d
�}�fdd�}i}i}tjj
�|d
d�D]1}|��}|r~zdd�|�dd�D�\}	}
Wn	t
ytYqTw||	�r}|
||	<qT|||�i}qT|||�|S)a�
    .. versionadded:: 2019.2.0

    Runs an ``apt-cache show`` on the passed package names, and returns the
    results in a nested dictionary. The top level of the return data will be
    the package name, with each package name mapping to a dictionary of version
    numbers to any additional information returned by ``apt-cache show``.

    filter
        An optional comma-separated list (or quoted Python list) of
        case-insensitive keys on which to filter. This allows one to restrict
        the information returned for each package to a smaller selection of
        pertinent items.

    refresh : False
        If ``True``, the apt cache will be refreshed first. By default, no
        refresh is performed.

    CLI Examples:

    .. code-block:: bash

        salt myminion pkg.show gawk
        salt myminion pkg.show 'nginx-*'
        salt myminion pkg.show 'nginx-*' filter=description,provides
    r�F�filtercSst|t�s	t|�S|��SrS)r	rMr�r[rrr�<lambda> 
r�zshow.<locals>.<lambda>r�rvr�cSsN|�dd�}|�dd�}|dur#|dur%|�|i��|i��|�dSdSdS)NZPackageZVersion)rdrzr)r��pkginfor�r�rrr�_add-
s
�zshow.<locals>._addcs |��}|dvs
�sdS|�vS)N)�packager�T)r�)rW�Zfilter_rr�
_check_filter3
szshow.<locals>._check_filterr�r[css�|]}|��VqdSrSr'r7rrrr9=
s�zshow.<locals>.<genexpr>r
r%Nr)rsrtr��clean_kwargsrdZsplit_input�invalid_kwargsr�r�rkr�r@r(rf)r�r�r�r4rrr�rrCrW�valrrrrv
sB
���

rvc	Os�tjjjdi|��}|�dd�}|rtjj�|�t�}td|d|i���D]U\}}t�}|�	dd�ddkr9q'|��D]:\}}|dkrJ||d	<q=|d
krS||d<q=|dkr\||d
<q=|dkre||d<q=|dkrn||d<q=|dkrsq=|||<q=|||<q'|S)a<
    Return the information of the named package(s) installed on the system.

    .. versionadded:: 2015.8.1

    names
        The names of the packages for which to return information.

    failhard
        Whether to throw an exception if none of the packages are installed.
        Defaults to True.

        .. versionadded:: 2016.11.3

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.info_installed <package1>
        salt '*' pkg.info_installed <package1> <package2> <package3> ...
        salt '*' pkg.info_installed <package1> failhard=false
    r�Tzlowpkg.inforN�iir%�irr��origin�vendor�sectionr?Z
maintainerZpackagerZhomepage�urlNr)
rsrtr�r	rdr
r
r�rr)	r�r�r�r�r{Zpkg_nfoZt_nforWrXrrr�info_installedQ
s2






rcCsxd}tdd�}tdd�}tdd�}tdd�}|r:|r:|r2|r2d|�d|�d	|�d|��}|Sd|�d|��}|S)
z�
    Returns the http_proxy_url if proxy_username, proxy_password, proxy_host, and proxy_port
    config values are set.

    Returns a string.
    r#r�Z
proxy_hostZ
proxy_portZproxy_usernameZproxy_passwordzhttp://r
r�r�)r��host�port�username�passwordrrrr��
s�r�c
Ks�d}|rtj�|tj�|tjj��}i}tjj�|�D]>\}}}t�	|d�D]2}tj�||�}t
d|�}ttj�|��}	|tj�
|�|	tj�|	���d�|�|di�|d<q&q|S)z�
    .. versionadded:: 3000

    List prefetched packages downloaded by apt in the local disk.

    root
        operate on a different root directory.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_downloaded
    z/var/cache/aptz*.debr�)r��sizeZcreation_date_time_tZcreation_date_timer�r�)rr�r^�relpathrPrsrtZos_walk�fnmatchrr�r��getctime�getsize�datetime�utcfromtimestamp�	isoformatrz)
�rootr�Z	CACHE_DIRr��dirnames�	filenamesr��package_path�pkg_infoZ
pkg_timestamprrr�list_downloaded�
s&
���r$cKsztjj�dg�std��gd�}t�}td|dd�}|�d�D]}|�d�s(q |�	d	�}|d
|�}|�
|�q t|�S)a/
    .. versionadded:: 3003

    List services that use files which have been changed by the
    package manager. It might be needed to restart them.

    Requires checkrestart from the debian-goodies package.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.services_need_restart
    �checkrestartzw'checkrestart' is needed. It is part of the 'debian-goodies' package which can be installed from official repositories.)r%z	--machinez	--packagerEF)r�r[zSERVICE:rVr�)rsrtr�Z	which_binrrqr�r@r;r<r}rk)r�r�ZservicesZ	cr_outputrCZend_of_nameZservicerrr�services_need_restart�
s�

r&)T)rF)
NFNFNNNFFF)r~NN)FF)NN)TF)NNN)FFF)TT)F)TN)NNNNr�TNN)NTN)r�TrS)NNFr�){�__doc__rrr�loggingrrNr=r�r�r��collectionsr�urllib.errorr�urllib.requestrr�rr�Zsalt.configrsZ
salt.syspathsZsalt.utils.argsZsalt.utils.dataZsalt.utils.environmentZsalt.utils.filesZsalt.utils.functoolsZsalt.utils.itertoolsZsalt.utils.jsonZsalt.utils.pathZsalt.utils.pkgZsalt.utils.pkg.debZsalt.utils.stringutilsZsalt.utils.systemdZsalt.utils.versionsZsalt.utils.yamlZsalt.exceptionsrrrr	Zsalt.modules.cmdmodr
�	getLoggerrgrvZaptsources.sourceslistrrrg�ImportErrorrcrbZsoftwareproperties.ppar�r�r�r�r�r��	frozensetr�r rrr"rHr�r�r�r�r�r�r�rt�	functoolsZalias_functionr�r�r�r�r'r(r~r#r2r�rrDr�rXrYrZr�r]rjrurr~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr@rrvrr�r$r&rrrr�<module>s.
�����1TJ
X�
\
�
 
1
7
,
,
k
@E
�
W
0

9+<'Gn
2K
�

S0
j

+h#P7
$