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

�N�g�<�@sdZddlZddlZddlZddlZddlZddlZddlm	Z	dZ
e�e�Z
dZdd�Zdd	�Z	
d$dd�Zd
d�Ze
fdd�Ze
dfdd�Ze
dfdd�Ze
dddddd
fdd�Ze
ddddd
fdd�Ze
dfdd�Ze
fdd�Ze
fdd�Ze
dfd d!�Ze
dfd"d#�ZdS)%z>
Aptly Debian repository manager.

.. versionadded:: 2018.3.0
�N)�SaltInvocationErrorz/etc/aptly.conf�aptlycCstjj�d�r	tSdS)zI
    Only works on systems with the aptly binary in the system path.
    r)FzAThe aptly binaries required cannot be found or are not installed.)�salt�utils�path�which�__virtualname__�r	r	�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/aptly.py�__virtual__srcCsB|�dd�td|dd�}|ddkrt�d||d�|d	S)
z`
    Run the aptly command.

    :return: The string output of the command.
    :rtype: str
    rrzcmd.run_allT)Zignore_retcode�retcodez'Unable to execute command: %s
Error: %s�stderr�stdout)�insert�__salt__�log�debug)�cmd�cmd_retr	r	r
�_cmd_run s
r�basec	Cs�t�}d}|||d�}|rtd||�}|st�d|�dS|D]}||dur5|�d|�d||���q |r@|�d|���|S)	a�
    Format the common arguments for creating or editing a repository.

    :param str comment: The description of the repository.
    :param str component: The default component to use when publishing.
    :param str distribution: The default distribution to use when publishing.
    :param str uploaders_file: The repository upload restrictions config.
    :param str saltenv: The environment the file resides in.

    :return: A list of the arguments formatted as aptly arguments.
    :rtype: list
    N��comment�	component�distributionz
cp.cache_filez%Unable to get cached copy of file: %sF�-�=z-uploaders-file=)�listrr�error�append)	rrr�uploaders_file�saltenv�retZcached_uploaders_path�settings�settingr	r	r
�_format_repo_args0s$��r%cCs8t�d|�tj�|�sd|��}t�|�t|��dS)z�
    Validate that the configuration file exists and is readable.

    :param str config_path: The path to the configuration file for the aptly instance.

    :return: None
    :rtype: None
    zChecking configuration file: %sz"Unable to get configuration file: N)rr�osr�isfilerr)�config_path�messager	r	r
�_validate_configXs	

�r*cCs.t|�ddd|��g}t|�}tjj�|�S)a
    Get the configuration data.

    :param str config_path: The path to the configuration file for the aptly instance.

    :return: A dictionary containing the configuration data.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.get_config
    Zconfig�show�-config=)r*rrr�json�loads)r(rrr	r	r
�
get_configisr/FcCsjt|�t�}ddd|��dg}t|�}dd�|��D�}t�dt|��|D]}t|||d�||<q'|S)	aN
    List all of the repos.

    :param str config_path: The path to the configuration file for the aptly instance.
    :param bool with_packages: Return a list of packages in the repo.

    :return: A dictionary of the repositories.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.list_repos
    �reporr,�	-raw=truecS�g|]}|���qSr	��strip��.0�liner	r	r
�
<listcomp>��zlist_repos.<locals>.<listcomp>zFound repositories: %s)�namer(�
with_packages)r*�dictr�
splitlinesrr�len�get_repo)r(r;r"rrZreposr:r	r	r
�
list_repos�s�r@c	
Cs�t|�tt|����}t�}ddd|��d|��|g}t|�}|��D]C}z0|�d�}|d���dd��	�}d	�
|����d	d
�}tjj
�tjj
�|d�	���||<Wq$ttfygt�d|�Yq$w|rrt�d
|�|St�d|�|S)a�
    Get the details of the repository.

    :param str name: The name of the repository.
    :param str config_path: The path to the configuration file for the aptly instance.
    :param bool with_packages: Return a list of packages in the repo.

    :return: A dictionary containing information about the repository.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.get_repo name="test-repo"
    r0r+r,z-with-packages=�:r�default�� �_�zSkipping line: %szFound repository: %szUnable to find repository: %s)r*�str�bool�lowerr<rr=�split�replacer4�joinrrZstringutilsZto_noneZto_num�AttributeError�
IndexErrorrr)	r:r(r;r"rrr7�items�keyr	r	r
r?�s4�
���r?cCs�t|�td||d�}|rt�d|�dSddd|��g}	t|||||d�}
|	�|
�|	�|�|r;|	�d	d
|g�t|	�td||d�}|rQt�d|�dSt�d|�d
S)aO
    Create the new repository.

    :param str name: The name of the repository.
    :param str config_path: The path to the configuration file for the aptly instance.
    :param str comment: The description of the repository.
    :param str component: The default component to use when publishing.
    :param str distribution: The default distribution to use when publishing.
    :param str uploaders_file: The repository upload restrictions config.
    :param str from_snapshot: The snapshot to initialize the repository contents from.
    :param str saltenv: The environment the file resides in.

    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.new_repo name="test-repo" comment="Test main repo" component="main" distribution="trusty"
    �aptly.get_repo�r:r(zRepository already exists: %sTr0�creater,�rrrr r!�from�snapshotzCreated repo: %szUnable to create repo: %sF)	r*rrrr%�extendrrr)r:r(rrrr Z
from_snapshotr!�current_repor�repo_paramsr0r	r	r
�new_repo�s0�

rZcCs<t|�t�}|||d�}t|�D]}	||	dur|�|	d�qtd||d�}
|
s2t�d|�dSt|
�D]}||vrB|
�|d�q6||
krOt�d|�dSd	d
d|��g}t|||||d�}
|�	|
�|�
|�t|�td||d�}|D]}	||	||	kr�|�|	||	i�qx|r�t�d
|�dSt�d|�dS)a_
    Configure the repository settings.

    :param str name: The name of the repository.
    :param str config_path: The path to the configuration file for the aptly instance.
    :param str comment: The description of the repository.
    :param str component: The default component to use when publishing.
    :param str distribution: The default distribution to use when publishing.
    :param str uploaders_file: The repository upload restrictions config.
    :param str from_snapshot: The snapshot to initialize the repository contents from.
    :param str saltenv: The environment the file resides in.

    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.set_repo name="test-repo" comment="Test universe repo" component="universe" distribution="xenial"
    rNrQrRzUnable to get repo: %sFz;Settings already have the desired values for repository: %sTr0Zeditr,rTz0Unable to change settings for the repository: %szFSettings successfully changed to the desired values for repository: %s)
r*r<r�poprrrrr%rWrr�update)r:r(rrrr r!Zfailed_settingsr#r$Zcurrent_settingsZcurrent_settingrrYZnew_settingsr	r	r
�set_reposX����

��r]cCs�t|�tt|����}td||d�}|st�d|�dSddd|��d|��|g}t|�td||d�}|rAt�d	|�d
St�d|�dS)a�
    Remove the repository.

    :param str name: The name of the repository.
    :param str config_path: The path to the configuration file for the aptly instance.
    :param bool force: Whether to remove the repository even if it is used as the source
        of an existing snapshot.

    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.delete_repo name="test-repo"
    rQrRzRepository already absent: %sTr0Zdropr,z-force=zUnable to remove repo: %sFzRemoved repo: %s)	r*rGrHrIrrrrr)r:r(�forcerXrr0r	r	r
�delete_repops&�r_cC�Ht|�ddd|��dg}t|�}dd�|��D�}t�dt|��|S)a
    Get a list of all the mirrors.

    :param str config_path: The path to the configuration file for the aptly instance.

    :return: A list of the mirror names.
    :rtype: list

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.list_mirrors
    Zmirrorrr,r1cSr2r	r3r5r	r	r
r8�r9z list_mirrors.<locals>.<listcomp>zFound mirrors: %s�r*rr=rrr>�r(rrr"r	r	r
�list_mirrors��rccCr`)a+
    Get a list of all the published repositories.

    :param str config_path: The path to the configuration file for the aptly instance.

    :return: A list of the published repository names.
    :rtype: list

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.list_published
    Zpublishrr,r1cSr2r	r3r5r	r	r
r8�r9z"list_published.<locals>.<listcomp>z Found published repositories: %srarbr	r	r
�list_published�rdrecCsbt|�ddd|��dg}|r|�d�n|�d�t|�}dd�|��D�}t�d	t|��|S)
ae
    Get a list of all the snapshots.

    :param str config_path: The path to the configuration file for the aptly instance.
    :param bool sort_by_time: Whether to sort by creation time instead of by name.

    :return: A list of the snapshot names.
    :rtype: list

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.list_snapshots
    rVrr,r1z
-sort=timez
-sort=namecSr2r	r3r5r	r	r
r8�r9z"list_snapshots.<locals>.<listcomp>zFound snapshots: %s)r*rrr=rrr>)r(Zsort_by_timerrr"r	r	r
�list_snapshots�s
rfcCs�t|�tt|����}t�t�d�}ddd|��d|��dg}t|�}d}d}d	}|��D]-}|rLt�||�}	|	rJd
|��}
||
�	|	�
d��nd	}|s[t�||�}	|	r[|	�
d�}q.t�d
t
|d��t�dt
|d��|S)a�
    Remove data regarding unreferenced packages and delete files in the package pool that
        are no longer being used by packages.

    :param bool dry_run: Report potential changes without making any changes.

    :return: A dictionary of the package keys and files that were removed.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.cleanup_db
    )�deleted_keys�
deleted_filesZdbZcleanupr,z	-dry-run=z
-verbose=truez5^List\s+[\w\s]+(?P<package_type>(file|key)s)[\w\s]+:$z^\s+-\s+(?P<package>.*)$NZdeleted_�package�package_typez(Package keys identified for deletion: %srgz)Package files identified for deletion: %srh)r*rGrHrIrrr=�re�searchr�grouprrr>)r(�dry_runr"rrZtype_patternZlist_patternZ
current_blockr7�matchrjr	r	r
�
cleanup_db�s8�

�rp)NNNNr)�__doc__�loggingr&rkZsalt.utils.jsonrZsalt.utils.pathZsalt.utils.stringutilsZsalt.exceptionsrZ_DEFAULT_CONFIG_PATH�	getLogger�__name__rrrrr%r*r/r@r?rZr]r_rcrerfrpr	r	r	r
�<module>sN
	
�(!6
�A
�[-