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/modules/__pycache__/freezer.cpython-310.pyc
o

�N�g�(�@s�dZddlZddlZddlZddlmmZddlm	Z	ddl
mZddlm
Z
e�e�ZddiZdd	�Zd
d�Zd dd
�Zd dd�Zdd�Zd!dd�Zdd�Zdd�Zdd�Zdd�Zd!dd�Zdd�ZdS)"z�
Module for freezer
:maintainer:    Alberto Planas <aplanas@suse.com>
:maturity:      new
:depends:       None
:platform:      Linux
�N)�CommandExecutionError)�clean_kwargs)�fopen�list_�listcCsdS)z�
    Freezer is based on top of the pkg module.

    Return True since the `pkg` module should always exist. This
    avoids the overhead of loading all modules.

    T�rrr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/freezer.py�__virtual__sr	cCstj�tdd�S)z9
    Return the path where we will store the states.
    Zcachedir�freezer)�os�path�joinZ__opts__rrrr�_states_path$srcCs:|sdn|}t�}tj�||�d��tj�||�d��fS)zR
    Return the full path for the packages and repository freezer
    files.

    r
�	-pkgs.yml�	-reps.yml)rrrr
)�name�states_pathrrr�_paths+s
�rcCs"|sdn|}tdd�t|�D��S)a�
    Return True if there is already a frozen state.

    A frozen state is merely a list of packages (including the
    version) in a specific time. This information can be used to
    compare with the current list of packages, and revert the
    installation of some extra packages that are in the system.

    name
        Name of the frozen state. Optional.

    CLI Example:

    .. code-block:: bash

        salt '*' freezer.status
        salt '*' freezer.status pre_install

    r
css�|]	}tj�|�VqdS�N)rr�isfile)�.0�irrr�	<genexpr>Ns�zstatus.<locals>.<genexpr>)�allr)rrrr�status9srcCsRg}t�}tj�|�s
|St�|�D]}|�d�r"|�|dd��qtt|��S)zw
    Return the list of frozen states.

    CLI Example:

    .. code-block:: bash

        salt '*' freezer.list

    )rrNi����)	rrr�isdir�listdir�endswith�append�sorted�set)�retr�staterrrrQs
�Fc
Ks�t�}z
tj�|�st�|�Wnty-}zd}t�|||�t|||f��d}~wwt	|�r8|s8td��t
di|��}tddi|��}tddi|��}tt
|�||f�D]\}	}
t|	d��}t�|
|�Wd�n1stwYqZdS)	a~
    Save the list of package and repos in a freeze file.

    As this module is build on top of the pkg module, the user can
    send extra attributes to the underlying pkg module via kwargs.
    This function will call ``pkg.list_pkgs`` and ``pkg.list_repos``,
    and any additional arguments will be passed through to those
    functions.

    name
        Name of the frozen state. Optional.

    force
        If true, overwrite the state. Optional.

    CLI Example:

    .. code-block:: bash

        salt '*' freezer.freeze
        salt '*' freezer.freeze pre_install
        salt '*' freezer.freeze force=True root=/chroot

    z6Error when trying to create the freezer storage %s: %sNz?The state is already present. Use force parameter to overwrite.�
pkg.list_pkgs�pkg.list_repos�wTr)rrr�exists�makedirs�OSError�log�errorrrr�__salt__�ziprr�json�dump)r�force�kwargsr�e�msg�safe_kwargs�pkgs�repos�fname�content�fprrr�freezeis0
������r9c	Ks�tdd	i|��}t|�t|�}|D]N}z&||��}|�|�td|fi|��|dd�|�t�d|�Wqtya}zd}t�|||�|d�|||f�WYd}~qd}~wwdS)
z0Add missing repositories and update the ret dictr$zpkg.mod_repor5�addzAdded missing repository %szError adding %s repository: %s�commentNr)	r+r �copy�updaterr)�info�	Exceptionr*)	�frozen_reposr!r0r5Z
missing_repos�repoZ_tmp_kwargsr1r2rrr�_add_missing_repositories�s 
"���rBcKs�tdd	i|��}t|�t|�}|D]C}ztd|fi|��|dd�|�t�d|�WqtyV}zd}t�|||�|d�|||f�WYd}~qd}~wwdS)
z1Remove extra repositories and update the ret dictr$zpkg.del_repor5�removezRemoved extra repository %sz Error removing %s repository: %sr;Nr�r+r rr)r>r?r*)r@r!r0r5Zextra_reposrAr1r2rrr�_remove_extra_repositories�s"���rEcKs�tdd
i|��}t|�t|�}|D]D}ztdd
d|i|��|dd�|�t�d|�WqtyW}zd}t�|||�|d�|||f�WYd	}~qd	}~wwd	S)z,Add missing packages and update the ret dictr#zpkg.installrr4r:zAdded missing package %szError adding %s package: %sr;NrrD)�frozen_pkgsr!r0r4Zmissing_pkgs�pkgr1r2rrr�_add_missing_packages�s"���rHcKs�tdd
i|��}t|�t|�}|D]D}ztdd
d|i|��|dd�|�t�d|�WqtyW}zd}t�|||�|d�|||f�WYd	}~qd	}~wwd	S)z-Remove extra packages and update the ret dictr#z
pkg.removerr4rCzRemoved extra package %szError removing %s package: %sr;NrrD)rFr!r0r4Z
extra_pkgsrGr1r2rrr�_remove_extra_packages�s"���rIc
	Kst|�std��i}i}tt|�||f�D] \}}t|��}|�t�|��Wd�n1s0wYqtdi|��}ggd�ggd�gd�}	t	||	fi|��t
||	fi|��t||	fi|��t||	fi|��|r|	dst|�D]}t
�|�qw|	S)a�
    Make sure that the system contains the packages and repos from a
    frozen state.

    Read the list of packages and repositories from the freeze file,
    and compare it with the current list of packages and repos. If
    there is any difference, all the missing packages are repos will
    be installed, and all the extra packages and repos will be
    removed.

    As this module is build on top of the pkg module, the user can
    send extra attributes to the underlying pkg module via kwargs.
    This function will call ``pkg.list_repos``, ``pkg.mod_repo``,
    ``pkg.list_pkgs``, ``pkg.install``, ``pkg.remove`` and
    ``pkg.del_repo``, and any additional arguments will be passed
    through to those functions.

    name
        Name of the frozen state. Optional.

    clean
        If True remove the frozen information YAML from the cache

        .. versionadded:: 3000

    CLI Example:

    .. code-block:: bash

        salt '*' freezer.restore
        salt '*' freezer.restore root=/chroot

    �Frozen state not found.N)r:rC)r4r5r;r;r)rrr,rrr=r-�loadrrBrHrIrErrC)
rZcleanr0rFr@r6r7r8r3r!rrr�restore�s,"
���rLc		Cs�i}t|�r
t|�std��tt|�t|��D]W\}}t|d��
}t�|�}Wd�n1s0wYt|d��
}t�|�}Wd�n1sJwY|�d�r_tj	j
�||�|d<q|�d�rntj	j
�||�|d<q|S)a�
    Display the difference between two frozen states. The results are shown as
    as a dictionary with keys for packages and repositories. Each key may
    contain a changes dictionary showing items that differ between the two
    frozen states. Items shown in the "old" changes but not the "new" were
    removed. Items in "new" but not "old" were added. Items shown in both
    probably updated/changed versions between freezes.

    old
        Name of the "old" frozen state. Required.

    new
        Name of the "new" frozen state. Required.

    CLI Example:

    .. code-block:: bash

        salt '*' freezer.freeze pre_install post_install

    rJ�rNrr4rr5)rrr,rrr-rKr�salt�utilsZ
dictdifferZ	deep_diff)	�old�newr!ZofileZnfileZofpZold_dictZnfpZnew_dictrrr�compare-s ��

�rRr)NF)�__doc__�loggingrZsalt.utils.dictdifferrNZsalt.utils.jsonrOr-Zsalt.exceptionsrZsalt.utils.argsrZsalt.utils.filesr�	getLogger�__name__r)Z__func_alias__r	rrrrr9rBrErHrIrLrRrrrr�<module>s.
�


0
P