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

�N�g*?�@s.dZddlZddlZddlZddlZddlZddlmm	Z	ddl
ZddlZddlZddl
ZddlmZmZe�e�ZdZdd�Ze	jdd��Ze	jd	d
��Zdd�Zd,dd�Zd-dd�Zdd�ZeZdd�Zdd�Zdd�Z d-dd�Z!d.dd�Z"d/dd �Z#d!d"�Z$d#d$�Z%d,d%d&�Z&d0d(d)�Z'd*d+�Z(dS)1z[
Package support for XBPS package manager (used by VoidLinux)

.. versionadded:: 2016.11.0
�N)�CommandExecutionError�MinionError�pkgcCstddvrt�rtSdS)zM
    Set the virtual pkg module if the os is Void and xbps-install found
    �osZVoid)Fz Missing dependency: xbps-install)Z
__grains__�_check_xbps�__virtualname__�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/xbpspkg.py�__virtual__sr
cCstjj�d�S)zQ
    Looks to see if xbps-install is present on the system, return full path
    �xbps-install)�salt�utils�path�whichrrrr	r%srcCsNtdt�dgdd�}|durdSt�d�}|�|�}|sdS|�d��d	�S)
z
    Get the xbps version
    �cmd.runz	--version�trace��output_loglevelNFz!(?:XBPS:[\s]+)([\d.]+)(?:[\s]+.*)��.)�__salt__r�re�compile�search�group�split)Zversion_stringZ
VERSION_MATCHZ
version_matchrrr	�_get_version-s
�

rcCs6tdd�}|�d�ddvrtdddd	�d
Sd
S)z�
    Recomputes internal hash table for the PATH variable.
    Used whenever a new command is created during the current
    session.
    zenviron.getZSHELL�/���)ZcshZtcshrZrehashrrN)rr)�shellrrr	�_rehashAs�r Fc	s�tjj�|�}t�fdd�dD��riSd}i}td|dd�}|��D],}|s)q$z|�d�d	�d
d	�\}}Wnt	yGt
�d|�Ynwtd|||�q$td
|�|s_td|�|S)z�
    List the packages currently installed as a dict::

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

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_pkgs
    cs g|]}tjj���|���qSr)rr
�data�is_true�get��.0�x��kwargsrr	�
<listcomp>[s zlist_pkgs.<locals>.<listcomp>)ZremovedZ
purge_desiredz
xbps-query -lrrrNr�-�/xbps-query: Unexpected formatting in line: "%s"zpkg_resource.add_pkgzpkg_resource.sort_pkglistzpkg_resource.stringify)rr
r!r"�anyr�
splitlinesr�rsplit�
ValueError�log�error)Zversions_as_listr(�cmd�ret�out�liner�verrr'r	�	list_pkgsLs*��r7Tc
Ks�tjj�|�}|rt�i}d}td|dd�}|��D]4}|s!qd}d}z|��d�dd	�\}}Wnt	t
fyDt�d
|�Yqwt�
d||�|||<q|S)z�
    Check whether or not an upgrade is available for all packages

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_upgrades
    zxbps-install -unrrrzbase-systemZNonNumericValueIsErrorrr*rr+�pkg=%s version=%s)rr
r!r"�
refresh_dbrr-rr.r/�
IndexErrorr0r1r)�refreshr(r3r2r4r5rr6rrr	�
list_upgradesvs(�
r<c

Ostjj�|�dd��}|sdS|rt�i}|D]}d||<qddg}|�|�td|ddd�}|��D]<}|s:q5|�	d	�d
krBq5z|�
�d�dd
�\}}	Wntt
fyat�d|�Yq5wt�d||	�||vrq|	||<q5t|�d
kr~||dS|S)a�
    Return the latest version of the named package available for upgrade or
    installation. If more than one package name is specified, a dict of
    name/version pairs is returned.

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

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.latest_version <package name>
        salt '*' pkg.latest_version <package1> <package2> <package3> ...
    r;T�rz-unrr)Zignore_retcoderz is up to date.rrr*rr+r8)rr
r!r"�popr9�extendrr-�findrr.r/r:r0r1r�len)
�namesr(r;r3�namer2r4r5rr6rrr	�latest_version�s: 

��rDcKs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=)rD)rCr(rrr	�upgrade_available�s
rEcKsRtjj�t�d}td|dd�}|ddkr'd}d|vr#||d7}t|��d	S)
z�
    Update list of available packages from installed repos

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.refresh_db
    zxbps-install -Sy�cmd.run_allrr�retcoderr=�stderrT)rr
rZ
clear_rtagZ__opts__rr)r(r2�callZcommentrrr	r9�sr9cOstd|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)rBr(rrr	�versions
rJcKsrt�}dd�|r
dnd�g}td|ddd�}t�d	d
�t�}tjj�||�}|ddkr7t	d
||d�d��|S)a�
    Run a full system upgrade

    refresh
        Whether or not to refresh the package database before installing.
        Default is `True`.

    Returns a dictionary containing the changes:

    .. code-block:: python

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

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    rz-{}yu�Sr=rFrF)rZpython_shell�
pkg.list_pkgsNrGrz&Problem encountered upgrading packages)Zchanges�result)�info)
r7�formatr�__context__r>rr
r!�
compare_dictsr)r;r(�oldr2rM�newr3rrr	�upgrade#s�rTc
Ks�ztd|||fi|��\}}Wnty }zt|��d}~ww|s%iS|dkr1t�d|�iSdg}	|r;|	�d�|rE|	�d|���|	�d�|	�|�t�}
td	|	d
d�t�	dd�t�}t
�tjj
�|
|�S)
ak
    Install the passed package

    name
        The name of the package to be installed.

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

    fromrepo
        Specify a package repository (url) to install from.


    Multiple Package Installation Options:

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

        CLI Example:

        .. code-block:: bash

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

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

        CLI Example:

        .. code-block:: bash

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

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

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

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.install <package name>
    �pkg_resource.parse_targetsNZ
repositoryz"xbps: pkg_type "%s" not supported.rz-Sz
--repository=�-yrrrrL)rrrr0r1�appendr?r7rPr>r rr
r!rQ)rCr;Zfromrepo�pkgsZsourcesr(�
pkg_params�pkg_type�excr2rRrSrrr	�installNs83����


r\c

s�ztd||�\}}Wnty}zt|��d}~ww|s iSt���fdd�|D�}|s0iSddg}|r;|�d�|�|�td|d	d
�t�dd�t�}	tj	j
��|	�S)a�
    name
        The name of the package to be deleted.

    recursive
        Also remove dependent packages (not required elsewhere).
        Default mode: enabled.

    Multiple Package Options:

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

    Returns a list containing the removed packages.

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.remove <package name> [recursive=False]
        salt '*' pkg.remove <package1>,<package2>,<package3> [recursive=False]
        salt '*' pkg.remove pkgs='["foo", "bar"]' [recursive=False]
    rUNcsg|]}|�vr|�qSrrr$�rRrr	r)�szremove.<locals>.<listcomp>zxbps-removerVz-RrrrrL)rrrr7rWr?rPr>rr
r!rQ)
rCrX�	recursiver(rYrZr[�targetsr2rSrr]r	�remove�s(��

r`c	Ks�i}tdddd�}|��D]D}i}|sqz
|���dd�\}}}Wnty1t�d|�Ynw|��r:t|�nd|d	<||d
<|dkrHdnd
|d<|||d
<q|S)zr
    List all repos known by XBPS

    CLI Example:

    .. code-block:: bash

       salt '*' pkg.list_repos
    rz
xbps-query -Lrr� �z?Problem parsing xbps-query: Unexpected formatting in line: "%s"rZnbpkg�urlz(RSA signed)TFZ	rsasigned)	rr-�striprr/r0r1�isdigit�int)r(�reposr4r5�repo�nbrc�rsarrr	�
list_repos�s&
��rkcKst�}||vr||SiS)z�
    Display information about the repo.

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.get_repo 'repo-url'
    )rk)rhr(rgrrr	�get_repo�s
rlc
	Csg}g}ddg}d}t�d|d�}|D]}|�t�||��q|D]a}g}	tjj�|d��"}
|
D]}|�tjj	�
|��rE|�|�q3|	�|�q3Wd�n1sUwY|r�||vr�|	r�tjj�|d��
}|�|	�Wd�n1szwYq$t
�|�q$|S)	a
    Find what file a repo is called in.

    Helper function for add_repo() and del_repo()

    repo
        url of the repo to locate (persistent).

    rewrite
        Whether to remove matching repository settings during this process.

    Returns a list of absolute paths.
    z/etc/xbps.d/z/usr/share/xbps.d/z*.confz\s*repository\s*=\s*z/?\s*(#.*)?$�rN�w)rrr?�globrr
�files�fopen�match�stringutilsZ
to_unicoderW�
writelinesrr`)
rh�rewriteZret_valrpZ	conf_dirsZ	name_globZregexZcur_dir�filenameZ
write_buffZcur_filer5Zrewrite_filerrr	�_locate_repo_filess2����
�rw�#/usr/share/xbps.d/15-saltstack.confcCsxt|�s:z+tjj�|d��}|�tjj�d|�d���Wd�WdS1s(wYWdSty9YdSwdS)aO
    Add an XBPS repository to the system.

    repo
        url of repo to add (persistent).

    conffile
        path to xbps conf file to add this repo
        default: /usr/share/xbps.d/15-saltstack.conf

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.add_repo <repo url> [conffile=/path/to/xbps/repo.conf]
    za+zrepository=�
NFT)	rwrr
rprq�writersZto_str�OSError)rh�conffileZ	conf_filerrr	�add_repo0s����r}cKs(z	t|dd�WdStyYdSw)z�
    Remove an XBPS repository from the system.

    repo
        url of repo to remove (persistent).

    CLI Examples:

    .. code-block:: bash

        salt '*' pkg.del_repo <repo url>
    T)ruF)rwr{)rhr(rrr	�del_repoLs��r~)F)T)NFNNN)NNT)rx))�__doc__ro�loggingrrZsalt.utils.datarZsalt.utils.decoratorsr
Z
decoratorsZsalt.utils.filesZsalt.utils.pathZsalt.utils.pkgZsalt.utils.stringutilsZsalt.exceptionsrr�	getLogger�__name__r0rr
Zmemoizerrr r7r<rDZavailable_versionrEr9rJrTr\r`rkrlrwr}r~rrrr	�<module>sF
	



*+J


+
S4

-