%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core22/current/usr/share/subiquity/subiquitycore/__pycache__/
Upload File :
Create Path :
Current File : //snap/core22/current/usr/share/subiquity/subiquitycore/__pycache__/snapd.cpython-310.pyc

o

K��^d�@s�ddlZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlZe�d�ZGdd�d�ZGd	d
�d
�ZGdd�d�ZGd
d�d�ZGdd�d�ZGdd�d�ZdS)�N)�partial)�
quote_plus�	urlencode)�
run_in_thread)�run_commandzsubiquitycore.snapdc@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�SnapdConnectioncCs||_d�t|��|_dS)Nzhttp+unix://{}/)�root�formatr�url_base)�selfr	�sock�r�+/usr/share/subiquity/subiquitycore/snapd.py�__init__'szSnapdConnection.__init__cKsT|r
|dt|�7}t���}|j|j|dd�Wd�S1s#wYdS)N�?�<)�timeout)r�requests_unixsocket�Session�getr)r�path�args�sessionrrrr+s

$�zSnapdConnection.getcKs\|r
|dt|�7}t���}|j|j|t�|�dd�Wd�S1s'wYdS)Nrr)�datar)rrr�postr�json�dumps)rr�bodyrrrrrr1s
�$�zSnapdConnection.postcCs�t�d�tj�|jd�}tj|dd�ttj�|d�d��}|�|�	��Wd�n1s0wY|jdkrCdd	ggd
�g}nddgg}|D]}t
|�qJdS)
Nz(restarting snapd to pick up proxy configz"etc/systemd/system/snapd.service.dT)�exist_okzsnap_proxy.conf�w�/�	systemctlz
daemon-reload)r"�restartz
snapd.service�sleep�2)�log�debug�osr�joinr	�makedirs�open�write�proxy_systemd_dropinr)r�proxy�
dropin_dir�fp�cmds�cmdrrr�configure_proxy9s 
��
�

�zSnapdConnection.configure_proxyN)�__name__�
__module__�__qualname__rrrr3rrrrr&s
rc@�$eZdZdd�Zdd�Zdd�ZdS)�_FakeFileResponsecC�
||_dS�N)r)rrrrrrM�
z_FakeFileResponse.__init__cC�dSr:r�rrrr�raise_for_statusP�z"_FakeFileResponse.raise_for_statuscCs8t|j��
}t�|�Wd�S1swYdSr:)r+rr�load)rr0rrrrSs$�z_FakeFileResponse.jsonN�r4r5r6rr>rrrrrr8K�r8c@r7)�_FakeMemoryResponsecCr9r:�r)rrrrrrZr;z_FakeMemoryResponse.__init__cCr<r:rr=rrrr>]r?z$_FakeMemoryResponse.raise_for_statuscCs|jSr:rDr=rrrr`sz_FakeMemoryResponse.jsonNrArrrrrCXrBrCc@s eZdZdZdd�Zdd�ZdS)�ResponseSetzqResponses for a endpoint that returns different data each time.

    Motivating example is v2/changes/$change_id.cCs||_d|_dS)Nr)�files�index)rrFrrrris
zResponseSet.__init__cCsh|j|j}ttj�dd��}|dkr)|j|t|j�kr)t|j�d|_t|�S|j|7_t|�S)N�SUBIQUITY_REPLAY_TIMESCALE�)rFrG�intr(�environr�lenr8)r�f�drrr�nextms�zResponseSet.nextN)r4r5r6�__doc__rrOrrrrrEdsrEc@r)
�FakeSnapdConnectioncCs||_||_i|_||_dSr:)�
snap_data_dir�scale_factor�
response_sets�output_base)rrRrSrUrrrrzs
zFakeSnapdConnection.__init__cCst�d�t�d|j�dS)Nz3pretending to restart snapd to pick up proxy config�)r&r'�timer$rS)rr.rrrr3�s
z#FakeSnapdConnection.configure_proxycKsv|dkr|ddkr|jd}t|d���tdddd	d
��S|dkr2|ddkr2tdddd
d
��Std�||f���)Nzv2/snaps/subiquity�action�refreshz/run/subiquity/updatingr �async�7���OK)�type�changezstatus-code�status�switch�8�Acceptedz*Don't know how to fake POST response to {})rUr+�closerC�	Exceptionr
)rrrr�update_marker_filerrrr�s&
���zFakeSnapdConnection.postcKs�t�d|j�|�dd�}|r|dtt|����7}||jvr(|j|��St	j
�|j|�}t	j
�
|d�r>t|d�St	j
�|�r]tt�t	j
�|d���}t|�}|j|<|��Std�||f���)NrIr!�-z.jsonz*.jsonz)Don't know how to fake GET response to {})rWr$rS�replacer�sorted�itemsrTrOr(rr)rR�existsr8�isdir�globrErer
)rrr�filename�filepathrF�rsrrrr�s 
�zFakeSnapdConnection.getN)r4r5r6rr3rrrrrrrQys
rQc@r)
�
AsyncSnapdcCr9r:)�
connection)rrrrrrr�r;zAsyncSnapd.__init__c�s2�tt|jj|fi|���IdH}|��|��Sr:)rrrrrr>r)rrr�responserrrr�s�
�zAsyncSnapd.getc�s8�tt|jj||fi|���IdH}|��|��dS)Nr_)rrrrrr>r)rrrrrsrrrr�s�
�zAsyncSnapd.postc�s^�|j||fi|��IdH}d�|�}	|�|�IdH}|dddkr&dSt�d�IdHq)Nz
v2/changes/{}T�resultr`�Doneg�������?)rr
r�asyncior$)rrrrr_�change_pathrtrrr�
post_and_wait�s�
�zAsyncSnapd.post_and_waitN)r4r5r6rrrrxrrrrrq�s
rq)rv�	functoolsrrmr�loggingr(rW�urllib.parserr�subiquitycore.async_helpersr�subiquitycore.utilsrr�	getLoggerr&rr8rCrErQrqrrrr�<module>s$
%
2

Zerion Mini Shell 1.0