Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/payload/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/payload/__pycache__/flatpak.cpython-36.pyc

3

C��e�2�@sddlZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZmZm
Z
mZddlmZddlmZejdd	�ejd
d�ddlmZmZmZmZmZdd
lmZee�ZdgZGdd�de�Z Gdd�de�Z!Gdd�de!�Z"Gdd�de!�Z#dS)�N)�ABC�abstractmethod)�get_module_logger)�_)�GError�VariantType�Variant�Bytes)�	progressQ)�FlatpakInstallErrorZFlatpakz1.0ZGioz2.0)�Transaction�Installation�Remote�TransactionOperationType�TransactionErrorDetails)�File�FlatpakPayloadc@s�eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Ze
dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zed&d'��Zd(S))rz9Main class to handle flatpak installation and management.ZAnacondazfile:///flatpak/repocCs||_d|_d|_dS)a�Create and initialize this class.

        This flatpak implementation works on a repository stored in the stage2 image specifically
        for the SilverBlue image. It will be used from the ostree payload after the installation.
        This is a temporal solution for SilverBlue use-case. It will be extended as full featured
        payload in the future.

        :param sysroot: path to the system root
        :type sysroot: str
        N)�_sysroot�_remote_refs_list�_transaction)�selfZsysroot�r�/usr/lib64/python3.6/flatpak.py�__init__2szFlatpakPayload.__init__cCstjj|jd�}|j|�dS)z�Create flatpak objects and set them to install to the result system.

        This call will re-initialize current settings so everything set here will be cleaned.
        zvar/lib/flatpakN)�os�path�joinr�initialize_with_path)r�target_pathrrr�initialize_with_system_pathBsz*FlatpakPayload.initialize_with_system_pathcCsDtjd|�|j|j|jd�}|j||�}|j|�|_t|�|_	dS)a>Create flatpak objects and set them for the given target path.

        The initialization process will create a repository on the given path.

        This call will re-initialize current settings so everything set here will be cleaned.

        :param str target_path: path where we want to install flatpaks
        zConfigure flatpak for path %sFN)
�log�debug�_create_flatpak_remote�LOCAL_REMOTE_NAME�LOCAL_REMOTE_PATH�_create_flatpak_installation�_create_flatpak_transactionr�RemoteRefsListr)rr�remote�installationrrrrJs
	z#FlatpakPayload.initialize_with_pathcCs"tj|�}|j|�|j|�|S)N)r�newZset_gpg_verifyZset_url)r�namerZ
gpg_verifyr(rrrr"[s


z%FlatpakPayload._create_flatpak_remotecCs*tj|�}tj|dd�}|j|dd�|S)NF)rZnew_for_pathr
�
add_remote)rr(r�install_pathr)rrrr%bs
z+FlatpakPayload._create_flatpak_installationcCs8tj|�}|jd|j�|jd|j�|jd|j�|S)NZ
new_operationZoperation_doneZoperation_error)rZnew_for_installationZconnect�_operation_started_callback�_operation_stopped_callback�_operation_error_callback)rr)�transactionrrrr&is

z*FlatpakPayload._create_flatpak_transactioncCsRtjd�|jrH|jj�j�}|j�}tjj|�rHtjd|�tj	|�d|_dS)z�Clean the current repository and settings.

        One of the initialize methods have to be called before the flatpak object can be
        used again.
        zCleaning up flatpak repositoryzRemoving flatpak repository %sN)
r r!r�get_installation�get_pathrr�exists�shutilZrmtree)rrrrr�cleanupqs

zFlatpakPayload.cleanupcCstjj|jdd��S)zQTest if flatpak installation source is available.

        :return: bool
        �N)rr�isdirr$)�clsrrr�is_available�szFlatpakPayload.is_availablecCs
|jj�S)z�Get required size to install all the flatpaks.

        :returns: bytes required to install all flatpaks in the remote
        :rtype: int
        )r�get_sum_installation_size)rrrr�get_required_size�sz FlatpakPayload.get_required_sizecCs8tjd||�|j||d�}|jj�}|j|dd�dS)z�Add a new remote to the existing installation.

        :param str name: name of the remote
        :param str url: url pointing to the remote (use file:// for local paths)
        z"Adding a new flatpak remote %s: %sTN)r r!r"rr2r,)rr+Zurlr(r)rrrr,�s
zFlatpakPayload.add_remotecCsPtjd|�|jj�}x4|j�D](}|j�|kr |j|d�tjd|�q WdS)znRemove remote from the existing installation.

        :param str name: Name of the remote to remove.
        zRemoving a flatpak remote %sNzFlatpak remote %s removed)r r!rr2Zlist_remotesZget_name�
remove_remote)rr+r)r(rrrr=�s
zFlatpakPayload.remove_remotecCsJ|j�y|jj�Wn.tk
rD}ztt|���WYdd}~XnXdS)z-Install all the refs contained on the remote.N)�_stuff_refs_to_transactionrZrunrr�str)rZexnrrr�install_all�s
zFlatpakPayload.install_allcCs*x$|jj�D]}|jj|j|d�qWdS)N)r�get_refs_full_formatrZadd_installr#)r�refrrrr>�sz)FlatpakPayload._stuff_refs_to_transactioncCst|jj��}|j|�dS)ziReplace remote on all the installed refs.

        :param str new_remote: name of the new remote
        N)�InstalledRefsListrr2�replace_installed_refs_remote)rZ
new_remoteZinstalled_refs_listrrrrD�sz,FlatpakPayload.replace_installed_refs_remotecCs*|j|d�tjtd�d|j�i�dS)a�Start of the new operation.

        :param transaction: the main transaction object
        :type transaction: Flatpak.Transaction instance
        :param operation: object describing the operation
        :type operation: Flatpak.TransactionOperation instance
        :param progress: object providing progess of the operation
        :type progress: Flatpak.TransactionProgress instance
        ZstartedzInstalling %(flatpak_name)sZflatpak_nameN)�_log_operationr
Zsend_messager�get_ref)rr1�	operationZprogressrrrr.�s

z*FlatpakPayload._operation_started_callbackcCs|j|d�dS)a�Existing operation ended.

        :param transaction: the main transaction object
        :type transaction: Flatpak.Transaction instance
        :param operation: object describing the operation
        :type operation: Flatpak.TransactionOperation instance
        :param str commit: operation was committed this is a commit id
        :param result: object containing details about the result of the operation
        :type result: Flatpak.TransactionResult instance
        ZstoppedN)rE)rr1rGZcommit�resultrrrr/�sz*FlatpakPayload._operation_stopped_callbackcCs&|j|d�tjd|j|tjk�dS)aProcess error raised by the flatpak operation.

        :param transaction: the main transaction object
        :type transaction: Flatpak.Transaction instance
        :param operation: object describing the operation
        :type operation: Flatpak.TransactionOperation instance
        :param error: object containing error description
        :type error: GLib.Error instance
        :param details: information if the error was fatal
        :type details: int value of Flatpak.TransactionErrorDetails
        ZfailedzCFlatpak installation failed with message: '%s' -- error is fatal %sN)rEr �error�messagerZFATAL)rr1rGrIZdetailsrrrr0�sz(FlatpakPayload._operation_error_callbackcCs&tj|j��}tjd||j�|�dS)Nz(Flatpak operation: %s of ref %s state %s)rZ	to_stringZget_operation_typer r!rF)rG�stateZoperation_type_strrrrrE�szFlatpakPayload._log_operationN)�__name__�
__module__�__qualname__�__doc__r#r$rrrr"r%r&r6�classmethodr:r<r,r=r@r>rDr.r/r0�staticmethodrErrrrr,s*	
		
c@s4eZdZdd�Zedd��Zedd��Zdd�Zd	S)
�BaseRefsListcCs||_g|_dS)z�Load all flatpak refs from the installed system.

        Makes easier operations above the refs.

        :param installation: flatpak installation instance with remotes attached
        :type installation: Flatpak.Installation instance
        N)�
_installation�_refs)rr)rrrr�szBaseRefsList.__init__cCs|js|j�|jS)z'Get list of installed application refs.)rT�
_load_refs)rrrr�refsszBaseRefsList.refscCsdS)Nr)rrrrrU
szBaseRefsList._load_refscCs&g}x|jD]}|j|j��qW|S)anGet list of refs in full format.

        This formatting is used for example for installation.
        The format looks like:

        [app|runtime]/ref/arch/branch

        examples:
        runtime/org.videolan.VLC.Plugin.bdj/x86_64/3-18.08
        app/org.gnome.Gnote/x86_64/stable

        :return: list of refs in the full format
        :rtype: [str]
        )rV�appendZ
format_ref)rrHrBrrrrAsz!BaseRefsList.get_refs_full_formatN)	rLrMrNr�propertyrVrrUrArrrrrR�srRc@seZdZdd�Zdd�ZdS)r'cCs|jjtjd�|_dS)aLoad remote application references.

        This will load the list just once. We can do that because we support only one repository
        on the fixed place right now. This have to be re-implemented when there will be a proper
        flatpak support.
        N)rSZlist_remote_refs_syncrr#rT)rrrrrU'szRemoteRefsList._load_refscCs$d}x|jD]}||j�}qW|S)z�Get sum of the installation size for all the flatpaks.

        :return: sum of bytes of the installation size of the all flatpaks
        :rtype: int
        r)rVZget_installed_size)rZsize_sumrBrrrr;2sz(RemoteRefsList.get_sum_installation_sizeN)rLrMrNrUr;rrrrr'%sr'c@s eZdZdZdd�Zdd�ZdS)rCz(ssasta{sv})cCs|jj�|_dS)N)rSZlist_installed_refsrT)rrrrrUCszInstalledRefsList._load_refscs�|jj�}|j�}t|j�}x�|j�D]�}tjj||d�}t|d��}|j	�}WdQRXt
j|t|�d���fdd�t
�j��D�}t
d|�|d<t
j|�}	|	j�j�}
t|d	��}|j|
�WdQRXq&WdS)
z�Replace remote for all the refs.

        :param str new_remote_name: the remote name which will be used instead of the current one
        z
active/deploy�rbNFcsg|]}�j|��qSr)Zget_child_value)�.0�i)�variantrr�
<listcomp>WszCInstalledRefsList.replace_installed_refs_remote.<locals>.<listcomp>�sr�wb)rSr3r�#FLATPAK_DEPLOY_DATA_GVARIANT_STRINGrArrr�open�readrZnew_from_bytesr	�rangeZ
n_childrenZ	new_tupleZget_data_as_bytes�get_data�write)rZnew_remote_namer-Zvariant_typerBZdeploy_path�fZcontentZchildrenZnew_variantZ
serializedr)r\rrDFs


z/InstalledRefsList.replace_installed_refs_remoteN)rLrMrNr`rUrDrrrrrC?srC)$rr5Zgi�abcrrZpyanaconda.anaconda_loggersrZpyanaconda.core.i18nrZpyanaconda.core.glibrrrr	Zpyanaconda.progressr
Zpyanaconda.payload.errorsrZrequire_versionZgi.repository.Flatpakrr
rrrZgi.repository.GiorrLr �__all__�objectrrRr'rCrrrr�<module>s&I1